Bat file to run file. r

Asked

Viewed 968 times

3

I would like to use a . bat file to run a particular file. r daily with windows taskmanager, but I’m not getting it running.

My steps are as follows: 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 format . bat

4) two clicks to rotate it

However the bat does not run whole, it only loads the packets of my code and closes.

  • What do you mean "it only loads the packets of my code and closes"?

  • The beginning of my R code is a function that loads all the packages needed to run the code, so when I run the bat, you can see "loading Packages", then it closes

  • If it closes, it is because it finished the execution. Put a pause at the bottom of your.

  • but it is not running until the end, so much so that the files it generates are not being updated

  • 1

    By default, Windows closes the terminal when some script finishes running. I recommend entering the terminal, navigating to where the file Prohort.R is (i.e., the specific directory inside the drive G:) and runs "C:\Program Files\R\R-3.3.0\bin\i386\Rscript.exe" CMD BATCH Prohort.R. This will generate a file Prohort.Rout and inside it will be the log of R. There it will be possible to see what went wrong in your script. That is, find out why.

2 answers

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 don’t see anything because you probably don’t put any function in the script that saves any file or image. If you create a script that only generates objects within the R environment but doesn’t use any function to export the results out of the R environment, you won’t see the results (I believe you wanted to see the R outputs somewhere). Then 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, ran the analysis and closed the R without saving anything.

1


As spoken by colleague Marcos Nunes: By default, Windows closes the terminal when some script finishes running. I recommend entering the terminal, navigating to where the file Prohort.R is (i.e., the specific directory inside the drive G:) and runs "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 R log. There you can see what went wrong in your script. That is, find out why he is just loading the packages, without running anything else.

Thus, opening the file . Rout as notepad managed to visualize the crash!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.