Checks the specified filepath for formatting consistencies, such as trailing slashes, etc.
checkPath(path, create) # S4 method for character,logical checkPath(path, create) # S4 method for character,missing checkPath(path) # S4 method for `NULL`,ANY checkPath(path) # S4 method for missing,ANY checkPath()
| path | A character string corresponding to a filepath. |
|---|---|
| create | A logical indicating whether the path should
be created if it doesn't exist. Default is |
Character string denoting the cleaned up filepath.
file.exists, dir.create.
## normalize file paths paths <- list("./aaa/zzz", "./aaa/zzz/", ".//aaa//zzz", ".//aaa//zzz/", ".\\aaa\\zzz", ".\\aaa\\zzz\\", file.path(".", "aaa", "zzz")) checked <- normPath(paths) length(unique(checked)) ## 1; all of the above are equivalent#> [1] 1## check to see if a path exists tmpdir <- file.path(tempdir(), "example_checkPath") dir.exists(tmpdir) ## FALSE#> [1] FALSEtryCatch(checkPath(tmpdir, create = FALSE), error = function(e) FALSE) ## FALSE#> [1] FALSEcheckPath(tmpdir, create = TRUE)#> [1] "/tmp/RtmpzknuyG/example_checkPath"dir.exists(tmpdir) ## TRUE#> [1] TRUEunlink(tmpdir, recursive = TRUE)