common_path | R Documentation |
Find the common part of the path up to a provided set of files. Be aware that the last element (after the last file separator) is treated as a file. Thus, if only directories, without files are submitted, the common path containing these directories is returned.
common_path(x, fsep = .Platform$file.sep)
x |
|
fsep |
|
character(1)
representing the path common to all files in x
.
This function uses "(\\\\)|/"
to split the provided paths into the
individual directories to support both Windows-specific and
unix-specific separators between folders. File and folder names
should thus not contain these characters.
Johannes Rainer
## Find the common part of the file path
pths <- c("/tmp/some/dir/a.txt", "/tmp/some/dir/b.txt",
"/tmp/some/other/dir/c.txt", "/tmp/some/other/dir/d.txt")
common_path(pths)
## If there is no common part
common_path(c("/a/b", "b"))
## Windows paths; note that "/" is used as file separator in the result
common_path(c("C:\\some\\path\\a.txt", "C:\\some\\path\\b.txt"))
## No input
common_path(character())
## No path
common_path(c("a.txt", "b.txt"))
## Same path for all
common_path(c("a/a.txt", "a/a.txt"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.