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

Running an R function over files in a Bash command line

I am trying to iterate a function I have written in R (strandcode.txt) over all of the files in a given directory. strandcode.txt is shown below, it's a simple function to compute a Chi Squared test. strand <- function(file){ data <-…
4
votes
1 answer

How to restore RStudio Viewer Pane after having setting its viewer option to NULL?

I have set the RStudio Viewer pane to open my default Web Browser instead of the View Pane by setting the following option: options(viewer=NULL) How do I reset back to original setting without starting a new rsession? I want again default to…
KK.
  • 693
  • 6
  • 15
4
votes
1 answer

Can I specify mandatory arguments with optparse

I am using the optparse package but cannot find out if I can specify mandatory arguments. install.packages('optparse') library('optparse') library('data.table') # example from vignette option_list <- list( # those 2 are linked together by…
statquant
  • 13,672
  • 21
  • 91
  • 162
4
votes
1 answer

Difference output running Rscript vs source

I have the following script: city <- c("Екатеринбург", NA, "Курск", "Псков", "березники", "Челябинск", NA, "москва", "москва", "Петергоф/Санкт-Петербург", "Петергоф/Санкт-Петербург", "Волгоград", "Олегегорск",…
Artem Klevtsov
  • 9,193
  • 6
  • 52
  • 57
4
votes
0 answers

Resolving an error running Rmarkdown from the command line

I want to run Rmarkdown from the command line that will save an HTML output (I don't care if the command line shows me the plot as it's run or not, as long as the result is saved). My Rmd script is something like: --- title: "Report" output:…
0xb36a
  • 41
  • 3
4
votes
1 answer

How to call Rscript from R?

I am developing a package that exposes an R interface (a bunch of functions to be used interactively) and a command line interface via Rscript. This second one works via a small launcher, for instance, at the command line: Rscript mylauncher.R arg1…
JavaNewbie
  • 241
  • 3
  • 6
4
votes
2 answers

How to run an R script file from the command line

I know there are a lot of questions regarding this issue but I've tried everything and I think I just don't understand how the command line works in windows. I have a file saved in a folder on my desktop, let's say: C:\Users\abika_000\Desktop\R…
road_to_quantdom
  • 1,341
  • 1
  • 13
  • 20
4
votes
1 answer

how do I suppress the message of a function in an R script?

A similar question was asked previously at: How do I suppress this output? However, that question is only applicable to Rmarkdown code blocks. In the following case I've created a script with only the following: library(UsingR) I've saved the file…
David
  • 981
  • 1
  • 15
  • 27
4
votes
5 answers

/usr/bin/env: RScript: No such file or directory | After recent R-3.0.1. installation.

I am a bit lost when dealing with installing and using R. I installed R 3.0.1 from source and did the ./configure, make, make check, and make install as suggested. However I tried running R but it said that R wasn't in the /usr/bin folder. So I then…
user2555016
4
votes
1 answer

Execution halted when I use knitr and Rscript with opts_chunk

I wrote a bash script in Mac OS that takes my .rnw file, knit it and then makes a .pdf. To knit my file, I'm using the command Rscript -e "library(knitr); knit('file.rnw', encoding='utf8')" and everything works fine. However, I don't want the ##…
Marcus Nunes
  • 851
  • 1
  • 18
  • 33
3
votes
1 answer

R Script and Library preloading?

I have created an R script that it needs to load some libraries first. The problem is that the script needs 1.6 seconds to finish its calculations (measured it many times with Linux command "time") and 0.7 seconds only takes to load the…
Vangelis Tasoulas
  • 3,109
  • 3
  • 23
  • 36
3
votes
0 answers

Problem with loading MASS package using library. What is the solution?

I am trying to load MASS package with this code: install.packages("MASS") library(MASS) But R is showing this error: > install.packages("MASS") Error in install.packages : Updating loaded packages > install.packages("MASS") Installing package into…
sam
  • 37
  • 4
3
votes
0 answers

How to restore the rhandsontable package's disabled 'Undo' from the context menu in R shiny

For one of my Rshiny app, I am referring to this R shiny code from StackOverflow: In R Shiny, how do you reset data (reversing all manual inputs) in rhandsontable using an actionButton? When we use the package "rhandsontable," the following code…
Kevin Tracey
  • 154
  • 1
  • 16
3
votes
0 answers

Tensorflow text classification in R using 3 classes - Error in py_call_impl(callable, dots$args, dots$keywords)

I'm working on a text classification problem that classifies some tweets into one of three labels. I have two columns in my dataset: Score column with the value of 0 (negative), 1 (positive) or 2 (neutral) and Statement column with the tweet text. I…
3
votes
1 answer

Run R script and hide the actual code from user

I have created an R code script that: Reads some data from a database Makes some transformations and.. exports into a csv the modified table. This code needs to run in a client's machine, but we need to "hide" the actual code from the user. Is…
Vamkos
  • 125
  • 1
  • 8