R/save_active_file.R

Defines functions save_active_file find_active_file

find_active_file <- function(arg = file, call = parent.frame()) {
  if (!is_rstudio()) { # nolint object_usage_linter
    cli_abort("Argument {.arg {arg}} is missing, with no default", call = call)
  }
  normalizePath(rstudioapi::getSourceEditorContext()$path)
}

save_active_file <- function(file = find_active_file()) {
  if (is_rstudio()) { # nolint object_usage_linter
    if (rstudioapi::hasFun("documentSaveAll")) {
      rstudioapi::documentSaveAll()
    }
    rstudioapi::executeCommand("activateConsole", quiet = TRUE)
  }

  system2("lamin", c("save", file))
}

Try the laminr package in your browser

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

laminr documentation built on June 8, 2025, 1:27 p.m.