Skip to content

Commit 42cb4c1

Browse files
committed
Automatically set as_job to FALSE in tar_make() if rstudioapi and/or RStudio is not available
1 parent b087656 commit 42cb4c1

File tree

6 files changed

+33
-25
lines changed

6 files changed

+33
-25
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Description: Pipeline tools coordinate the pieces of computationally
1212
The methodology in this package
1313
borrows from GNU 'Make' (2015, ISBN:978-9881443519)
1414
and 'drake' (2018, <doi:10.21105/joss.00550>).
15-
Version: 1.7.0.9002
15+
Version: 1.7.1
1616
License: MIT + file LICENSE
1717
URL: https://docs.ropensci.org/targets/, https://github.com/ropensci/targets
1818
BugReports: https://github.com/ropensci/targets/issues

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# targets 1.7.0.9002 (development)
1+
# targets 1.7.1
22

33
* Use `bslib` in `tar_watch()`.
44
* 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).
5+
* Automatically set `as_job` to `FALSE` in `tar_make()` if `rstudioapi` and/or RStudio is not available.
56

67
# targets 1.7.0
78

R/tar_make.R

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
#' `tar_option_get("controller")$summary()` to close down the dispatcher
9595
#' and worker processes.
9696
#' @param as_job `TRUE` to run as an RStudio IDE / Posit Workbench job,
97+
#' if running on RStudio IDE / Posit Workbench.
9798
#' `FALSE` to run as a `callr` process in the main R session
9899
#' (depending on the `callr_function` argument).
99100
#' If `as_job` is `TRUE`, then the `rstudioapi` package must be installed.
@@ -171,6 +172,9 @@ tar_make <- function(
171172
tar_assert_none_na(as_job)
172173
# Tested in tests/interactive/test-job.R.
173174
# nocov start
175+
if (as_job && !rstudio_available(verbose = reporter != "silent")) {
176+
as_job <- FALSE
177+
}
174178
if (as_job) {
175179
call <- match.call()
176180
tar_make_as_job(call = call)
@@ -260,29 +264,6 @@ tar_make_inner <- function(
260264
# Tested in tests/interactive/test-job.R.
261265
# nocov start
262266
tar_make_as_job <- function(call) {
263-
tar_assert_package(
264-
"rstudioapi",
265-
msg = paste(
266-
"The 'rstudioapi' package is required to run tar_make()",
267-
"with as_job = TRUE. Either install the package or set as_job = FALSE.",
268-
"You can set as_job = FALSE either manually",
269-
"in tar_make() or persistently",
270-
"for the project in _targets.yaml",
271-
"using tar_config_set(as_job = FALSE)."
272-
)
273-
)
274-
tar_assert_true(
275-
rstudioapi::isAvailable(),
276-
msg = paste(
277-
"tar_make(as_job = TRUE) can only run inside the RStudio IDE",
278-
"or Posit Workbench. If you are running the pipeline in a terminal",
279-
"or a different IDE, then please set as_job = FALSE.",
280-
"You can set as_job = FALSE either manually",
281-
"in tar_make() or persistently",
282-
"for the project in _targets.yaml",
283-
"using tar_config_set(as_job = FALSE)."
284-
)
285-
)
286267
args <- as.list(call)[-1L]
287268
args$as_job <- FALSE
288269
args <- paste(names(args), "=", map_chr(args, tar_deparse_safe))

R/utils_rstudio_addins.R renamed to R/utils_rstudio.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,27 @@ rstudio_symbol_at_cursor <- function(context) {
2929
)
3030
}
3131
# nocov end
32+
33+
# Tested in tests/interactive/test-job.R
34+
# nocov start
35+
rstudio_available <- function(verbose = TRUE) {
36+
available <- TRUE
37+
if (!rlang::is_installed("rstudioapi")) {
38+
available <- FALSE
39+
reason <- "package {rstudioapi} is not installed."
40+
}
41+
if (!rstudioapi::isAvailable()) {
42+
available <- FALSE
43+
reason <- "RStudio API / Posit Workbench is not running."
44+
}
45+
if (!available && verbose) {
46+
message <- paste(
47+
"as_job is TRUE in tar_make(), but",
48+
reason,
49+
"Running with as_job = FALSE."
50+
)
51+
tar_message(message, class = "tar_condition_validate")
52+
}
53+
available
54+
}
55+
# nocov end

man/tar_make.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/interactive/test-job.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Test both in RStudio and the terminal.
12
tar_test("tar_make(as_job = TRUE)", {
23
tar_script({
34
list(

0 commit comments

Comments
 (0)