gadenbuie / shrtcts

Make Anything an RStudio Shortcut
https://pkg.garrickadenbuie.com/shrtcts/
Other
119 stars 4 forks source link

using source(".R") as a shortcut #12

Closed sbalci closed 3 years ago

sbalci commented 3 years ago

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.

gadenbuie commented 3 years ago

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() { ... }?

sbalci commented 3 years ago

Thank you very much. It works :) 🥇

gadenbuie commented 3 years ago

Great, glad to hear that!

sbalci commented 3 years ago

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

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