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

How to pass an optparse argument to a R-markdown file while rendering?

I have an Report.Rmd file, that generates a pdf. Inside the .Rmd file I have some code with optparse, that receives a parameter from Rscript to use: ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) library(optparse) # get user as…
raoul
  • 197
  • 3
  • 14
2
votes
0 answers

Linux bash running Rscript closes itself, how do I trace the cause?

I have an Ubuntu server which runs a web scraping cron job daily at 0901. cron line: 01 09 * * 1-5 bash /root/FCPIDCheck.sh The file runs a pid checker to see whether the process is already running from the day before this stops instances from…
Freddie
  • 65
  • 4
2
votes
0 answers

Rscript and simple graph

[edit 3] At this point, it is possible for me to use the commands: library(Cairo) CairoPNG("test.png") pie( 1:10, labels=paste("label number",1:10)) dev.off() to obtain the same figure quality. Someone with apparently the same problem:…
Gildas
  • 998
  • 10
  • 16
2
votes
1 answer

What is causing the error "Z matrix not specified" when making a graph of vectors

I am making a graph for some vectors, and I have the following code (r script): calculating the derivatives #calculating the derivatives #x direction`#x direction gradientx2d_dd=function(x,dx){} dd=uwind xdim=dd[1] ydim=dd[2] gradx=0.0*uwind for (i…
N.Morris
  • 21
  • 3
2
votes
2 answers

R Error in validObject(.Object) when running as script, but not in console

The following code works fine in the R console (R 3.3.0): m = system.file("external/pores_1.mtx", package = "Matrix") x = Matrix::readMM(m) I can put it in a script and it runs fine in R console as: source("test.R") However, when I execute it as…
burger
  • 5,683
  • 9
  • 40
  • 63
2
votes
0 answers

Running r function with rscript fails after loading package "methods"

As the title says really: "C:\Program Files\R\R-3.3.2\bin\Rscript.exe" "D:\code\R\loadAndProcess.r" 10 ""DATA"" Fails. Any help is greatly appreciated! Here, is parts of code: library(jsonlite); settings_url <- "D:/SETTINGS.json"; settings_paths <-…
2
votes
0 answers

How to speed up the package/library loading time in R?

I have a run_stat.r script that can run in command line such as Rscript anova.r on my ubuntu server: #load package library(ez) #run code.... The problem is that the loading time of ez package would take 2~3 seconds. Can R preload the…
David.Z
  • 21
  • 1
2
votes
0 answers

how to get current script file name in R Script

i run file test.R in RStudio. how can i get full path (include file name) or just the file name of the current script : test.R thanks
Omry Atia
  • 73
  • 1
  • 9
2
votes
2 answers

calling an Rscript from node.js

I have been trying to execute an Rscript from my node.js server. tried to follow an example online, but i keep getting a null returned object or sometimes the process keeps running forever. I have mentioned the code snippet below. Thank…
2
votes
1 answer

Permanently change Rscript and R Sys.getenv("HOME")

Updated: When I open RStudio and enter Sys.getenv("HOME"), I get: [1] "C:/Users/Clayton/Documents" When I open git-bash, and enter Rscript -e "Sys.getenv('Home')" I get: "C:\\Users\\Clayton" This means Rscript and R can't load my packages from the…
Tunn
  • 1,506
  • 16
  • 25
2
votes
1 answer

How do I do I write a script to export a data frame to my desktop from RStudio Server?

I'm using RStudio Server version 0.99.903 and I want to create a script to export a data frame to my local machine running Windows 7. I can successfully export the data frame manually to the hard drive following the steps described HERE. I have…
2
votes
0 answers

Rscript: How to inject options for an R script

How can I set R options (e. g. options(keep.source = TRUE)) individually for R scripts that I execute via Rscript? In the Rscript docs I cannot find such a command line argument. I want to run the same R script with different options. My goal is to…
R Yoda
  • 8,358
  • 2
  • 50
  • 87
2
votes
1 answer

how to make R script stop when it has to read a line?

I want this code to ask for the value of x while I run the whole script but it doesn't wait for the input. Although it waits for a file to get uploaded by the user at line 3. While running it line by line this works fine and that is obvious. What is…
Yogesh
  • 1,384
  • 1
  • 12
  • 16
2
votes
2 answers

Where is my output text file from an R-script run in unix?

I am using R on a Unix system. I wrote an R script in windows, and uploaded it to Unix (via putty), such that I could run the script in R (in unix) with the command source('CODE.R'). Now, here is the problem. In my R script, I wrote…
NeverBe
  • 107
  • 1
  • 1
  • 7
2
votes
0 answers

Rscript and jsonlite on Windows - passing string arguments containing quotes

(R 3.3.1, Windows 10) Hi - I am trying to pass a string containing double quotes as an argument to an r script (so that I can parse it as JSON using toJSON from the jsonlite package) using the following format from the command prompt: rscript.exe…