Manish
Manish

Reputation: 3531

How to pass command line parameters in R-Studio?

I am using LaTeX and R to generate a geographical report. But I need to pass one text file as input. I need to run it on the Terminal using the following command:

R -e "Sweave('$PRGDIR/Test.Rnw')" <Input File> 1 0

Bu running on the Terminal is not a good practice while using an IDE (R-Studio). How can I do it using R-Studio?

Upvotes: 1

Views: 1874

Answers (1)

Daniel Chen
Daniel Chen

Reputation: 360

I've had a similar problem, and the way I solved it was to create a variable in the shell call as follows:

R -e "file <- 'input_file.txt'; param1 <- 1; param2 <- 2; Sweave('$PRGDIR/Test.Rnw')"

within the .Rnw script do a check to search for the variables using the exists function:

if(exists("file")){
    # do stuff here
} else{
    stop('I Need a file!')
}

Upvotes: 1

Related Questions