gadenbuie/shrtcts

using source(".R") as a shortcut

Closed this issue · 4 comments

Hi,
Thanks for the package.
I tried to add source("xx.R") as a shortcut function. The function works and shown at the addins list. But when I start Rstudio the .R file is running at the beginning. I do not want it to run each time I open the rstudio.
Then I tried to use rstudioapi::jobRunScript("xx.R") but then when I start Rstudio I get error: rstudio not running message and shortcut is not added.
Is there a way to call an R script via your package.

If you want a shortcut that runs source("/full/path/to/script.R"), you can certainly do this, but you need to create a function that calls source(...):

#' Run my script
#'
#' Runs the script that does the thing
#'
#' @interactive
function() {
  # make sure you use the full path to the script
  source("/full/path/to/script.R")
}

Can you try putting the code you want to run as a shortcut inside function() { ... }?

Thank you very much. It works :) 🥇

Great, glad to hear that!

this also works. I use the script as a background job.

function() {
  rstudioapi::jobRunScript(
    path = "/Users/ .... .R")
}