Skip to content

Commit

Permalink
Add the check library to libpath
Browse files Browse the repository at this point in the history
This is needed because callr has a bug when
the sub-process ignores .Renviron and .Rprofile, but
a sub-sub-process does not.

Closes #134.
  • Loading branch information
gaborcsardi committed Sep 23, 2021
1 parent 5544634 commit 5d031bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions R/background.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,25 @@ rcc_init <- function(self, private, super, path, args, build_args,
# set up environment, start with callr safe set
chkenv <- callr::rcmd_safe_env()

package <- private$description$get("Package")[[1]]
libdir <- file.path(dirname(targz), paste0(package, ".Rcheck"))

# if R_TESTS is set here, we'll skip the session_info, because we are
# probably inside test cases of some package
if (Sys.getenv("R_TESTS", "") == "") {
private$session_output <- tempfile()
private$tempfiles <- c(private$session_output, profile)
package <- private$description$get("Package")[[1]]
libdir <- file.path(dirname(targz), paste0(package, ".Rcheck"))
profile <- make_fake_profile(package, private$session_output, libdir)
chkenv["R_TESTS"] <- profile
}

# user supplied env vars take precedence
if (length(env)) chkenv[names(env)] <- env

options <- rcmd_process_options(
cmd = "check",
cmdargs = c(basename(targz), args),
libpath = libpath,
libpath = c(libdir, libpath),
repos = repos,
user_profile = FALSE,
stderr = "2>&1",
Expand Down
5 changes: 3 additions & 2 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ do_check <- function(targz, package, args, libpath, repos,
# set up environment, start with callr safe set
chkenv <- callr::rcmd_safe_env()

libdir <- file.path(dirname(targz), paste0(package, ".Rcheck"))

# if R_TESTS is set here, we'll skip the session_info, because we are
# probably inside test cases of some package
if (Sys.getenv("R_TESTS", "") == "") {
session_output <- tempfile()
libdir <- file.path(dirname(targz), paste0(package, ".Rcheck"))
profile <- make_fake_profile(package, session_output, libdir)
on.exit(unlink(profile), add = TRUE)
chkenv["R_TESTS"] <- profile
Expand All @@ -217,7 +218,7 @@ do_check <- function(targz, package, args, libpath, repos,
res <- rcmd_safe(
"check",
cmdargs = c(basename(targz), args),
libpath = libpath,
libpath = c(libdir, libpath),
user_profile = FALSE,
repos = repos,
stderr = "2>&1",
Expand Down

0 comments on commit 5d031bd

Please # to comment.