File: fileparts.R

package info (click to toggle)
r-cran-matlab 1.0.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 640 kB
  • sloc: sh: 13; makefile: 2
file content (158 lines) | stat: -rw-r--r-- 5,191 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
###
### $Id: fileparts.R 22 2022-05-30 18:03:47Z proebuck $
###


##-----------------------------------------------------------------------------
test.fileparts <- function(input, expected) {
    output <- do.call(getFromNamespace("fileparts", "matlab"), input)
    identical(output, expected)
}

ext <- ".ext"
gz <- ".gz"
file.without.ext <- "myfile"
file.with.ext <- paste(file.without.ext, ext, sep = "")
file.with.ext.gz <- paste(file.with.ext, gz, sep = "")
hidden.file <- ".profile"
user.name <- "luser"
abs.dir <- paste("", "home", user.name, sep = "/")
rel.cur.dir <- "."
rel.parent.dir <- ".."
tilde.dir <- "~"
tilde.user.dir <- paste(tilde.dir, user.name, sep = "")

abs.dir.file.with.ext <- paste(abs.dir, file.with.ext, sep = "/")
abs.dir.file.with.ext.gz <- paste(abs.dir, file.with.ext.gz, sep = "/")
abs.dir.file.without.ext <- paste(abs.dir, file.without.ext, sep = "/")
abs.dir.hidden.file <- paste(abs.dir, hidden.file, sep = "/")
abs.dir.trailing.slash <- paste(abs.dir, "", sep = "/")
abs.rel.cur.dir <- paste(abs.dir, rel.cur.dir, sep = "/")
abs.rel.parent.dir <- paste(abs.dir, rel.parent.dir, sep = "/")
rel.cur.dir.file.with.ext <- paste(rel.cur.dir, file.with.ext, sep = "/")
rel.cur.dir.file.without.ext <- paste(rel.cur.dir, file.without.ext, sep = "/")
rel.cur.dir.hidden.file <- paste(rel.cur.dir, hidden.file, sep = "/")
rel.cur.dir.trailing.slash <- paste(rel.cur.dir, "", sep = "/")
tilde.dir.trailing.slash <- paste(tilde.dir, "", sep = "/")
tilde.user.dir.trailing.slash <- paste(tilde.user.dir, "", sep = "/")


## 'myfile.ext'
test.fileparts(list(file.with.ext),
               list(pathstr = "",
                    name    = file.without.ext,
                    ext     = ext,
                    versn   = ""))

## '/home/luser/myfile.ext'
test.fileparts(list(abs.dir.file.with.ext),
               list(pathstr = abs.dir,
                    name    = file.without.ext,
                    ext     = ext,
                    versn   = ""))

## '/home/luser/myfile.ext.gz'
test.fileparts(list(abs.dir.file.with.ext.gz),
               list(pathstr = abs.dir,
                    name    = file.with.ext,
                    ext     = gz,
                    versn   = ""))

## '/home/luser/myfile'
test.fileparts(list(abs.dir.file.without.ext),
               list(pathstr = abs.dir,
                    name    = file.without.ext,
                    ext     = "",
                    versn   = ""))

## '/home/luser/.profile'
test.fileparts(list(abs.dir.hidden.file),
               list(pathstr = abs.dir,
                    name    = character(0),
                    ext     = hidden.file,
                    versn   = ""))

## '/home/luser'
test.fileparts(list(abs.dir),
               list(pathstr = dirname(abs.dir),
                    name    = basename(abs.dir),
                    ext     = "",
                    versn   = ""))

## '/home/luser/'
test.fileparts(list(abs.dir.trailing.slash),
               list(pathstr = abs.dir,
                    name    = character(0),
                    ext     = "",
                    versn   = ""))

## './myfile.ext'
test.fileparts(list(rel.cur.dir.file.with.ext),
               list(pathstr = rel.cur.dir,
                    name    = file.without.ext,
                    ext     = ext,
                    versn   = ""))

## './myfile'
test.fileparts(list(rel.cur.dir.file.without.ext),
               list(pathstr = rel.cur.dir,
                    name    = file.without.ext,
                    ext     = "",
                    versn   = ""))

## './.profile'
test.fileparts(list(rel.cur.dir.hidden.file),
               list(pathstr = rel.cur.dir,
                    name    = character(0),
                    ext     = hidden.file,
                    versn   = ""))

## '.'
test.fileparts(list(rel.cur.dir),
               list(pathstr = "",
                    name    = character(0),
                    ext     = ".",
                    versn   = ""))

## '..'
test.fileparts(list(rel.parent.dir),
               list(pathstr = "",
                    name    = ".",
                    ext     = ".",
                    versn   = ""))

## './'
test.fileparts(list(rel.cur.dir.trailing.slash),
               list(pathstr = rel.cur.dir,
                    name    = character(0),
                    ext     = "",
                    versn   = ""))

## "~"
test.fileparts(list(tilde.dir),
               list(pathstr = "",
                    name    = tilde.dir,
                    ext     = "",
                    versn   = ""))

## "~/"
test.fileparts(list(tilde.dir.trailing.slash),
               list(pathstr = tilde.dir,
                    name    = character(0),
                    ext     = "",
                    versn   = ""))

## "~luser"
test.fileparts(list(tilde.user.dir),
               list(pathstr = "",
                    name    = tilde.user.dir,
                    ext     = "",
                    versn   = ""))

## "~luser/"
test.fileparts(list(tilde.user.dir.trailing.slash),
               list(pathstr = tilde.user.dir,
                    name    = character(0),
                    ext     = "",
                    versn   = ""))