Skip to content

Commit

Permalink
Merge pull request #160 from ropensci/rm_warning
Browse files Browse the repository at this point in the history
Suppress warning from the project*_path() functions when the file does not already exist
  • Loading branch information
slager authored Aug 14, 2024
2 parents 37cf803 + 950b3a9 commit 26498f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 6 additions & 3 deletions R/processData.R
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,8 @@ project_path <- function(file = NULL) {
if (is.null(file)) {
return(usethis::proj_get())
} else {
return(normalizePath(file.path(usethis::proj_get(), file), winslash = "/"))
return(normalizePath(file.path(usethis::proj_get(), file), winslash = "/",
mustWork = FALSE))
}
}

Expand All @@ -707,7 +708,8 @@ project_extdata_path <- function(file = NULL) {
usethis::proj_get(),
"inst", "extdata", file
),
winslash = "/"
winslash = "/",
mustWork = FALSE
))
}
}
Expand All @@ -734,7 +736,8 @@ project_data_path <- function(file = NULL) {
usethis::proj_get(),
"data", file
),
winslash = "/"
winslash = "/",
mustWork = FALSE
))
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-project-path.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ datapackage_skeleton(
)
package_build(file.path(tempdir(), "subsetCars"))
usethis::proj_set(file.path(tempdir(), "subsetCars"))
test_that("path functions throw no warning when file does not exist", {
expect_no_warning(project_path('zzzZZZ333.txt'))
expect_no_warning(project_extdata_path('zzzZZZ333.txt'))
expect_no_warning(project_data_path('zzzZZZ333.txt'))
})
test_that("project_path works with file arguments", {
expect_equal(project_path("DESCRIPTION"), expected = file.path(usethis::proj_get(), "DESCRIPTION")) # nolint
})
Expand Down

0 comments on commit 26498f4

Please sign in to comment.