R Under development (unstable) (2023-11-16 r85542 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library("R.utils") Loading required package: R.oo Loading required package: R.methodsS3 R.methodsS3 v1.8.2 (2022-06-13 22:00:14 UTC) successfully loaded. See ?R.methodsS3 for help. R.oo v1.25.0 (2022-06-12 02:20:02 UTC) successfully loaded. See ?R.oo for help. Attaching package: 'R.oo' The following object is masked from 'package:R.methodsS3': throw The following objects are masked from 'package:methods': getClasses, getMethods The following objects are masked from 'package:base': attach, detach, load, save R.utils v2.12.3 successfully loaded. See ?R.utils for help. Attaching package: 'R.utils' The following object is masked from 'package:utils': timestamp The following objects are masked from 'package:base': cat, commandArgs, getOption, isOpen, nullfile, parse, warnings > warnifnot <- egsub("stop", "warning", stopifnot, value=FALSE) > > message("Absolute and relative paths ...") Absolute and relative paths ... > > message("- Absolute and relative path of getwd()") - Absolute and relative path of getwd() > stopifnot(identical(getAbsolutePath("."), getwd())) > stopifnot(identical(getRelativePath("."), ".")) > > message("- Tilde expansion") - Tilde expansion > pathH0 <- normalizePath("~") > print(pathH0) [1] "C:\\Users\\CRAN\\Documents" > pathH <- normalizePath("~", winslash = "/") > print(pathH) [1] "C:/Users/CRAN/Documents" > pathHA <- getAbsolutePath(pathH) > print(pathHA) [1] "C:/Users/CRAN/Documents" > > pathA <- getAbsolutePath("~", expandTilde=TRUE) > print(pathA) [1] "C:/Users/CRAN/Documents" > warnifnot(identical(tolower(pathA), tolower(pathH))) > > pathR <- getRelativePath("~") > print(pathR) [1] "C:/Users/CRAN/Documents" > warnifnot(identical(tolower(getAbsolutePath(pathR)), tolower(pathH))) > > pathR <- getRelativePath("~", caseSensitive=TRUE) > print(pathR) [1] "C:/Users/CRAN/Documents" > > > message("- ~/../Documents") - ~/../Documents > pathA <- getAbsolutePath("~/../Documents", expandTilde=TRUE) > pathA0 <- file.path(getParent(pathH), "Documents") > ## Account for the case when getParent(pathH) = "C:/", which in case > ## we get C://Documents instead of C:/Documents > pathA0 <- normalizePath(pathA0, winslash = "/") > utils::str(list(pathA = pathA, pathA0 = pathA0)) List of 2 $ pathA : chr "C:/Users/CRAN/Documents" $ pathA0: chr "C:/Users/CRAN/Documents" > stopifnot(pathA == pathA0) > > message("- /tmp/") - /tmp/ > pathA <- getAbsolutePath("/tmp/", expandTilde=TRUE) > print(pathA) [1] "/tmp" > stopifnot(identical(pathA, "/tmp")) > > > message("- Microsoft Windows UNC paths") - Microsoft Windows UNC paths > stopifnot(identical(getAbsolutePath("//vinata/biomed"), "//vinata/biomed")) > stopifnot(identical(getAbsolutePath("//vinata///biomed"), "//vinata/biomed")) > > message("- Vector of files") - Vector of files > paths <- c(".", "..", getwd()) > print(paths) [1] "." [2] ".." [3] "d:/RCompile/CRANincoming/R-devel/R.utils.Rcheck/tests" > pathsA <- getAbsolutePath(paths) > print(pathsA) . "d:/RCompile/CRANincoming/R-devel/R.utils.Rcheck/tests" .. "d:/RCompile/CRANincoming/R-devel/R.utils.Rcheck" d:/RCompile/CRANincoming/R-devel/R.utils.Rcheck/tests "d:/RCompile/CRANincoming/R-devel/R.utils.Rcheck/tests" > pathsR <- getRelativePath(paths) > print(pathsR) . "." .. ".." d:/RCompile/CRANincoming/R-devel/R.utils.Rcheck/tests "." > pathsAR <- getRelativePath(pathsA) > print(pathsAR) d:/RCompile/CRANincoming/R-devel/R.utils.Rcheck/tests "." d:/RCompile/CRANincoming/R-devel/R.utils.Rcheck ".." d:/RCompile/CRANincoming/R-devel/R.utils.Rcheck/tests "." > pathsRA <- getAbsolutePath(pathsR) > print(pathsRA) . "d:/RCompile/CRANincoming/R-devel/R.utils.Rcheck/tests" .. "d:/RCompile/CRANincoming/R-devel/R.utils.Rcheck" . "d:/RCompile/CRANincoming/R-devel/R.utils.Rcheck/tests" > > # Sanity checks > stopifnot(all(isAbsolutePath(pathsA))) > stopifnot(all(!isAbsolutePath(pathsR))) > stopifnot(all(pathsRA == pathsA)) > stopifnot(all(pathsAR == pathsR)) > > > message("- Paths relative to given directories") - Paths relative to given directories > stopifnot(getRelativePath("foo", "foo") == ".") > stopifnot(getRelativePath("foo/bar", "foo") == "bar") > stopifnot(getRelativePath("foo/bar", "foo/bar/yah") == "..") > stopifnot(getRelativePath("foo/bar/cool", "foo/bar/yah/sub/") == "../../cool") > stopifnot(getRelativePath("/tmp/foo/", "/tmp/") == "foo") > stopifnot(getRelativePath("/tmp/bar/", "/bar/foo/") == "../../tmp/bar") > stopifnot(getRelativePath("C:/foo/bar/", "C:/bar/") == "../foo/bar") > stopifnot(getRelativePath("C:/foo/bar/", "D:/bar/") == "C:/foo/bar") > > message("Absolute and relative paths ... DONE") Absolute and relative paths ... DONE > > proc.time() user system elapsed 0.46 0.07 0.53