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

Rscript does not recognize setGeneric function

I am trying to convert an R script into something that a client can run in batch mode. My code uses generic functions and one snippet which is near the beginning goes like: setGeneric("testInput", function(inputData, params = list()) …
Branko K.
  • 41
  • 2
3
votes
1 answer

Executing expressions in Rscript.exe

I'd like to put some expressions that write stuff to a file directly into a call to Rscript.exe (without specifying file in Rscript [options] [-e expression] file [args] and thus without an explicit R script that is run). Everything seems to work…
Rappster
  • 12,762
  • 7
  • 71
  • 120
3
votes
1 answer

how to connect to Rserve with an R client

I'm not sure if I am doing this right. In tab 1, I open R, then I execute Rserve(port = 6311) inside the R session. I load the variable "name = Hello World" In tab 2, I open R, then I try to connect to Rserve. I do this by: c = RSconnect(host =…
user1103294
  • 423
  • 3
  • 6
  • 16
3
votes
2 answers

Rscript and Backticks

I need to run knit2html on the command line using Rscript. I tried the following code and it works Rscript -e "(knitr::knit2html(text = '## good', fragment.only = TRUE))" However, when I introduce R code chunks (or anything involving backticks),…
Ramnath
  • 54,439
  • 16
  • 125
  • 152
3
votes
1 answer

Replacing rows in R

In R am reading a file with comments as csv using read.data.raw = read.csv(inputfile, sep='\t', header=F, comment.char='') The file looks like this: #comment line 1 data 1xy #comment line 2 data 2xy data 3xy Now I…
Omar Wagih
  • 8,504
  • 7
  • 59
  • 75
2
votes
2 answers

Is there a better way to hierarchically cluster in R?

I would like to do hierarchical clustering by row and then by column. I came up with this total hack of a solution: #! /path/to/my/Rscript --vanilla args <- commandArgs(TRUE) mtxf.in <- args[1] clusterMethod <- args[2] mtxf.out <- args[3] mtx <-…
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
2
votes
3 answers

Print a plot I have saved in the environment anywhere in Rmarkdown

I create an Rmarkdown document where I would like to create a plot at the start of the document, and then print it at the end of the document. I thought the best way to achieve this would be to save the plot in the environment and then recall it…
2
votes
1 answer

load average boost up to 1000+ after adding a Rscript while submit my job using slurm

I submit my job using slurm, at the beginning, everything works well. After adding a Rscript to perform a simple filtering, the system load average suddenly boost up to 1000+, this is quite abnormal. I've tring to search through Google, but find…
sirenfrappe
  • 57
  • 1
  • 5
2
votes
0 answers

R parse() function fails if text contains \r (carriage return)

I'm using R3.4.4 for Windows. I parse multi-line text containing R code to be feed into eval(). When the lines are separated by line feed ('\n') parsing is successful. But if they are seperated by carriage return ('\r') or ('\r\n') then the function…
Adi E
  • 478
  • 2
  • 4
  • 9
2
votes
3 answers

How to combine duplicate rows in R?

I'm using R to create a data frame with several duplicate columns. I'd like to consolidate all of the duplicated columns into a single column. How to do this in R? Note 1 : When I build dataframes with multiple columns, R adds numbers to the names…
Kevin Tracey
  • 154
  • 1
  • 16
2
votes
1 answer

Override Specific Compiler Flags When Installing R Packages

I have a R script that tries to install many packages (omitted all but showing just one): install.packages("zoo") Then I run Rscript my_r.r Then, I noticed it will try to compile some C code: gcc -m64 -std=gnu99 -I"/usr/include/R" -DNDEBUG…
HCSF
  • 2,387
  • 1
  • 14
  • 40
2
votes
2 answers

Create a report with total percentages per question option in R script

I've got a dataset with groups and a bunch of yes/no value (0=no, 1=yes). I'm trying to create a report with the totals per group, and nice layout, using just R-script. Here's what I've got so far. # test data (real data from API service is…
BdR
  • 2,770
  • 2
  • 17
  • 36
2
votes
1 answer

Exit code when calling R script from bash

I have an R script that I call from an interactive bash shell (MacOS Catalina). This is one of a series of scripts that I call from the interactive shell, so I need to know if the initial script failed. It seems that no matter how the script fails…
Ben Carlson
  • 1,053
  • 2
  • 10
  • 18
2
votes
1 answer

R beakr script as Rscript Windows 10 service

I'm trying to setup a simple beakr service in Windows that implements the example at https://github.com/MazamaScience/beakr. I'm able to run the script from the command line successfully and I've been able to add the service in Windows using NSSM,…
lagerratrobe
  • 151
  • 4
2
votes
2 answers

Loading R package inside R script

I tried several ways on loading few specific packages inside my script.R to run the script in terminal by typing ./Rscript script.R. There is no problem with the script but I get an error when I want to load a package e,g tidyverse. Error: package…
Apex
  • 1,055
  • 4
  • 22