Skip to content

Commit

Permalink
Expansion of '~' in Windows now follows the definition of fs::path_ex…
Browse files Browse the repository at this point in the history
…pand() rather than base::path.expand().
  • Loading branch information
MLopez-Ibanez committed Jan 6, 2024
1 parent 14c7911 commit 5f5c585
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@

* `path_rel2abs()` will not expand symlinks to avoid problems with Python's venv.
(fix #64, reported by @DE0CH)

* Expansion of `'~'` in Windows now follows the definition of `fs::path_expand()` rather than `base::path.expand()`.


## New features and improvements
Expand Down
9 changes: 6 additions & 3 deletions R/path_rel2abs.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#' Converts a relative path to an absolute path. It tries really hard to create
#' canonical paths. If the path passed corresponds to an executable, it tries
#' to find its path using `Sys.which()`.
#' Converts a relative path to an absolute path.
#'
#' It tries really hard to create canonical paths. If the path passed
#' corresponds to an executable, it tries to find its path using `Sys.which()`.
#' Expansion of `'~'` in Windows follows the definition of `fs::path_expand()`
#' rather than `base::path.expand()`.
#'
#' @param path (`character(1)`) Character string representing a relative path.
#' @param cwd (`character(1)`) Current working directory.
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-path.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ test_path_rel2abs <- function(testcases)
if (testcases[i,3L] == "Sys.which") {
exp <- path_abs(Sys.which(testcases[i,1]))
} else {
exp <- gsub("\\", "/", path.expand(testcases[i,3L]), fixed = TRUE)
exp <- gsub("\\", "/", path_expand(testcases[i,3L]), fixed = TRUE)
}
if (res == exp) {
#cat("[OK] ", i, ": path_rel2abs(\"", orig, "\", \"", cwd, "\") -> ", res, "\n", sep="")
} else {
cat("[FAILED] ", i, ": path_rel2abs(\"", orig, "\", \"", cwd, "\") -> ", res, " but expected: ", exp, "\n")
cat(sep="", "[FAILED] ", i, ": path_rel2abs(\"", orig, "\", \"", cwd, "\") -> ", res, " but expected: ", exp, "\n")
}
expect_match(res, exp, fixed = TRUE)
}
Expand Down

0 comments on commit 5f5c585

Please sign in to comment.