diff --git a/DESCRIPTION b/DESCRIPTION index ebf92ac..c11cdfb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,7 +7,7 @@ Authors@R: role = c("aut", "cre"), email = "jonas@lindeloev.dk", comment = c(ORCID = "0000-0003-4565-0595")) -Description: Call `job::job({})` to run R code as an RStudio job and keep your console free in the meantime. This allows for a productive workflow while testing (multiple) long-running chunks of code. It can also be used to organize results using the RStudio Jobs GUI or to test code in a clean environment. Two RStudio Addins can be used to run selected code as a job. +Description: Call job::job({}) to run R code as an RStudio job and keep your console free in the meantime. This allows for a productive workflow while testing (multiple) long-running chunks of code. It can also be used to organize results using the RStudio Jobs GUI or to test code in a clean environment. Two RStudio Addins can be used to run selected code as a job. License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) diff --git a/R/call_utils.R b/R/call_utils.R index 76d32bb..2483979 100644 --- a/R/call_utils.R +++ b/R/call_utils.R @@ -6,6 +6,7 @@ #' @export #' @param x Text to print #' @param ... Currently unused +#' @return No return value, called for side effects. print.jobcode = function(x, ...) { cat(x) } @@ -54,6 +55,6 @@ get_packages = function(packages) { if (length(packages) > 0 & is.character(packages) == FALSE) stop("`packages` must be a character vector or length 0.") - new_packages = packages[packages %in% c("base", options("defaultPackages")[[1]]) == FALSE] + new_packages = packages[packages %in% c("base", getOption("defaultPackages")) == FALSE] new_packages } diff --git a/R/job.R b/R/job.R index cd1c5a7..ce42ead 100644 --- a/R/job.R +++ b/R/job.R @@ -227,7 +227,7 @@ Sys.sleep(0.4) # RStudio job output lags. This avoids unordered outputs. # FINISH # ########## # Fall back on default export -if (is.null(options('job.exported')[[1]])) +if (is.null(getOption('job.exported'))) job::export('changed') if (exists('.__jobsettings__')) rm(.__jobsettings__) diff --git a/R/job_utils.R b/R/job_utils.R index d365d7e..6154691 100644 --- a/R/job_utils.R +++ b/R/job_utils.R @@ -3,10 +3,7 @@ # Returns a named vector of hashed variables in the calling environment hash_env = function(env) { varnames = ls(envir = env, all.names = TRUE) - orig_warn = options("warn") - options(warn = -1) - hashes = lapply(varnames, function(x) digest::digest(get(x, envir = env))) - options(orig_warn) + hashes = lapply(varnames, function(x) suppressWarnings(digest::digest(get(x, envir = env)))) names(hashes) = varnames hashes diff --git a/R/misc.R b/R/misc.R index 4abca2b..7fb5352 100644 --- a/R/misc.R +++ b/R/misc.R @@ -1,6 +1,6 @@ # TRUE if this is the RStudio main session check_available = function() { - if (rstudioapi::isAvailable() == FALSE) + if (rstudioapi::isAvailable() == FALSE & getOption("is.job", FALSE) == FALSE) stop("You must run this from the RStudio main session.") if (rstudioapi::getVersion() < 1.2) stop("Install RStudio v1.2 or greater for the 'jobs' functionality.") diff --git a/README.md b/README.md index f1ac63d..d8710be 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,7 @@ Two [RStudio Addins](https://rstudio.github.io/rstudioaddins/) are installed wit * *"Run selection as job in empty session"* calls `job::empty()`. It imports nothing from your environment, so the code can run in clean isolation. All variables are returned. -## Simple usage - +## Minimal example Write your script as usual. Then wrap parts of it using `job::job({})` to run that chunk as a job: ```r @@ -34,10 +33,12 @@ job::job({ When the job completes, it silently saves `foo` and `bar` to your global environment. -Here is a more typical use case: `brms` is great, but you often restrict yourself to fit as few models as possible fewer models because compilation and sampling takes time. Let's run it as a job! + +## Typical usage +`brms` is great, but you often restrict yourself to fit as few models as possible fewer models because compilation and sampling takes time. Let's run it as a job! ```r -# Do light processing tasks in the main session +# Do light processing in the main session library(brms) data = mtcars[mtcars$hp > 100, ] model1 = mpg ~ hp * wt diff --git a/cran-comments.md b/cran-comments.md index cc2316d..b46fa8e 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,3 +1,20 @@ +# Resubmission 2 +This is a resubmission. For this version, I have: + + * Removed the quotes in the DESCRIPTION text. + * Removed call to `options(warn = -1)`. + * Added \value to `print.jobcode()`. + +I appreciate why one would generally ban calls to `rm(list = ls()`. +But these lines are only found in `export()` which can only run within RStudio +jobs (if `rstudioapi::isAvailable() == TRUE & getOption("is.job", FALSE) == TRUE`). +`job` can never remove anything from the user's global workspace or filespace. +`rm()` is the only way to control what is returned from the job since the underlying +`rstudioapi::runJobScript()` returns the full job environment upon completion. + + + + # Resubmission This is a resubmission. For this version, I have: diff --git a/man/print.jobcode.Rd b/man/print.jobcode.Rd index a56dc11..ef7db18 100644 --- a/man/print.jobcode.Rd +++ b/man/print.jobcode.Rd @@ -11,6 +11,9 @@ \item{...}{Currently unused} } +\value{ +No return value, called for side effects. +} \description{ Nice print .jobcode }