basename2 | R Documentation |
basename2()
removes all of the path up to and including the last path
separator (if any).
dirname2()
returns the part of the path
up to but excluding the
last path separator, or \string. if there is no path separator.
basename2(path, expand = TRUE)
dirname2(path, expand = TRUE)
path |
character vector, containing path names. |
expand |
logical. Should tilde (see \codelink2basepath.expand) be expanded? |
Trailing path separators are removed before dissecting the path, and for
dirname2()
any trailing file separators are removed from the result.
A character vector of the same length as path
.
If path
is an empty string, then both dirname2()
and
basename2()
return an emty string.
\
and /
are accepted as
path separators, and dirname2()
does NOT translate the path
separators.
Recall that a network share looks like \string//host/share and a drive looks like \stringd:.
For a path which starts with a network share or drive, the path specification is the portion of the string immediately afterward, e.g. \string/path/to/file is the path specification of \string//host/share/path/to/file and \stringd:/path/to/file. For a path which does not start with a network share or drive, the path specification is the entire string.
The path specification of a network share will always be empty or absolute, but the path specification of a drive does not have to be, e.g. \stringd:file is a valid path despite the fact that the path specification does not start with \string/.
If the path specification of path
is empty or is \string/, then
dirname2()
will return path
and basename2()
will return
an empty string.
If path
is an empty string, then both dirname2()
and
basename2()
return an emty string.
Recall that a network share looks like \string//host/share.
For a path which starts with a network share, the path specification is the portion of the string immediately afterward, e.g. \string/path/to/file is the path specification of \string//host/share/path/to/file. For a path which does not start with a network share, the path specification is the entire string.
If the path specification of path
is empty or is \string/, then
dirname2()
will return path
and basename2()
will return
an empty string.
path <- c("/usr/lib", "/usr/", "usr", "/", ".", "..")
x <- cbind(path, dirname = dirname2(path), basename = basename2(path))
print(x, quote = FALSE, print.gap = 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.