is.absolutePath: Test for absolute path

View source: R/fileUtils.R

is.absolutePathR Documentation

Test for absolute path

Description

Checks a vector of paths to see if they are absolute paths. Returns a corresponding logical vector that is TRUE for absolute paths and FALSE for others. Implementation uses a regular expression so this may not always work correctly, especially in non-ascii settings. No checks are made to see if a path exists nor if it is even a valid path.

Usage

is.absolutePath(paths)

Arguments

paths

A character vector to check to see if which are potentially absolute paths.

Value

A logical vector that is TRUE for absolute paths= , FALSE+ for most other things (including NA and empty string), and an empty vector if paths= is empty or NULL.

Examples

# All absolute paths
is.absolutePath( c( "~",  "/", "\\", "~/bob",  "/bob", "\\bob" ))
is.absolutePath( c("C:\\", "c:/", "C:\\bob", "c:/bob" ))
is.absolutePath( c(".", "./", ".\\", "./bob", ".\\bob" ))
is.absolutePath( c(".", "./", ".\\", "./bob", ".\\bob" ))
is.absolutePath( c("..", "../", "..\\", "../bob", "..\\bob" ))
is.absolutePath( c("/[](){}''|;:::Invalid but absolute!" ))

# None are absolute paths
is.absolutePath( c("", "bob/../bob", "bob\\..\\bob" ))
is.absolutePath( c("bob", "bob\\bob", "bob/bob", ".bob" ))
is.absolutePath( c( NA, "NA", "BETA_ß_" ))
is.absolutePath( list( x= "hello" ))

# empty logical returned
is.absolutePath( NULL )
is.absolutePath( character( 0 ))


jefferys/JefferysRUtils documentation built on Jan. 12, 2024, 9:18 p.m.