R/rstudio_addin_tar_read.R

Defines functions rstudio_addin_tar_read

Documented in rstudio_addin_tar_read

# RStudio addins are tested interactively in
# tests/interactive/test-rstudio_addins.R. # nolint
# nocov start
#' @title RStudio addin to call [tar_read()] on the symbol at the cursor.
#' @description For internal use only. Not a user-side function.
#' @export
#' @keywords internal
#' @param context RStudio API context from
#'   `rstudioapi::getActiveDocumentContext()`.
rstudio_addin_tar_read <- function(context = NULL) {
  tar_assert_package("rstudioapi")
  context <- context %||% rstudioapi::getActiveDocumentContext()
  target <- rstudio_symbol_at_cursor(context)
  if (!is.null(target)) {
    cli_blue_bullet(paste("Loading target", target, "into global environment."))
    env <- list(target = as.symbol(target))
    print(eval(substitute(targets::tar_read(target), env = env)))
  }
}
# nocov end

Try the targets package in your browser

Any scripts or data that you put into this service are public.

targets documentation built on Oct. 12, 2023, 5:07 p.m.