Skip to content

Commit

Permalink
Improve rstudioapi error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Feb 6, 2024
1 parent b9642a9 commit 7fd68b2
Show file tree
Hide file tree
Showing 82 changed files with 178 additions and 156 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ Language: en-US
VignetteBuilder: knitr
Config/testthat/edition: 3
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.0
RoxygenNote: 7.3.1
26 changes: 24 additions & 2 deletions R/tar_make.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
#' @param as_job `TRUE` to run as an RStudio IDE / Posit Workbench job,
#' `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.
#' If `as_job` is `TRUE`, then the `rstudioapi` package must be installed.
#' @examples
#' if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
#' tar_dir({ # tar_dir() runs code from a temp dir for CRAN.
Expand Down Expand Up @@ -263,7 +263,29 @@ tar_make_inner <- function(
# Tested in tests/interactive/test-job.R.
# nocov start
tar_make_as_job <- function(call) {
tar_assert_package("rstudioapi")
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() can only run with as_job = TRUE 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
4 changes: 2 additions & 2 deletions R/utils_assert.R
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,11 @@ tar_assert_nzchar <- function(x, msg = NULL) {

#' @export
#' @rdname tar_assert
tar_assert_package <- function(package) {
tar_assert_package <- function(package, msg = NULL) {
tryCatch(
rlang::check_installed(package),
error = function(e) {
tar_throw_validate(conditionMessage(e))
tar_throw_validate(msg %|||% conditionMessage(e))
}
)
}
Expand Down
4 changes: 2 additions & 2 deletions man/tar_active.Rd

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

2 changes: 1 addition & 1 deletion man/tar_assert.Rd

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

4 changes: 2 additions & 2 deletions man/tar_backoff.Rd

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

2 changes: 1 addition & 1 deletion man/tar_branch_index.Rd

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

2 changes: 1 addition & 1 deletion man/tar_branches.Rd

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

4 changes: 2 additions & 2 deletions man/tar_call.Rd

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

4 changes: 2 additions & 2 deletions man/tar_cancel.Rd

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

6 changes: 3 additions & 3 deletions man/tar_canceled.Rd

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

6 changes: 3 additions & 3 deletions man/tar_completed.Rd

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

6 changes: 3 additions & 3 deletions man/tar_crew.Rd

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

4 changes: 2 additions & 2 deletions man/tar_cue.Rd

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

4 changes: 2 additions & 2 deletions man/tar_definition.Rd

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

2 changes: 1 addition & 1 deletion man/tar_delete.Rd

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

2 changes: 1 addition & 1 deletion man/tar_destroy.Rd

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

6 changes: 3 additions & 3 deletions man/tar_dispatched.Rd

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

2 changes: 1 addition & 1 deletion man/tar_edit.Rd

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

4 changes: 2 additions & 2 deletions man/tar_envir.Rd

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

6 changes: 3 additions & 3 deletions man/tar_errored.Rd

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

4 changes: 2 additions & 2 deletions man/tar_format.Rd

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

2 changes: 1 addition & 1 deletion man/tar_github_actions.Rd

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

4 changes: 2 additions & 2 deletions man/tar_group.Rd

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

2 changes: 1 addition & 1 deletion man/tar_invalidate.Rd

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

4 changes: 2 additions & 2 deletions man/tar_load.Rd

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

6 changes: 3 additions & 3 deletions man/tar_load_everything.Rd

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

4 changes: 2 additions & 2 deletions man/tar_load_globals.Rd

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

6 changes: 3 additions & 3 deletions man/tar_load_raw.Rd

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

2 changes: 1 addition & 1 deletion man/tar_make.Rd

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

Loading

0 comments on commit 7fd68b2

Please sign in to comment.