I am trying to run a r script using batch file. Currently I am using
start"" "shortcut of R"
to open R. However, I wanna R automatically run a r script that I have saved on the computer.
Possibly R will be closed after running the script and user do not see R running.
Is that possible? Thanks a lot!
After you add Rscript to the path, in my case by adding the folder C:\Program Files\R\R-4.0. 2\bin\x64 to the path, be sure to open and close CMD for PATH to refresh. Then open a new window of CMD, and type Rscript , and tell me your output.
To run an R command, put the cursor on the line of the command and then click the Run button at the top of the file window. Or just press CTRL-Enter. In the next figure data was read, and a histogram created, with the lessR Histogram function.
/r - iterate through the folder and all subfolders, i.e. recursively. %%I - placeholder for a path/filename. The above command simply lists all files in the current folder and all subfolders. Follow this answer to receive notifications.
Rscript is a non-interactive variant of the standard R command, just designed for this kind of use.
For example, under windows you can define a launcher.bat
like this :
PATH PATH_TO_R/R-version/bin;%path%
cd PATH_TO_R_SCRIPT
Rscript myscript.R arg1 arg2
In myscript.R you add the code to read the arguments:
args <- commandArgs(trailingOnly = TRUE)
arg1 <- as.character(args[1])
arg2 <- as.numeric(args[2])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With