dirSeparator(dos.path=<<see below>>, all.separators=F) isDirSeparator(sep, dos.path=<<see below>>) makeDirSeparator(path, dos.path=<<see below>>)
getPlatform()
is called to determine
if the current session is running on Windows.
dos.path=TRUE
to return
a string containing all Windows path separators, "[/\\]", if set to TRUE.
By default, it is FALSE.
dirSeparator
returns a character string
containing the appropriate directory separator for the platform, or as
specified by
dos.path
.
isDirSeparator
returns a logical value
indicating whether or not the
sep
argument
can be used as a directory separator.
makeDirSeparator
returns a character string
containing the correct directory separator to use if appending a directory
or file name to the input
path
argument.
Function
calls
the function
dirSeparator
.
In most cases you can use
file.path
instead of using
dirSeparator
,
paste
,
and
substituteString
,
when writing code to create or modify path names in a platform independent way.
# one method for creating a file path path <- "myhome/mysplus\\library" paste(path, "myPkg", "README", sep = dirSeparator()) # but function file.path is better, since it will also # fix any directory separators used in the path string file.path(path, "myPkg", "README")
# a sample function to fix up a directory path example.fixPath <- function(path) { substituteString(pattern = "/", replacement = dirSeparator(), x = substituteString(pattern = "\\\\", replacement = dirSeparator(), x = path, global = TRUE, fixed = TRUE), global = TRUE, fixed = TRUE) } example.fixPath("C:/PROGRAM FILES/TIBCO/splus81\\library\\nlme3") # but function file.path does the job file.path("C:/PROGRAM FILES/TIBCO/splus81\\library\\nlme3")
isDirSeparator("\\") # on UNIX returns: F, on Windows returns: T
makeDirSeparator("/homes/splus/") # returns: "" makeDirSeparator("/homes/splus") # on UNIX returns: "/"