Bat file to run file.r

3

I would like to use a .bat file to run a particular .r file daily with the windows taskmanager, but I can not get it to run.

My steps: 1) open notepad

2) enter code, which is currently:

"C:\Program Files\R\R-3.3.0\bin\i386\Rscript.exe" --vanilla  "G:\Macroeconomia\Economistas\Coleta\Prohort\Prohort.R"

3) save the file in .bat format

4) two clicks to run it

However the bat does not run entire, it just loads the packages from my code and dates.

    
asked by anonymous 10.04.2017 / 21:07

2 answers

1

As spoken by colleague Marcos Nunes: By default, Windows closes the terminal when some script finishes running. I recommend getting into the terminal, navigating to where the Prohort.R file is (i.e., the specific directory inside drive G :) and running "C:\Program Files\R\R-3.3.0\bin\i386\R.exe" CMD BATCH Prohort.R . This will generate a Prohort.Rout file and inside it will be the log of R. There you will be able to see what went wrong in your script. That is, find out why it is just loading the packages, without running anything else.

So by opening the .Rout file as a notepad I was able to see the crash!

    
11.04.2017 / 19:29
1

@Danilo Imbimbo, I made a script in R, which loads packages and performs some tasks as well. Answering your question, when you run your * .bat it opens the cmd and closes and you see nothing because you probably do not put any function in the script that saves some file or image. If you create a script that only generates objects within the R environment, but uses no function to export the results out of the R environment, you will not see the results (I believe you wanted to see the R outputs somewhere). So you need to edit your script and put some functions like "write.table ()" to save some objects and so on. What you did would be as if you opened the R, rolled through the analysis and closed the R without saving anything.

    
30.07.2018 / 04:46