Reputation: 2617
Let's assume I have an R script located in C:\Users\user\myscript.R
. How can I assign a hotkey (e.g., F1
) so that every time that I press that hotkey the R script will be executed in the background (i.e., without opening Rstudio)?
Note:
I use Windows 10 and have AutoHotkey installed which might help to bind the script to the key.
Upvotes: 2
Views: 560
Reputation: 93
press win+r, type "shell:startup", and press enter. It should bring up file explorer. There, you can create a different script and write this inside it:
F1::
Run, C:\Users\user\myscript.R
This will make the trigger script run at startup, so that whenever you press f1, myscript.r will run
Upvotes: 0
Reputation: 2617
This solution involves three steps:
1) Create a .bat
file that executes the R script (as suggested by Daniel O):
runscript.bat (located in C:\Users\user\runscript.bat
)
"C:\Program Files\R\R-4.0.0\bin\R.exe" CMD BATCH "C:\Users\user\myscript.R"
2) Bind the .bat
script to the Home
hotkey with the open-source software AutoHotkey by creating a .ahk
script (as suggested by D. Pardal):
bindscript.ahk (located in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
so it will automatically load-up on start-up, see this)
Home::Run, runscript.bat, C:\Users\user
3) Set environment variable for R on windows 10 following this tutorial.
Upvotes: 2