Skip to content

Commit

Permalink
Merge pull request #45 from lindeloev/dev
Browse files Browse the repository at this point in the history
CRAN resubmission 2
  • Loading branch information
lindeloev authored Jun 2, 2021
2 parents e456f84 + eb883fb commit 35b02d9
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Authors@R:
role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0003-4565-0595"))
Description: Call `job::job({<code here>})` 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({<code here>}) 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)
Expand Down
3 changes: 2 additions & 1 deletion R/call_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion R/job.R
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
5 changes: 1 addition & 4 deletions R/job_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/misc.R
Original file line number Diff line number Diff line change
@@ -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.")
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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({<your code>})` to run that chunk as a job:

```r
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
3 changes: 3 additions & 0 deletions man/print.jobcode.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 35b02d9

Please sign in to comment.