Skip to content

Commit

Permalink
Merge pull request #454 from IndrajeetPatil/f408-error-path-rel
Browse files Browse the repository at this point in the history
`path_rel()` provides an informative error message when multiple starting directory paths are specified
  • Loading branch information
gaborcsardi committed May 4, 2024
2 parents 564e012 + b71a253 commit 03f550a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# fs (development version)

* `path_ext()` returns extension when multiple dots are present in file name (@IndrajeetPatil, #452).
* `path_ext()` and `path_ext_remove()` return correct extension and path, respectively, when multiple dots are present in file name (@IndrajeetPatil, #452, #453).

* `path_rel()` provides an informative error message when multiple starting directory paths are specified (@IndrajeetPatil, #454).

# fs 1.6.4

Expand Down
4 changes: 4 additions & 0 deletions R/path.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ path_norm <- function(path) {
# This implementation is partially derived from
# https://github.com/python/cpython/blob/9c99fd163d5ca9bcc0b7ddd0d1e3b8717a63237c/Lib/posixpath.py#L446
path_rel <- function(path, start = ".") {
if (length(start) > 1L) {
stop("`start` must be a single path to a starting directory.", call. = FALSE)
}

start <- path_abs(path_expand(start))
path <- path_abs(path_expand(path))

Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-path.R
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,11 @@ describe("path_rel", {
path_rel(c("a", "a/b", "a/b/c"), "a/b"),
fs_path(c("..", ".", "c"))
)
expect_error(
path_rel(c("a", "a/b", "a/b/c"), c("a/b", "a")),
"`start` must be a single path to a starting directory",
fixed = TRUE
)
})

it("works for windows paths", {
Expand Down

0 comments on commit 03f550a

Please sign in to comment.