-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathfile.R
32 lines (32 loc) · 851 Bytes
/
file.R
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
Filename <- setRefClass("Filename",
fields = list(name = "character"),
methods = list(
initialize = function(name) {
.self$name <<- str_replace_all(name, "\\\\", "/")
},
getExt = function() {
str_match(.self$name, "\\.[^.]+$")[1]
},
getFilenameSansExt = function() {
str_match(.self$name, "(.*)\\.[^.]+$")[2]
},
changeExt = function(ext, destdir = NULL) {
if (is.null(destdir)) {
str_replace(.self$name, "\\.[^.]+$", ext)
} else {
n <- str_replace(.self$getBasename(), "\\.[^.]+$", ext)
n <- file.path(destdir, n)
str_replace_all(n, "\\\\", "/")
}
},
getDirname = function() {
dirname(.self$name)
},
getBasename = function() {
basename(.self$name)
},
exists = function() {
file.exists(.self$name)
}
)
)