Skip to content

Commit 8aaf785

Browse files
committed
Upkeep on path_first_existing()
1 parent 44cf3db commit 8aaf785

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

R/pkgdown.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,14 @@ tidyverse_url <- function(url, tr = NULL) {
141141

142142
pkgdown_config_path <- function(base_path = proj_get()) {
143143
path_first_existing(
144-
base_path,
145-
c(
146-
"_pkgdown.yml",
147-
"_pkgdown.yaml",
148-
"pkgdown/_pkgdown.yml",
149-
"inst/_pkgdown.yml"
144+
path(
145+
base_path,
146+
c(
147+
"_pkgdown.yml",
148+
"_pkgdown.yaml",
149+
"pkgdown/_pkgdown.yml",
150+
"inst/_pkgdown.yml"
151+
)
150152
)
151153
)
152154
}

R/utils.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ isNA <- function(x) {
7272
length(x) == 1 && is.na(x)
7373
}
7474

75-
path_first_existing <- function(...) {
76-
paths <- path(...)
77-
for (path in paths) {
75+
path_first_existing <- function(paths) {
76+
# manual loop with explicit use of `[[` to retain "fs" class
77+
for (i in seq_along(paths)) {
78+
path <- paths[[i]]
7879
if (file_exists(path)) {
7980
return(path)
8081
}

tests/testthat/test-utils.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,17 @@ test_that("slug() sets file extension, iff 'ext' not aleady the extension", {
1717
expect_equal(slug("abc.r", "R"), "abc.r")
1818
expect_equal(slug("abc.R", "txt"), "abc.txt")
1919
})
20+
21+
test_that("path_first_existing() works", {
22+
create_local_project()
23+
24+
all_3_files <- proj_path(c("alfa", "bravo", "charlie"))
25+
26+
expect_null(path_first_existing(all_3_files))
27+
28+
write_utf8(proj_path("charlie"), "charlie")
29+
expect_equal(path_first_existing(all_3_files), proj_path("charlie"))
30+
31+
write_utf8(proj_path("bravo"), "bravo")
32+
expect_equal(path_first_existing(all_3_files), proj_path("bravo"))
33+
})

0 commit comments

Comments
 (0)