Skip to content

Commit

Permalink
simplify example integration
Browse files Browse the repository at this point in the history
  • Loading branch information
maxheld83 committed Jul 7, 2024
1 parent 990a3f9 commit 0831ab8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 36 deletions.
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 9 additions & 9 deletions R/examples.R
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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")
15 changes: 0 additions & 15 deletions R/paths.R

This file was deleted.

2 changes: 0 additions & 2 deletions inst/examples/paths/path_package_this/example.R

This file was deleted.

8 changes: 4 additions & 4 deletions tests/testthat/test-dependencies.R
Original file line number Diff line number Diff line change
@@ -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"))
})
3 changes: 0 additions & 3 deletions tests/testthat/test-example.R

This file was deleted.

0 comments on commit 0831ab8

Please sign in to comment.