We can further extend the use of R by passing command line arguments to functions the way we do in multiple programming languages.
You will have to create a script in R which uses the arguments to process the data, we will use below script for example-
library(quantmod)
require(quantmod)
#! To Enable Command Line Arguments
args <- commandArgs(TRUE)
#! Using the Argument Value & Processing Data
symbolsHUL<-c(args[1])
getSymbols(symbolsHUL)
startT <- "2016-01-01"
endT <- "2017-01-01"
rangeT <- paste(startT,"::",endT,sep="")
#! We are still using Static Data here which will be fixed in next post
HUL <- HINDUNILVR.NS[,6][rangeT]
plot(HUL)
- Save the above script as Stock.R in working directory
- Run the below command from Command line
There should be HUL plot saved in working directory in the form of PDF.