Search code examples
rquantmod

Download-Save-Load roundtrip with Quantmod in R


I want to download data using quantmod, save them to files to be loaded later.

The following piece of R code

library(quantmod)

symbols <- c("DEXUSUK", "STLFSI", "GDP")
tmpdir <- tempdir()

getSymbols(symbols, src="FRED")
saveSymbols(symbols, file.path=tmpdir)

rm(list = symbols)

getSymbols(symbols, src="RData", dir=tmpdir, extension="RData")

produces an error on the last line:

Error in `colnames<-`(`*tmp*`, value = c("DEXUSUK.Open", "DEXUSUK.High",  : length of 'dimnames' [2] not equal to array extent

Yet valid .RData files get created in the temp. location and can be load()-ed individually.

Is this a problem in quantmod (using version 0.4-3 on R 3.1.2) or is this usage invalid?


Solution

  • You need to specify col.names

    getSymbols(symbols, src="RData", dir=tmpdir, extension="RData", col.names="Close")
    #[1] "DEXUSUK" "STLFSI"  "GDP"