0

I want to download data series for the same indicator for different countries, from an online database called Quandl. I can use the same URL for each request, but I only need to change the country code.

The code below does not work, could someone help me with the right R code?

This is my first question on stackoverflow, apologies if I am not up to par yet with all stackoverflow rules. I have tried searching for an answer using google etc. No succes so far...

install.packages("Quandl")
library(Quandl)

x.df <- data.frame(x)

countries <- c("BE", "ESP")

for(i in countries){
    temp.df <- Quandl("AMECO/", i, "_1_0_319_0_UBLGAPS", start_date = "1995-12-30", collapse = "annual")
    x.df <- merge(x.df, temp.df, all=TRUE)
    }

I get this error message:

Error in match.arg(transform) :
'arg' should be one of “”, “diff”, “rdiff”, “normalize”, “cumul”, “rdiff_from”

TJT
  • 1
  • 1
  • 1
    Seems I don't have access to AMECO through my free access to Quandl. you should try `Quandl(paste0("AMECO/",i,"_1_0_319_0_UBLGAPS", ...))` – Eric Lecoutre Jul 13 '16 at 15:36
  • 1
    @TJT ; you should choose an example where someone with free access can do testing. You should also edit your question to load all necessary non-base packages. – IRTFM Jul 13 '16 at 15:37

1 Answers1

0

To explain the reason for the particular error that is being thrown. This call:

 Quandl("AMECO/", i, "_1_0_319_0_UBLGAPS", start_date = "1995-12-30", collapse = "annual")

.... has a bunch of unnamed arguments and the third argument, "_1_0_319_0_UBLGAPS" is getting positionally matched to the transform parameter in the Quandl function which only accepts the values listed in the error message. This running example modified from the Quandl/R help page shows that Eric Lecoutre's advice was on-point:

> data <- Quandl(code=paste0("WIKI/", "FB.", 11), 
                 start_date="2014-01-01", 
                 end_date="2014-12-31", 
                 collapse="monthly", 
                 transform="diff")
> str(data)
'data.frame':   11 obs. of  2 variables:
 $ Date      : Date, format: "2014-12-31" ...
 $ Adj. Close: num  0.32 2.71 -4.05 4.22 2.17 ...
 - attr(*, "freq")= chr "daily"

Moral of this tale: when faced with a match.arg error, go back and name all your function arguments.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Thank you 42-. Still puzzling a bit on how to get the R function right to download time series data for one indicator about different countries. But I will dive into the sources you mentioned and will get back to you if I still can't get the code right. – TJT Jul 13 '16 at 21:29
  • If both "AMECO/BE_1_0_319_0_UBLGAPS" and "AMECO/ESP_1_0_319_0_UBLGAPS" succeed when used singly then rather than trying to "merge" perhaps you should instead append in a list or `rbind.data.frame` after adding an ID column. We are crippled in furhter efforts because of the lack of you either describing those datasets or using an example that does not require a paid subscription. – IRTFM Jul 13 '16 at 22:15