Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes: deprecated wrap arg, and passing lib_paths to tools::pkgVignettes #160

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions R/extract-package-code.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#' @export
#'
# TODO: support commentDontrun, commentDonttest
extract_package_code <- function(pkg, pkg_dir=find.package(pkg),
extract_package_code <- function(pkg,
lib_paths=NULL,
pkg_dir=find.package(pkg),
types=c("examples", "tests", "vignettes", "all"),
output_dir=tempfile(pattern="genthat-extract_package"),
filter=NULL) {
Expand Down Expand Up @@ -32,7 +34,7 @@ extract_package_code <- function(pkg, pkg_dir=find.package(pkg),
output <- file.path(output_dir, type)
stopifnot(dir.exists(output) || dir.create(output, recursive=TRUE))

files <- fun(pkg, pkg_dir, output_dir=output)
files <- fun(pkg, pkg_dir, output_dir=output, lib_paths=lib_paths)

if (!is.null(filter)) {
files <- files[grepl(filter, tools::file_path_sans_ext(files))]
Expand All @@ -44,7 +46,7 @@ extract_package_code <- function(pkg, pkg_dir=find.package(pkg),
}

#' @importFrom tools Rd_db Rd2ex
extract_package_examples <- function(pkg, pkg_dir, output_dir) {
extract_package_examples <- function(pkg, pkg_dir, output_dir, lib_paths=NULL) {
db <- tryCatch({
tools::Rd_db(basename(pkg_dir), lib.loc=dirname(pkg_dir))
}, error=function(e) {
Expand Down Expand Up @@ -82,7 +84,7 @@ extract_package_examples <- function(pkg, pkg_dir, output_dir) {
na.omit(examples)
}

extract_package_tests <- function(pkg, pkg_dir, output_dir) {
extract_package_tests <- function(pkg, pkg_dir, output_dir, lib_paths=NULL) {
test_dir <- file.path(pkg_dir, "tests")

if (!dir.exists(test_dir)) {
Expand All @@ -100,8 +102,8 @@ extract_package_tests <- function(pkg, pkg_dir, output_dir) {
}

#' @importFrom tools pkgVignettes checkVignettes
extract_package_vignettes <- function(pkg, pkg_dir, output_dir) {
vinfo <- tools::pkgVignettes(pkg, source=T)
extract_package_vignettes <- function(pkg, pkg_dir, output_dir, lib_paths=NULL) {
vinfo <- tools::pkgVignettes(pkg, source=T, lib.loc=lib_paths)
if (length(vinfo$docs) == 0) {
return(character())
}
Expand All @@ -111,11 +113,11 @@ extract_package_vignettes <- function(pkg, pkg_dir, output_dir) {
# sources in the R code. It might actually run the vignettes as well.
# That is a pity, but there is no way to tell it not to (the tangle is
# needed to it extracts the R code)
tools::checkVignettes(pkg, pkg_dir, tangle=TRUE, weave=FALSE, workdir="src")
tools::checkVignettes(pkg, pkg_dir, tangle=TRUE, weave=FALSE, workdir="src", lib.loc=lib_paths)
}

# check if there are some sources
vinfo <- tools::pkgVignettes(pkg, source=T)
vinfo <- tools::pkgVignettes(pkg, source=T, lib.loc=lib_paths)
files <- as.character(unlist(vinfo$sources))
if (length(files) == 0) {
return(character())
Expand Down
4 changes: 3 additions & 1 deletion R/genthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ gen_from_package <- function(pkgs_to_trace, pkgs_to_run=pkgs_to_trace,
filter=NULL,
prune_tests=FALSE,
quiet=TRUE,
lib_paths=NULL,
...) {

if (prune_tests) {
Expand All @@ -70,7 +71,7 @@ gen_from_package <- function(pkgs_to_trace, pkgs_to_run=pkgs_to_trace,
}

working_dir <- tempfile(pattern="genthat-gen_from_package")
files <- lapply(pkgs_to_run, extract_package_code, types=types, output_dir=working_dir, filter=filter)
files <- lapply(pkgs_to_run, extract_package_code, lib_paths=lib_paths, types=types, output_dir=working_dir, filter=filter)
files <- unlist(files)

if (length(files) == 0) {
Expand All @@ -82,6 +83,7 @@ gen_from_package <- function(pkgs_to_trace, pkgs_to_run=pkgs_to_trace,
files_to_run=files,
action=action,
quiet=quiet,
lib_paths=lib_paths,
...
)

Expand Down
2 changes: 1 addition & 1 deletion R/run-generated-tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_generated_file <- function(test) {
testthat::test_env()
}

testthat::test_file(test, reporter="stop", wrap=FALSE, env=env)
testthat::test_file(test, reporter="stop", env=env)
}

#' @export
Expand Down