diff --git a/NEWS.md b/NEWS.md index ac2b34a6..98fc1931 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # fs (development version) +* `path_has_parent()` now expands `~` (#412). + * New `path_select_components()` function to select components of one or more paths (#326, @Tazinho). diff --git a/R/path.R b/R/path.R index a718eb1f..513ce469 100644 --- a/R/path.R +++ b/R/path.R @@ -484,7 +484,9 @@ path_filter <- function(path, glob = NULL, regexp = NULL, invert = FALSE, ...) { #' @export path_has_parent <- function(path, parent) { path <- path_abs(path) + path <- path_expand(path) parent <- path_abs(parent) + parent <- path_expand(parent) res <- logical(length(path)) diff --git a/tests/testthat/test-path.R b/tests/testthat/test-path.R index df7c5373..78b3b7b7 100644 --- a/tests/testthat/test-path.R +++ b/tests/testthat/test-path.R @@ -553,6 +553,10 @@ describe("path_has_parent", { expect_true(path_has_parent("foo/bar", "foo")) expect_true(path_has_parent("path/myfiles/myfile", "path/to/files/../../myfiles")) + + # expands path + expect_true(path_has_parent("~/a", path_expand("~/a"))) + expect_true(path_has_parent(path_expand("~/a"), "~/a")) }) it("works with multiple paths", { expect_equal(path_has_parent(c("/a/b/c", "x/y"), "/a/b"), c(TRUE, FALSE))