Directory Separator Character(s)

DESCRIPTION:

Functions to return or test for the appropriate directory separator character(s) depending on whether or not the S-PLUS session platform is Windows or UNIX.

USAGE:

dirSeparator(dos.path=<<see below>>, all.separators=F)
isDirSeparator(sep, dos.path=<<see below>>)
makeDirSeparator(path, dos.path=<<see below>>)

REQUIRED ARGUMENTS:

sep
a character string containing a directory separator.
path
a character string containing a directory path.

OPTIONAL ARGUMENTS:

dos.path
a logical value, set to TRUE for a Windows path separator, FALSE for UNIX. By default, getPlatform() is called to determine if the current session is running on Windows.
all.separators
a logical value used if dos.path=TRUE to return a string containing all Windows path separators, "[/\\]", if set to TRUE. By default, it is FALSE.

VALUE:

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.

DETAILS:

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.

SEE ALSO:

EXAMPLES:

# 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: "/"