Questions tagged [rscript]

Rscript (Rscript.exe on Windows) is a binary front-end to R, for use in scripting applications.

Rscript (Rscript.exe on Windows) is a binary front-end to R, for use in scripting applications. It is included in the core R distribution since version 2.5.0.

littler is an alternative front end to R for use in '#!' scripts.

Example:

Rscript

#! /path/to/Rscript
args <- commandArgs()
args <- args[-(1:match("--args", args)]
cat('hello world!', args, "\n")

littler

#! /path/to/r
cat('hello world!', argv, "\n")

Rscript passes all script arguments to R as additional elements to the vector returned from commandArgs().

littler provides convenience by assigning the script arguments to an argv vector and placing that into the global environment, a convention followed by other popular scripting languages.

656 questions
300
votes
31 answers

Determine path of the executing script

I have a script called foo.R that includes another script other.R, which is in the same directory: #!/usr/bin/env Rscript message("Hello") source("other.R") But I want R to find that other.R no matter what the current working directory. In other…
Frank
  • 64,140
  • 93
  • 237
  • 324
121
votes
6 answers

Passing command line arguments to R CMD BATCH

I have been using R CMD BATCH my_script.R from a terminal to execute an R script. I am now at the point where I would like to pass an argument to the command, but am having some issues getting it working. If I do R CMD BATCH my_script.R blabla…
Bryce Thomas
  • 10,479
  • 26
  • 77
  • 126
52
votes
2 answers

Why (or when) is Rscript (or littler) better than R CMD BATCH?

I am automating some webscraping with R in cron and sometimes I use R CMD BATCH and sometimes I use Rscript. To decide which one to use I mainly focus if I want the .Rout file or not. But reading the answers to some questions here in SO (like this…
Carlos Cinelli
  • 11,354
  • 9
  • 43
  • 66
43
votes
1 answer

Capturing Rscript errors in an output file

Unlike the similar command R CMD BATCH which by default produces an output file which contains any error messages which would cause the execution of a script to halt, I have not been able to find a way to do this with Rscript. I have tried using a…
R_User
  • 937
  • 1
  • 9
  • 17
35
votes
5 answers

Rscript: There is no package called ...?

I want to run R files in batch mode using Rscript, however it does not seem to be loading the libraries that I need. The specific error I am getting is: Error in library(timeSeries) : there is no package called 'timeSeries' Execution halted However…
pbreach
  • 16,049
  • 27
  • 82
  • 120
27
votes
1 answer

Rscript does not load methods package, R does -- why, and what are the consequences?

Just saw this: $ Rscript -e "sessionInfo()['basePkgs']" $basePkgs [1] "stats" "graphics" "grDevices" "utils" "datasets" "base" $ R --vanilla --slave -e "sessionInfo()['basePkgs']" $basePkgs [1] "stats" "graphics" "grDevices" "utils" …
krlmlr
  • 25,056
  • 14
  • 120
  • 217
21
votes
3 answers

How to Make my R script executable?

I am aware this is at high risk of being a duplicate, but in none of the other questions here I have found an answer to my problem. Below is a summary of what I have already tried. I have an R script file file.r: #!/usr/bin/env Rscript print("Hello…
k88074
  • 2,042
  • 5
  • 29
  • 43
20
votes
1 answer

How to pass Rscript -e a multiline string?

Is there a way to provide the code to Rscript -e in multiple lines? This is possible in vanilla R R --vanilla <
nachocab
  • 13,328
  • 21
  • 91
  • 149
19
votes
1 answer

print vs. echo in R

I'm running a batch process using Rscript. I would like to print messages to screen just like "echo" does in bash. So I use the function "print". The problem is that print's output does not go to the screen. It goes to the log file instead. Anybody…
Wilmer E. Henao
  • 4,094
  • 2
  • 31
  • 39
19
votes
6 answers

A web interface to an R program

I have to develop a web interface allowing the user to enter some inputs that will be passed to an Rscript as parameters and return the result to the user. I have some questions for someone who have done a similar web interface: Which web…
user1331120
  • 247
  • 2
  • 3
  • 8
17
votes
1 answer

automatically create personal library in R

When you try to install a package in R and you don't have access rights to the default library path, R will ask you: Would you like to use a personal library instead? Would you like to create a personal library '~/path' to install packages…
burger
  • 5,683
  • 9
  • 40
  • 63
15
votes
1 answer

Rscript could not find function

I need to run several scripts via the bash shell using Rscript and some functions I use require the function isGeneric. However, in this case the process end like that (for example): Error in .getLogLik() : could not find function…
Ludovic Duvaux
  • 307
  • 2
  • 10
14
votes
2 answers

Rscript - get rid of "WARNING: ignoring environment value of R_HOME"

Rscript is very handy. But I'd like to specify output paths at runtime, e.g.: my.Rscript input > output. message() is great for logging to STDERR, but Rscript seems to systematically output WARNING: ignoring environment value of R_HOME to STDOUT,…
Yannick Wurm
  • 3,617
  • 6
  • 25
  • 28
13
votes
1 answer

How do I test if R is running as Rscript?

I have code in a single R file that I want to be able to source (i.e., to define my functions etc.) within RStudio during development, and also run using the #! /usr/bin/env Rscript syntax via the command line (actually, using Hadoop). For the…
Chris
  • 941
  • 9
  • 18
13
votes
1 answer

Rscript detect if R script is being called/sourced from another script

I have a written a script that when it is sourced checks if the script is being run interactively using interactive(). If it is run interactively, it does not search for command line arguments. However, if it is not run interactively, it searches…
Brandon
  • 1,722
  • 1
  • 19
  • 32
1
2 3
43 44