0

The following code produces the error:

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

library(Quandl)
std_chart<-function(qcode, type="raw", transform= "", collapse="", logscale="",
                main="", xlab="", ylab="", recession_shading=TRUE, hline="",
                trend=""){
data<-Quandl(code=qcode,type=type,transform=transform,collapse=collapse)
return(data)
}

std_chart(qcode="FRED/GDP",
      logscale="log10",
      main="Gross Domestic Product (GDP) Value",
      ylab="Billions of Dollars")

std_chart(qcode="FRED/GDP",
      transform="",
      logscale="log10",
      main="Gross Domestic Product (GDP) Value",
      ylab="Billions of Dollars")

Both calls to the function produce the same error. When I debug it seems the argument is one of the choices per the following:

Browse[1]> arg==choices[1] [1] TRUE

I've used this Quandl function many times without problem. Any help appreciated. I'm thinking the problem is obvious and I'm still missing it. This is just a simplified version of what I am actually trying to do to focus on the error.

Using R version 3.1.2 Quandl version 2.8.0

rmacey
  • 599
  • 3
  • 22
  • The error message seems fairly clear. I don't know why you think an object named `choices` has anything to do with this. If you make the default of your transform-argument 'diff' you then get an error message saying there is no match for 'collapse', and if you fix that you get expected output. Voting to close as too trivial for an answer. – IRTFM May 14 '16 at 07:55
  • @42 I'm glad it's clear to you. Please share a bit more of your wisdom. The statement Quandl(code="GOOG/AMEX_EEM",type="raw",transform = "") produces the error 'arg' should be one of “”, “diff”, “rdiff”, “normalize”, “cumul”, “rdiff_from”. Why isn't "" valid to pass? In this case I do not want any transform. I understand that I could call this statement without the parameter, but I am trying to build a function which passes through the transform parameter. Thank you. – rmacey May 14 '16 at 12:50
  • It says that the argument "transform" should be one of those choices and you gave "transform" a value"". Your call did not pass a value to transform either. EricLeCoutre and Macey gave two different solution, both of which make sense. A third solution is to just remove the `transform=transform` from the Quandl call and you will get the default for that parameter. – IRTFM May 14 '16 at 16:33
  • I do agree that the documentation is very misleading on this point. Either the help page or the function should be rewritten. – IRTFM May 14 '16 at 16:52

2 Answers2

2

If you analyse parameters management, behinds the scene match.arg relies on pmatch, which does not manage empty strings matching:

look at ?pmatch

pmatch("", "")                             # returns NA

As your std_chart function is just a wrapper around Quandl queries, I would recommend basing your code on '...':

enstd_chart<-function(qcode, logscale="",
                main="", xlab="", ylab="", 
                recession_shading=TRUE, hline="",
                trend="",...){
 # ...: parameters to be passed to Quandl call
 data<-Quandl(code=qcode,...)
 return(data)
}

std_chart(qcode="FRED/GDP",
      logscale="log10",
      main="Gross Domestic Product (GDP) Value",
      ylab="Billions of Dollars")

std_chart(qcode="FRED/GDP",
      collapse="annual")
Eric Lecoutre
  • 1,461
  • 16
  • 25
1

Instead of passing "" to the function, one needs to pass NULL to the function. It is odd that documentation of a function such as Quandl includes

transform = c("", "diff", "rdiff", "normalize", "cumul", "rdiff_from")

which seems to suggest that "" is a valid argument. So instead of calling the function with

Quandl(code,transform="")

which will generate the error, use

Quandl(code, transform=NULL).
rmacey
  • 599
  • 3
  • 22