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

Rscript : Why is Error in UseMethod("extract_") : being indicated when attempting to use raster::extract?

I attempting to use raster package's extract method to extract values from a Raster* object. RStudioPrompt> jpnpe <- extract(jpnp, jpnb, fun = mean, na.rm = T) where jpnp is the raster object and jpnb is SpatialPolygonsDataFrame However the…
KK.
  • 693
  • 6
  • 15
7
votes
2 answers

Converting R command line arguments into integer vectors

I want to read command line arguments in R through Rscript and use the values stored in them for some integer operations. By default, the command line arguments are imported as characters: #!/usr/bin/env Rscript arg <- commandArgs(trailingOnly =…
Piyush Shrivastava
  • 1,046
  • 2
  • 16
  • 43
6
votes
1 answer

Passing arguments to R script in command line (shell/bash): what to do when column names contain tilde (~)

I'm utilizing Rscript to run an R script through bash, and I want to specify arguments to be passed to functions within the script itself. Specifically, I want to pass arguments that specify: path to data file (.csv) and certain column names in…
Emman
  • 3,695
  • 2
  • 20
  • 44
6
votes
1 answer

Is it possible to stop `Rscript` cleaning up its `tempdir`?

I'm using R, via Rscript and H2O, but H2O is crashing. I want to review the logs, but the R tempdir that contains them seem to be removed when the R session ends (i.e. when the Rscript finishes). Is it possible to tell R/Rscript not to remove the…
dommer
  • 19,610
  • 14
  • 75
  • 137
6
votes
1 answer

Rscript invalid font type in ggplot

I have a short script that produces a ggplot using a non-standard font (see MWE below). If I run the script in R (i.e., RStudio) everything works as expected and I see no error. When I run the script using the command line and Rscript I get the…
David
  • 9,216
  • 4
  • 45
  • 78
6
votes
1 answer

mclapply sendmaster error only with Rscript

I intermittently get the following error when using Rscript to call mclapply from the command-line: Error in sendMaster(try(lapply(X = S, FUN = FUN, ...), silent = TRUE)) : write error, closing pipe to the master If I run the exact same code in…
louiszya
  • 61
  • 3
6
votes
4 answers

Rscript file path with space

I am trying to run the following R script in windows shell: Rscript C:/Documents/Folder name containing space/myscript.txt In this case I get the error: Fatal error: cannot open file 'C:/Documents/Folder': No such file or directory However when I…
6
votes
1 answer

Error using rscript

I have a Homebrew version of R installed on my Mac (OS X, El Capitan 10.11.5). I've been using rscript successfully for about two weeks now. However, when I tried to run a script this morning using rscript file.r, I get the following…
K. Shores
  • 875
  • 1
  • 18
  • 46
6
votes
1 answer

Calling Rscript from linux shell script

Can anyone suggest how I might get this working.... I have an R script that takes several minutes to run and writes a few hundred lines of output. I want to write a shell script wrapper around this R script which will launch the R script in the…
David
  • 63
  • 6
6
votes
1 answer

Running an R script from Java

I've got a problem when I try to run a R script from Java Netbeans on Mac OS. I truly look for an answer of this problem on internet but nothing works. I've used Rserve and Runtime.getRuntime().exec("Rscript myScript.R") but neither of them works…
JaviMartinez
  • 61
  • 1
  • 3
5
votes
2 answers

External graphical device for littler or Rscript

I really like littler is really great for scripting using R. But i don't how to use external graphics device a la gnuplot (for example using Octave). I'm able to produce the desired graph but i have to use Sys.sleep and i don't want to do so,…
dickoa
  • 18,217
  • 3
  • 36
  • 50
5
votes
3 answers

Recursion error in R (Fibonacci sequence)

So I am trying to learn R on my own and am just working through the online tutorial. I am trying to code a recursive function that prints the first n terms of the Fibonacci sequence and can't get the code to run without the error: Error in if…
apr92
  • 51
  • 2
5
votes
1 answer

Rscript not finding installed packages in container

I am trying to schedule and R script to run inside a container. I have a docker file like this: # Install R version 3.5 FROM rocker/tidyverse:3.5.1 USER root # Install Ubuntu packages RUN apt-get update && apt-get install -y \ sudo \ …
Tom Greenwood
  • 1,502
  • 14
  • 17
5
votes
0 answers

Rscript not finding library

I have a problem when running R scripts on a Unix cluster as a batch job. The issue is when trying to load libraries in the environment, R cannot find the library. I'll give you an example. I'll use a basic R script names…
Dmotti
  • 51
  • 3
5
votes
0 answers

R Googlesheets package and gs_auth() function - Non interactive auto-refresh stale Token issue

I am running an R script that reads google sheet for every one hour. I am using googlesheets package and gs_auth() function for this. Initially I am storing the token from running gs_auth() with interactive authentication. From next time, the code…
R Bud
  • 261
  • 1
  • 4
  • 16
1 2
3
43 44