r-lib / callr Goto Github PK
View Code? Open in Web Editor NEWCall R from R
Home Page: https://callr.r-lib.org/
License: Other
Call R from R
Home Page: https://callr.r-lib.org/
License: Other
somehow....
When installing packages via devtools::install_github("repository") I am receiving the error that `rcmd_safe_env' is not in the namespace of callr. I checked, and it looks like it is in fact in the namespace.
I am using Ubuntu, if that is helpful.
I am not sure how, maybe in a file?
Backstory here: Bioconductor/BiocManager#4 (comment)
Unless told otherwise, I will make a PR.
From CRAN:
Dear maintainer,
Please see the problems shown on
<https://cran.r-project.org/web/checks/check_results_callr.html>.
Please correct before 2018-02-24 to safely retain your package on CRAN.
Best,
-k
Maybe I'll just call it r
?
We have a testthat test case that uses callr that does not work on travis or when called from R CMD check. Interestingly, it works fine if testthat is called directly. I made a demo repo at https://github.com/hannesmuehleisen/callrtestthattravistest. Error thrown:
Running ‘testthat.R’
ERROR
Running the tests in ‘tests/testthat.R’ failed.
Last 13 lines of output:
cannot open the connection
1: callr::r(do_something_dumb, show = TRUE) at testthat/test_01_callr.R:9
2: r_internal(func, args, libpath = libpath, repos = repos, stdout = stdout, stderr = stderr,
error = error, cmdargs = cmdargs, show = show, callback = callback, system_profile = system_profile,
user_profile = user_profile, env = env)
3: get_result(res)
4: readRDS(res)
5: gzfile(file, "rb")
Travis error is here: https://travis-ci.org/hannesmuehleisen/callrtestthattravistest/builds/189459759
Because that makes the R process, well, quit.
A workaround would be to have an argument for optional quit status, and then quit()
would be explicitly called with this status.
As well as output = TRUE
it would be useful to have (say) input = TRUE
which would print the complete command run by rcmd()
.
When I run the following repeatedly:
p <- process$new('ls')
p$kill()
This error occasionally comes up:
> p <- process$new('ls')
> p$kill()
[1] TRUE
> p <- process$new('ls')
> p$kill()
[1] FALSE
> p <- process$new('ls')
> p$kill()
Error in process_kill(self, private, grace) :
process_kill: Operation not permitted
> p <- process$new('ls')
> p$kill()
[1] FALSE
Could this be due to a race where the process stops after the R function process_kill()
is called, but before the C function callr_kill
gets to the part where it does stuff with the process?
In Travis logs, I also see callr_kill: No child processes
. I haven't figured out how to reproduce it locally, but I suspect it has a similar cause.
Error in process_signal(self, private, signal) :
callr_get_exit_status: No child processes
Calls: <Anonymous> ... <Anonymous> -> sd_stop -> <Anonymous> -> process_signal
Error in process_kill(self, private, grace) :
callr_kill: No child processes
https://travis-ci.org/rstudio/shinytest/jobs/359462139#L3125-L3130
The last release was published about 2 years ago. Is there any plan to publish a new release? It is such a great tool to enhance R performance and flexibility.
Create a background R session and run commands in it.
# devtools::install_github("romainfrancois/trump")
callr::r(function() library(trump))
#> Error in readRDS(res) : error reading from connection
#> 3. readRDS(res)
#> 2. get_result(output = out, options)
#> 1. callr::r(function() library(trump))
Devtools has this:
r_env_vars <- function() {
vars <- c(
"R_LIBS" = paste(.libPaths(), collapse = .Platform$path.sep),
"CYGWIN" = "nodosfilewarning",
# When R CMD check runs tests, it sets R_TESTS. When the tests
# themselves run R CMD xxxx, as is the case with the tests in
# devtools, having R_TESTS set causes errors because it confuses
# the R subprocesses. Un-setting it here avoids those problems.
"R_TESTS" = "",
"R_BROWSER" = "false",
"R_PDFVIEWER" = "false",
"TAR" = auto_tar())
if (is.na(Sys.getenv("NOT_CRAN", unset = NA))) {
vars[["NOT_CRAN"]] <- "true"
}
vars
}
# Determine the best setting for the TAR environmental variable
# This is needed for R <= 2.15.2 to use internal tar. Later versions don't need
# this workaround, and they use R_BUILD_TAR instead of TAR, so this has no
# effect on them.
auto_tar <- function() {
tar <- Sys.getenv("TAR", unset = NA)
if (!is.na(tar)) return(tar)
windows <- .Platform$OS.type == "windows"
no_rtools <- is.null(get_rtools_path())
if (windows && no_rtools) "internal" else ""
}
Would you consider adding to callr?
R_LIBS
auto_tar
can probably be dropped nowE.g.
OKhecking for file ‘devtools/DESCRIPTION’ ...
I can't figure out a good way to get back to the end of the previous line using ANSII escape codes to fix this, maybe you have some ideas.
callr::r(stats::acf, args = list(runif(100)))
should be the same as
callr::r(function(...) stats::acf(...), args = list(runif(100)))
Greetings,
I am installing a package that uses @master as a dependency.
After attempting to install both via the package, as well as directly the installation fails on windows 7
Specifically "make -f "Makevars.win"
Happens e.g. when calling devtools::build
on devtools
itself.
Maybe this is a processx issue, actually.
Call R CMD
instead of R. I mean, in addition.
From a Travis CI session with R 3.3:
$ R_LIBS_USER=/dummy R CMD build .
* checking for file ‘./DESCRIPTION’ ... OK
* preparing ‘dplyr’:
* checking DESCRIPTION meta-information ... OK
* cleaning src
Error in loadVignetteBuilder(pkgdir, TRUE) :
vignette builder 'knitr' not found
Execution halted
The command works if omitting the R_LIBS_USER
override. I believe this triggers r-lib/styler#46.
@gaborcsardi Looks to be an issue with how arguments are being escaped in callr or proccessx. This is the only recent change in devtools + dependencies that I think would cause it.
Or just let the users do it any way they want?
knit_remotely <- remotify(knitr::knit, envir = emptyenv())
knit_remotely(input = "blah.Rmd", output = "blah.md")
The extra argument envir
just changes a default value.
Mimic calling R -e
or R -f
or Rscript -e
or Rscript
.
Fails: :(
> pkgdown::build_site()
══ Building pkgdown site ═══════════════════════════════════════════════════════
Reading from: '/Users/gaborcsardi/works/callr'
Writing to: '/Users/gaborcsardi/works/callr/docs'
── Initialising site ───────────────────────────────────────────────────────────
Writing 'sitemap.xml'
── Building home ───────────────────────────────────────────────────────────────
Writing 'index.html'
── Building function reference ─────────────────────────────────────────────────
Loading callr
Reading 'man/callr.Rd'
Reading 'man/convert_and_check_my_args.Rd'
Reading 'man/get_result.Rd'
Reading 'man/make_error.Rd'
Reading 'man/r.Rd'
Reading 'man/r_bg.Rd'
Error in asNamespace(ns) : not a namespace
> traceback()
28: stop("not a namespace")
27: asNamespace(ns)
26: getNamespaceName(pkg)
25: unname(getNamespaceName(pkg))
24: ns_env_name(get_env(obj))
23: href_topic_local(in_braces)
22: as_html.tag_link(.x[[i]], ...)
21: .f(.x[[i]], ...)
20: .Call(map_impl, environment(), ".x", ".f", "character")
19: purrr::map_chr(x, as_html, ...)
18: flatten_para(text, ...)
17: as_data.tag_value(.x[[i]], ...)
16: .f(.x[[i]], ...)
15: .Call(map_impl, environment(), ".x", ".f", "list")
14: purrr::map(., as_data)
13: function_list[[i]](value)
12: freduce(value, `_function_list`)
11: `_fseq`(`_lhs`)
10: eval(quote(`_fseq`(`_lhs`)), env, env)
9: eval(quote(`_fseq`(`_lhs`)), env, env)
8: withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
7: sections %>% purrr::map(as_data) %>% purrr::map(add_slug)
6: data_reference_topic(topic, pkg, examples = examples, run_dont_run = run_dont_run,
mathjax = mathjax)
5: .f(.x[[i]], ...)
4: .Call(map_impl, environment(), ".x", ".f", "list")
3: purrr::map(topics, build_reference_topic, pkg = pkg, lazy = lazy,
examples = examples, run_dont_run = run_dont_run, mathjax = mathjax)
2: build_reference(pkg, lazy = lazy, examples = examples, run_dont_run = run_dont_run,
mathjax = mathjax, seed = seed, override = override, preview = FALSE)
1: pkgdown::build_site()
When changing the library path with .libPaths()
, the site library paths disappear:
callr::r(function() .libPaths())
## [1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"
## [3] "/usr/lib/R/library"
callr::r(function() {
.libPaths(tempdir())
.libPaths()
})
## [1] "/tmp/RtmplLBE1z" "/usr/lib/R/library"
callr::r(function() Sys.getenv("R_LIBS_SITE"))
## [1] "/tmp/RtmpC00eG2/file41e2d104715"
I'm not sure if this is intended, but I was expecting to see:
.libPaths()
## [1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"
## [3] "/usr/lib/R/library"
.libPaths(tempdir())
.libPaths()
## [1] "/tmp/RtmpCo52Xn" "/usr/local/lib/R/site-library"
## [3] "/usr/lib/R/site-library" "/usr/lib/R/library"
Sys.getenv("R_LIBS_SITE")
## [1] "/usr/local/lib/R/site-library:/usr/lib/R/site-library:/usr/lib/R/library"
This was also the behavior in callr::r
before ffa393f. The change seems to come from callr now setting R_LIBS_SITE
to a temp file. The site library paths are inherited fine, but are lost when .libPaths()
constructs new library paths.
I'm wondering if it is possible to get both output streams together, with lines in the right (chronological) order. One way to achieve this with system2
is to redirect stdout and stderr to the same connection, but this does not seem to work with callr, c.f. the following small snippet:
library(callr)
f = function() {
print("print")
message("message")
return("return")
}
out = tempfile()
# with callr
r(f, stdout = out, stderr = out)
readLines(out)
# -> "print" missing
# with system2
rscript = tempfile()
fp = file(rscript, "w")
dump("f", file = fp)
writeLines("f()", fp)
close(fp)
system2("Rscript", rscript, stdout = out, stderr = out)
readLines(out)
I picture a version of lapply()
that distributes the list over multiple processes spawned by callr::r()
or callr::rcmd()
. Is this part of the plan for future development?
Hi,
Compilation fails when RTools is installed in a location other than C:\RTools
.
Since RTools/bin
is added to the PATH
as a common practice, I suggest to call gcc
without specifying exact location, or use the BINPREF
variable, as discussed here
Thanks, Ido
Might be useful for debugging
the rcmd() function, as the stated by the name, runs a 'R CMD xxx' command.
What if I want to run 'R --version' ? Or R RHOME ?
Should I'd be better off using r(function(x) R.version), but it's a bit slower.
Thanks.
I think this is not needed any more.
Might be different for the --interactive
case.
naive question: why not taking an expression argument to r() ?
Is there any issue ? Because it also covers the function call case.
I mean
r(quote(summary(mycars)), vars = list(mycars)))
instead of
r(function(x) summary(x), args = list(mycars))
I'm not sure if this qualifies as a bug, but I don't understand what's happening here. Consider the following code snippet:
callr::r_safe(
function(n) {
point <- function(x, y) {
stopifnot(is.numeric(x), is.numeric(y))
structure(list(x = x, y = y), class = "point")
}
abs.point <- function(x) {
sqrt(x$x ^ 2 + x$y ^ 2)
}
points <- mapply(point, runif(n), runif(n), SIMPLIFY = FALSE)
sapply(points, abs)
},
args = list(n = 5L)
)
If abs.point
is called as abs(points[[1]])
, it works as I would expect. But using sapply
to iterate, I get a non-numeric argument to mathematical function
error.
The actual problem I'm facing is that something along the lines of the above example is being used in an rmarkdown document and pkgdown uses r_safe
to knit the .Rmd
file.
vanilla
copycat
Optionally.
Hi, it's kind of annoying in windows, because the warnings pop up everytime, like below:
In addition: Warning messages:
1: In readChar(path, nchars = file.info(path)$size, ...) :
can only read in bytes in a non-UTF-8 MBCS locale
2: In readChar(path, nchars = file.info(path)$size, ...) :
can only read in bytes in a non-UTF-8 MBCS locale
It comes from readChar()
in utils.R
:
read_char <- function(path, ...) {
readChar(path, nchars = file.info(path)$size, ...)
}
By checking out the help of readChar()
:
nchars will be interpreted in bytes not characters in a non-UTF-8 multi-byte locale, with a warning.
Sorry, I'm not familiar with readChar()
, but any ideas? Thanks.
EDIT:
I guess by setting useByte = TRUE
would be the solution #19
Devtools has this:
# Create a temporary .Rprofile based on the current "repos" option
# and return a named vector that corresponds to environment variables
# that need to be set to use this .Rprofile
r_profile <- function() {
tmp_user_profile <- file.path(tempdir(), "Rprofile-devtools")
tmp_user_profile_con <- file(tmp_user_profile, "w")
on.exit(close(tmp_user_profile_con), add = TRUE)
writeLines("options(repos =", tmp_user_profile_con)
dput(getOption("repos"), tmp_user_profile_con)
writeLines(")", tmp_user_profile_con)
c(R_PROFILE_USER = tmp_user_profile)
}
To ensure that the repository from the current session gets carried over to the child. Would you consider this for callr?
From r-lib/processx#96
And then add a test case for the timeout.
I am trying to build R and the Tidyverse with the Intel compiler suite, and callr
is failing to build. I have included the error message below; it looks to me like perhaps there is a missing #include
that gcc
is more forgiving about?
** package ‘callr’ successfully unpacked and MD5 sums checked
** libs
icc -std=c99 -qopenmp -O3 -ipo -xHost -multiple-processes -Wall tools/px.c -o tools/px
tools/px.c(76): warning #266: function "usleep" declared implicitly
if (fnum > 0) usleep(fnum * 1000.0 * 1000.0);
^
icc -std=c99 -qopenmp -O3 -ipo -xHost -multiple-processes supervisor/supervisor.c supervisor/utils.c \
-o supervisor/supervisor
supervisor/supervisor.c(87): warning #266: function "usleep" declared implicitly
usleep(milliseconds * 1000);
^
supervisor/supervisor.c(130): warning #266: function "kill" declared implicitly
int res = kill(pid, 0);
^
supervisor/supervisor.c(152): warning #266: function "kill" declared implicitly
kill(children[i], SIGTERM);
^
supervisor/supervisor.c(199): warning #266: function "kill" declared implicitly
kill(children[i], SIGKILL);
^
supervisor/supervisor.c(328): warning #266: function "fileno" declared implicitly
if (fcntl(fileno(fp_input), F_SETFL, O_NONBLOCK) == -1) {
^
supervisor/supervisor.c(347): error: incomplete type is not allowed
struct sigaction sa;
^
supervisor/supervisor.c(349): warning #266: function "sigemptyset" declared implicitly
sigemptyset(&sa.sa_mask);
^
supervisor/supervisor.c(350): warning #266: function "sigaction" declared implicitly
if (sigaction(SIGINT, &sa, NULL) == -1 ||
^
icc: error #10298: problem during post processing of parallel object compilation
compilation aborted for supervisor/supervisor.c (code 2)
make: *** [supervisor/supervisor] Error 2
ERROR: compilation failed for package ‘callr’
Please bump developer version to distinguish from version on CRAN.
Because .Renviron might actually have some useful variables.
SUpporting them directly is better, because various configs have various predefined sets that can still be overridden.
# The error message is cryptic.
callr::r_bg(func = function() 1 + "A", stdout = "~/out.txt", stderr = "~/err.txt")
#> Error in process_initialize(self, private, command, args, stdout, stderr, : callr error
# No traceback or warnings are available to the master process.
traceback()
#> No traceback available
warnings()
#> NULL
# Neither I/O stream made it to a text file.
any(c("out.txt", "err.txt") %in% list.files("~"))
#> [1] FALSE
# Using development callr: 3d398568995e5769eb9cab844ca735662e009485
sessionInfo()
#> R version 3.4.3 (2017-11-30)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: KDE neon User Edition 5.12
#>
#> Matrix products: default
#> BLAS: /usr/lib/libblas/libblas.so.3.6.0
#> LAPACK: /usr/lib/lapack/liblapack.so.3.6.0
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
#> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
#> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> loaded via a namespace (and not attached):
#> [1] Rcpp_0.12.15 crayon_1.3.4 digest_0.6.15 rprojroot_1.3-2
#> [5] assertthat_0.2.0 R6_2.2.2 backports_1.1.2 formatR_1.5
#> [9] magrittr_1.5 evaluate_0.10.1 debugme_1.1.0 stringi_1.1.6
#> [13] callr_2.0.2.9001 rmarkdown_1.8 tools_3.4.3 stringr_1.3.0
#> [17] yaml_2.1.16 compiler_3.4.3 htmltools_0.3.6 knitr_1.20
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.