isDirPath | R Documentation |
If a path ends in "/" or exists and is a directory, it is a directory path. To
do a pure lexical check, which just looks for the ending "/" and ignores the
file system, set lexical= TRUE
. Note that paths ending in "/" are directory
paths even when they don't exist and even if they could not be created due
to illegal characters or the existence of a file with that name (sans the
terminal "/"). e.g. some/path
as a file does not affect some/path/
being
reported as a directory.
isDirPath(paths, lexical = FALSE)
paths |
Vector of paths to check and see if they are directories. |
lexical |
Set TRUE to skip secondary check of the file system for paths that don't end in "/" but might already exist as directories. |
Any leading "~" is expanded a la path.expand()
, but Sys.glob()
is not used,
e.g. "*" is just a regular character.
Returns a logical vector, TRUE for paths to treat as directories, FALSE otherwise.
dir.exists()
: to just check if a directory exists.
dirname()
: to extract the directory part of a file path (ignores end "/").
Sys.glob()
: to expand glob patterns into a vector of paths (including
optionally adding a terminal "/" to directories).
path.expand()
: to expand leading "~" to home directory, where supported.
# By default, only false if not ending in "/" and not an existing directory
isDirPath( c("./", ".", "noSuchDir/", "noSuchDir", "~", "*" ))
#> [1] TRUE, TRUE, TRUE, FALSE, TRUE, FALSE
# With lexical=TRUE, only cares about ending "/"
isDirPath( c( "./", ".", "noSuchDir/", "noSuchDir", "~", "*" ),
lexical= TRUE )
#> [1] TRUE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.