Skip to content

Commit

Permalink
Automatically set as_job to FALSE in tar_make() if rstudioapi and/or …
Browse files Browse the repository at this point in the history
…RStudio is not available
  • Loading branch information
wlandau committed Jun 20, 2024
1 parent b087656 commit 42cb4c1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Description: Pipeline tools coordinate the pieces of computationally
The methodology in this package
borrows from GNU 'Make' (2015, ISBN:978-9881443519)
and 'drake' (2018, <doi:10.21105/joss.00550>).
Version: 1.7.0.9002
Version: 1.7.1
License: MIT + file LICENSE
URL: https://docs.ropensci.org/targets/, https://github.com/ropensci/targets
BugReports: https://github.com/ropensci/targets/issues
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# targets 1.7.0.9002 (development)
# targets 1.7.1

* Use `bslib` in `tar_watch()`.
* Speed up `target_upstream_edges()` and `pipeline_upstream_edges()` by avoiding data frames until the last minute (17% speedup for certain kinds of large pipelines).
* Automatically set `as_job` to `FALSE` in `tar_make()` if `rstudioapi` and/or RStudio is not available.

# targets 1.7.0

Expand Down
27 changes: 4 additions & 23 deletions R/tar_make.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
#' `tar_option_get("controller")$summary()` to close down the dispatcher
#' and worker processes.
#' @param as_job `TRUE` to run as an RStudio IDE / Posit Workbench job,
#' if running on RStudio IDE / Posit Workbench.
#' `FALSE` to run as a `callr` process in the main R session
#' (depending on the `callr_function` argument).
#' If `as_job` is `TRUE`, then the `rstudioapi` package must be installed.
Expand Down Expand Up @@ -171,6 +172,9 @@ tar_make <- function(
tar_assert_none_na(as_job)
# Tested in tests/interactive/test-job.R.
# nocov start
if (as_job && !rstudio_available(verbose = reporter != "silent")) {
as_job <- FALSE
}
if (as_job) {
call <- match.call()
tar_make_as_job(call = call)
Expand Down Expand Up @@ -260,29 +264,6 @@ tar_make_inner <- function(
# Tested in tests/interactive/test-job.R.
# nocov start
tar_make_as_job <- function(call) {
tar_assert_package(
"rstudioapi",
msg = paste(
"The 'rstudioapi' package is required to run tar_make()",
"with as_job = TRUE. Either install the package or set as_job = FALSE.",
"You can set as_job = FALSE either manually",
"in tar_make() or persistently",
"for the project in _targets.yaml",
"using tar_config_set(as_job = FALSE)."
)
)
tar_assert_true(
rstudioapi::isAvailable(),
msg = paste(
"tar_make(as_job = TRUE) can only run inside the RStudio IDE",
"or Posit Workbench. If you are running the pipeline in a terminal",
"or a different IDE, then please set as_job = FALSE.",
"You can set as_job = FALSE either manually",
"in tar_make() or persistently",
"for the project in _targets.yaml",
"using tar_config_set(as_job = FALSE)."
)
)
args <- as.list(call)[-1L]
args$as_job <- FALSE
args <- paste(names(args), "=", map_chr(args, tar_deparse_safe))
Expand Down
24 changes: 24 additions & 0 deletions R/utils_rstudio_addins.R → R/utils_rstudio.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,27 @@ rstudio_symbol_at_cursor <- function(context) {
)
}
# nocov end

# Tested in tests/interactive/test-job.R
# nocov start
rstudio_available <- function(verbose = TRUE) {
available <- TRUE
if (!rlang::is_installed("rstudioapi")) {
available <- FALSE
reason <- "package {rstudioapi} is not installed."
}
if (!rstudioapi::isAvailable()) {
available <- FALSE
reason <- "RStudio API / Posit Workbench is not running."
}
if (!available && verbose) {
message <- paste(
"as_job is TRUE in tar_make(), but",
reason,
"Running with as_job = FALSE."
)
tar_message(message, class = "tar_condition_validate")
}
available
}
# nocov end
1 change: 1 addition & 0 deletions man/tar_make.Rd

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

1 change: 1 addition & 0 deletions tests/interactive/test-job.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Test both in RStudio and the terminal.
tar_test("tar_make(as_job = TRUE)", {
tar_script({
list(
Expand Down

0 comments on commit 42cb4c1

Please sign in to comment.