How to pass command line arguments to run a Rscript

0 votes

Hello

I am a new user of R and I am stuck. I want to execute a Rscript that will allow me to compute some indices for many stations once. Here is what the manual says to do:

5.2 Calculating the indices on multiple station files 

The script that provides this functionality is climpact2.batch.stations.r. This script requires command line arguments to be passed to it at run time. Execution of this script takes the following form, from the Linux command line:

         Rscript climpact2.batch.stations.r /full/path/to/station/files/ /full/path/to/metadata.txt base_period_begin base_period_end cores_to_use

The 5 command line arguments above are defined in the following table.

Table 2. Command line arguments to pass to climpact2.batch.stations.r

/full/path/to/station/files/

Directory where individual station files are kept. An example can be found in sample_data/XXXX

/full/path/to/metadata.txt

Text file that contains information about each station file to process.

base_period_begin

Beginning year for the base period. To be used on all stations.

base_period_end

Ending year for the base period. To be used on all stations.

cores_to_use

Number of processor cores to use. When processing hundreds or thousands of files, this is useful.

An example of executing the climpact2.batch.stations.r file would be:

        Rscript climpact2.batch.stations.r ./sample_data/Renovados_hasta_2010 ./sample_data/climpact2.sample.batch.metadata.txt 1971 2000 4

I don't know how to run my script in R to get results. Please help me
 

Aug 4, 2018 in Data Analytics by Wendso
• 120 points
80 views

1 answer to this question.

0 votes

1. For taking an argument from the command line you'll have to create a function and save in an R file example as shown below:

add <- function(x+y) {
    x+y
}
Save it as a R file say "add.R"
2. Next in the command line or R script call the R script as shown in the function below:
From R GUI's command line:
source("add.R")
add(3, 5)
From R Script:
args <- commandArgs(TRUE)
x <- as.integer(args[1])
y <- as.integer(args[2])

source("add.R")

add(x,y)


answered Aug 6, 2018 by Anmol
• 1,620 points

Related Questions In Data Analytics

0 votes
1 answer

how to run a logistic regression with clustered standard errors in R?

have a look at rms package. lrm is logistic ...READ MORE

answered Nov 6, 2018 in Data Analytics by Kalgi
• 37,320 points
119 views
0 votes
1 answer

R programming: How to pass variables from a r program to mysql function?

To include the R variables called start.date and end.date, you can use paste to ...READ MORE

answered Dec 28, 2018 in Data Analytics by Tyrion anex
• 8,280 points
57 views
0 votes
1 answer

How to run a file with .r extension?

Follow the below command: C:\Program Files\R\R-3.1.1\bin\Rscript.ex ...READ MORE

answered Apr 29 in Data Analytics by Tyrion anex
• 8,280 points
19 views
+1 vote
1 answer

Need a hadoop engine in backend to run r server

Dear Koushik, Hope you are doing great. The hadoop ...READ MORE

answered Dec 17, 2017 in Data Analytics by Sudhir
• 1,610 points
38 views
0 votes
2 answers

How can I add YAML current date in rmarkdown ?

<$today:MM/dd/yyyy> READ MORE

answered Mar 25 in Data Analytics by Anupam Das
1,152 views
0 votes
3 answers

Python vs. R for data science

Hello Well there are lots of difference between ...READ MORE

answered Mar 30 in Data Analytics by MrBoot
• 1,210 points
70 views
0 votes
1 answer

Why is data cleaning needed?

Data cleaning is the fourth step in ...READ MORE

answered Nov 14, 2018 in Data Analytics by Maverick
• 10,040 points
14 views
0 votes
1 answer

What are the steps in data analysis process?

Need to follow these steps: Data requirements – ...READ MORE

answered Nov 14, 2018 in Data Analytics by Maverick
• 10,040 points
26 views
+1 vote
2 answers

avoid producing a eps-graphic with 2 pages by mixing traditional and grid graphics

The bv_set() is missing from your code hence ...READ MORE

answered Aug 27, 2018 in Data Analytics by Anmol
• 1,620 points
42 views
0 votes
2 answers

When scoring a logistic regression model , is having the predicted variable in test dataset mandatory ?

Answer to your follow up question: We can ...READ MORE

answered Oct 17, 2018 in Data Analytics by Anmol
• 1,620 points
39 views