0

I'm new to R and I'm wondering if R has something similar to SAS program where it can store the codes? I need to run the analysis on my data set (update monthly) every month. In SAS, I can just run the program and it will give me the results. I'd like to know if R has something similar to that? Thank you so much!

[Update] Thanks for the answers. R script is what I'm looking for!

OwenZ
  • 3
  • 3
  • 1
    I'm not sure what you mean - just store your code in a text file and then `source()` it when necessary. SAS files are just plain text too, so i'm not sure what difference it makes. Oh, and this isn't the place for such questions - Stackoverflow is for specific programming questions. – thelatemail Mar 24 '16 at 02:27
  • Thanks for the explanation. That solved my question. – OwenZ Mar 24 '16 at 22:08

2 Answers2

0

Yes. Just like you can create SAS programs in the enhanced editor, you can create R scripts in R. This process is even easier, in my opinion, when you write your R scripts using the tools that come with R Studio.

Brad Cannell
  • 3,020
  • 2
  • 23
  • 39
0

Are you just talking about running an R script?? If you have a text file called codefile.R containing R code, then from within an interactive R session source("codefile.R") will run it. Or you can use R CMD BATCH codefile.R from a command line/shell/terminal.

update: Dirk Eddelbuettel points out that Rscript or the littler package are recommended over R CMD BATCH ...

Community
  • 1
  • 1
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 1
    Boooo. Don't promote `R CMD BATCH`. We've had `Rscript` for almost a decade, ie almost as long as littler, and it is vastly superior. – Dirk Eddelbuettel Mar 24 '16 at 02:51
  • you can edit the question if you like ... (I am so backward that I'm still confused by the difference between `Rscript -e`, `echo {text} | R --slave`, and `r` ...) – Ben Bolker Mar 24 '16 at 12:33
  • Feel free to search on SO for that then :) The question has been addressed a few times. – Dirk Eddelbuettel Mar 24 '16 at 12:40
  • still haven't found the information for `Rscript -e` vs `echo ... | R --slave` -- I know there's something about which packages/environment stuff get loaded by default. If I find time maybe I'll try to write a SO question. – Ben Bolker Mar 24 '16 at 13:03