Skip to content

rcmdcheck_process$new() fails setup due to missing dependencies #230

@maksymiuks

Description

@maksymiuks

Hello!

Today, I've identified a relatively rare bug in specific parameter configurations. It happens when attempting to run a check for a source package, which requires installation during building due to S expressions with the desired libpath value being different from the current .libPaths(). Then, when one or more strong dependencies of the package to be checked were supposed to come from libpath and are not satisfiable via .libPaths(), the rcc_init internal will fail due to build failure, and build failed due to missing dependencies. I believe I've also identified the issue, and it is coming from that block:

rcmdcheck/R/build.R

Lines 19 to 46 in 6125f20

with_envvar(
c("R_LIBS_USER" = paste(libpath, collapse = .Platform$path.sep)), {
proc <- pkgbuild_process$new(
path,
tmpdir,
args = build_args,
clean_doc = clean_doc,
manual = TRUE
)
on.exit(proc$kill(), add = TRUE)
callback <- detect_callback()
while (proc$is_incomplete_output() ||
proc$is_incomplete_error()
|| proc$is_alive()) {
proc$poll_io(-1)
out <- proc$read_output()
err <- proc$read_error()
if (!quiet) {
out <- sub("(checking for file .)/.*DESCRIPTION(.)",
"\\1.../DESCRIPTION\\2", out, perl = TRUE)
callback(out)
callback(err)
}
}
proc$get_built_file()
}
)

Unfortunately, callr ignores "R_LIBS_USER" when setting up libraries in the new process (I'm pretty sure deliberately), which can be tested using this example

> .libPaths()
[1] "C:/Users/Szymon/AppData/Local/R/win-library/4.4" "C:/Program Files/R/R-4.4.1/library"             
> withr::with_envvar(c(R_LIBS_USER = paste("C:/Users/Szymon/Desktop/test_lib", collapse = .Platform$path.sep)), {
+   proc <- callr::r_bg(function() {
+     .libPaths()
+   })
+   
+ })
> proc$get_result()
[1] "C:/Users/Szymon/AppData/Local/R/win-library/4.4" "C:/Program Files/R/R-4.4.1/library"  

This means that the way build_package internally currently works, the subprocess building the package never gets the appropriate libpath set (with all the dependencies required to build a package with SEXP). Unfortunately, pkgbuild_process$new() does not accept a libpath parameter, so as far as rcmdcheck is concerned, I believe the fix is to replace with_envvar with with_libpath, and so the building process (which always uses current .libPath) can adequately use desired dependencies.

I'll try to prepare a PR with a suggested fix

Thanks for all your work under this package!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions