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
2
votes
1 answer

R - is there a limit to data that can be passed to an R file via RScript

I'm invoking RScript via this command: RScript myScript.R var1, var2, var3 This works if the length of variables is small. However, as soon as it exceeds a certain length (say over a 1000 characters) it breaks. Is there a limit to the length of…
Najla August
  • 81
  • 1
  • 12
2
votes
1 answer

Rscript launch custom R

Do you know how to specify R binary which will be launched by Rscript? It points to /usr/lib/R/bin/R by default. $ Rscript --verbose -e 'Sys.getenv("R_HOME")' running '/usr/lib/R/bin/R --slave --no-restore -e Sys.getenv("R_HOME")' [1]…
Cron Merdek
  • 1,084
  • 1
  • 14
  • 25
2
votes
2 answers

How to multiply each element of a dataframe by sum of element in each row in R?

I have a data frame as given below: Name Place a b c sum xyz mno 1 2 3 6 pqr jkl 4 6 1 11 I would like a command in R script which would help me divide numerical values in column "a", "b" and "c" by value in…
2
votes
0 answers

Passing value to a function through R CMD BATCH

I have a function created in R for test purpose that will get two values, add them and assign the result to a variable and the result will be stored in a csv file. Below is my r code f2 <- function(x, y) { args=(commandArgs(TRUE)) z1 <- x +…
Karthik Venkatraman
  • 1,619
  • 4
  • 25
  • 55
2
votes
1 answer

Writing an RDA to CSV in R

I'm trying to write a script to load an RDA by filename and write an equivalent file out as CSV. It's almost there (with the loading and writing) however the output CSV contains the vector of strings returned by load(), rather than the data frame…
Nick
  • 2,803
  • 1
  • 39
  • 59
2
votes
0 answers

Rscript not working in qsub cluster

I have two Rscripts named iHS.hist.R and Fst.hist.R. I know both scripts work. When I use the following commands in my directory in my ubuntu terminal I get a histogram plot for each script (two total if I do both scripts) module load R Rscript…
Evan
  • 1,477
  • 1
  • 17
  • 34
2
votes
2 answers

Running Rscript in command line and loading packages

I have a foo.R file which contains library("ggplot2") cat("Its working") I am trying to run foo.r via the command line using the Rscript commandRscript --default-packages=ggplot2 foo.R and it is giving me the following error: 1: In…
kasun61
  • 83
  • 2
  • 7
2
votes
2 answers

Rscript: how is $ interpreted in strings passed as inline code

Does anyone know how $ is interpreted within an inline call to rscript? In the example below, I am trying to get z to be the "a" element within the x list. However, z=x$a gives me x instead of the element of the list. > Rscript -e "x =…
W7GVR
  • 1,990
  • 1
  • 18
  • 24
2
votes
2 answers

Avoid loading libraries on multiple run of R script

I need to run (several times) my R script (script.R), which basically looks like this: library(myLib) cmd = commandArgs(TRUE) args=myLib::parse.cmd(cmd) myLib::exec(args) myLib is my own package, which load some dependencies (car, minpack.lm, plyr,…
2
votes
1 answer

How do you control the lifetime of a Rook server?

I am new to R and to Rook. I am able to successfully run Rook in a browser when I run from RTerm or from RStudio. However, when I run from RScript I get connection refused. My guess is that RScript runs my script and exits the script. So how would I…
Chet Murphy
  • 51
  • 1
  • 3
2
votes
1 answer

/usr/bin/Rscript: Argument list too long

Using rscript inside a bash script I am passing the content of text files has arguments. to rscript "$SCRIPTS/myscript.R" "$filecontent" I get the following when file have +- over 4000 row /usr/bin/Rscript: Argument list too long Any way I can…
2
votes
1 answer

Running R script from command line does not execute the code

I have tried both Rscript and R CMD BATCH. For example, if I run this simple R script: test <- function(){ print("test") } by using > R CMD BATCH test.R I get the following test.Rout file: R version 3.0.1 (2013-05-16) -- "Good Sport" Copyright…
user3181905
  • 119
  • 1
  • 2
  • 5
2
votes
1 answer

Libraries not loading when running Rscript from PHP

I am trying to run an R script from PHP. My PHP file looks like this: exec("Rscript fig_lollipop.r"); And my R script looks like this: library('RPostgreSQL') #more goes code here... I keep getting the following error: Error in…
2
votes
0 answers

R, Rscript, Works when variables hard coded, but not when passed as argument

I built the following R script to take a .csv generated by an automated report and split it into several .csv files. This code works perfectly, and outputs a .csv file for each unique value of "facility" in "todays_data.csv": disps <-…
2
votes
1 answer

How do I tell summary to not wrap columns?

I am trying to get summary to not wrap its output. However, when I call summary with 5 columns of data, it places the 5th column on a separate row. I am hoping there is a way that's easier than manually printing iterating over the object returned by…
joseph
  • 2,429
  • 1
  • 22
  • 43