R.from.shell: Using R From a Shell

R.from.shellR Documentation

Using R From a Shell

Description

How to use R from a shell (including the Windows command-line / / Unix terminal).

Details

For the purpose of running R scripts, there are four ways to do it. Suppose our R script has filename script1.R, we could write any of:

  • ⁠R -f script1.R⁠

  • ⁠R --file=script1.R⁠

  • ⁠R CMD BATCH script1.R⁠

  • ⁠Rscript script1.R⁠

The first two are different ways of writing equivalent statements. The third statement is the first statement plus options --restore --save (plus option --no-readline under Unix-alikes), and it also saves the \codelink2base:showConnectionsstdout and \codelink2base:showConnectionsstderr in a file of your choosing. The fourth statement is the second statement plus options --no-echo --no-restore. You can try:

  • ⁠R --help⁠

  • ⁠R CMD BATCH --help⁠

  • ⁠Rscript --help⁠

for a help message that describes what these options mean. In general, Rscript is the one you want to use. It should be noted that Rscript has some exclusive \codelink2base:EnvVarenvironment variables (not used by the other executables) that will make its behaviour different from R.

For the purpose of making packages, R CMD is what you will need. Most commonly, you will use:

  • ⁠R CMD build⁠

  • ⁠R CMD INSTALL⁠

  • ⁠R CMD check⁠

R CMD build will turn an R package (specified by a directory) into tarball. This allows for easy sharing of R packages with other people, including submitting a package to CRAN. R CMD INSTALL will install an R package (specified by a directory or tarball), and is used by \codelink3utils:install.packagesinstall.packages(). R CMD check will check an R package (specified by a tarball) for possible errors in code, documentation, tests, and much more.

Where are my R executable files located?

In an R session, you can find the location of your R executable files with the following command:

R.home("bin")

For me, this is:

⁠/usr/lib/R/bin⁠


ArcadeAntics/this.path documentation built on Sept. 27, 2024, 1:45 p.m.