diff --git a/NAMESPACE b/NAMESPACE index 6d0f87f..30aa8f7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,8 +1,5 @@ # Generated by roxygen2: do not edit by hand export(is_installed2) -export(path_ex_file) -export(path_extdata) -export(path_package_this) export(transform_with_generated) export(use_ex_file) diff --git a/R/examples.R b/R/examples.R index 20faea3..46bff0a 100644 --- a/R/examples.R +++ b/R/examples.R @@ -1,5 +1,8 @@ #' Source path_ex_files #' +#' To use this in your package, re-declare `source_pef()` in your package +#' with *your* package name. +#' #' @section Warning: #' Can only be called if all objects used in sourced files are already loaded. #' This is not a collation issue, but similar. @@ -9,12 +12,16 @@ #' If it uses objects from other files, #' manual collation instructions via `#' @include foo.R` may be neeeded, #' but that will quickly make the package unwieldy. +#' @inheritParams fs::path_package #' @keywords path helpers, example helpers #' @noRd -source_pef <- function(...) { - source(path_ex_file(...), local = TRUE)$value +source_pef <- function(package, ...) { + path <- fs::path_package(package = package, "examples", ..., ext = "R") + source(path, local = TRUE)$value } +source_pef_elf <- purrr::partial(source_pef, package = "elf") + #' Create or edit example files #' #' This function creates R files in the `inst/examples/` to be reused in @@ -42,10 +49,3 @@ use_ex_file <- function(..., open = rlang::is_interactive()) { } example_path <- fs::path("inst", "examples") - -#' Create path to example files -#' Used in example tag and tests -#' @inheritParams path_package_this -#' @keywords path helpers, example helpers -#' @export -path_ex_file <- function(...) path_package_this("examples", ..., ext = "R") diff --git a/R/paths.R b/R/paths.R deleted file mode 100644 index d1530dc..0000000 --- a/R/paths.R +++ /dev/null @@ -1,15 +0,0 @@ -#' Path to *this* package -#' @inheritParams fs::path_package -#' @inheritDotParams fs::path_package -#' @keywords path helpers -#' @example inst/examples/paths/path_package_this/example.R -#' @export -path_package_this <- function(..., package = "elf") { - fs::path_package(package = package, ...) -} - -#' Create path to external data -#' @inherit path_package_this -#' @keywords path helpers -#' @export -path_extdata <- function(...) path_package_this("extdata", ...) diff --git a/inst/examples/paths/path_package_this/example.R b/inst/examples/paths/path_package_this/example.R deleted file mode 100644 index cd9b8f9..0000000 --- a/inst/examples/paths/path_package_this/example.R +++ /dev/null @@ -1,2 +0,0 @@ -# path to *this* package -path_package_this() diff --git a/tests/testthat/test-dependencies.R b/tests/testthat/test-dependencies.R index 697fbd2..855e9aa 100644 --- a/tests/testthat/test-dependencies.R +++ b/tests/testthat/test-dependencies.R @@ -1,11 +1,11 @@ test_that("missing package is identified", { withr::local_options(rlib_message_verbosity = "verbose") - expect_message(source_pef("dependencies", "is_installed2", "missing")) - expect_false(source_pef("dependencies", "is_installed2", "missing")) + expect_message(source_pef_elf("dependencies", "is_installed2", "missing")) + expect_false(source_pef_elf("dependencies", "is_installed2", "missing")) }) test_that("present package is identified", { withr::local_options(rlib_message_verbosity = "verbose") - expect_silent(source_pef("dependencies", "is_installed2", "present")) - expect_true(source_pef("dependencies", "is_installed2", "present")) + expect_silent(source_pef_elf("dependencies", "is_installed2", "present")) + expect_true(source_pef_elf("dependencies", "is_installed2", "present")) }) diff --git a/tests/testthat/test-example.R b/tests/testthat/test-example.R deleted file mode 100644 index 8849056..0000000 --- a/tests/testthat/test-example.R +++ /dev/null @@ -1,3 +0,0 @@ -test_that("multiplication works", { - expect_equal(2 * 2, 4) -})