Generate a Windows command file and execute it in R

R is a powerful language. It can be used to process data and communicate with database and so on. The following functions are used to automatically download historical data of a list of stocks. The argument of the generateCMD function (stocklist) is a vector of stock symbols. The function can generate CMD command strings and store them into a CMD file and then execute the CMD file. To do this, you have to install “curl” on your windows system. You can download an appropriate lastest version of the CURL application from

toNumerics {
stopifnot(inherits(Date, c(“Date”, “POSIXt”)))
day month year list(year = year, month = month, day = day)

generateCMD {
cmdtext for (i in 1:length(stocklist))
stocksymbol # get today’s day, month, year information
today mydatecom day month year # download the data from the internet
cmdstr cmdtext }
cmdtext write(cmdtext, file=”dlcmd.cmd”)
system(“dlcmd.cmd”, wait=T)

This entry was posted in Tips. Bookmark the permalink.

Leave a Reply