0

以下代码产生错误:

match.arg(transform) 中的错误:'arg' 应该是“”、“diff”、“rdiff”、“normalize”、“cumul”、“rdiff_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")

对函数的两次调用都会产生相同的错误。当我调试时,参数似乎是以下选项之一:

浏览[1]> arg==选择[1] [1] TRUE

我已经多次使用这个 Quandl 函数没有问题。任何帮助表示赞赏。我认为问题很明显,但我仍然想念它。这只是我实际尝试关注错误的简化版本。

使用 R 版本 3.1.2 Quandl 版本 2.8.0

4

2 回答 2

2

如果分析参数管理,幕后match.arg依赖pmatch,它不管理空字符串匹配:

看着?pmatch

pmatch("", "")                             # returns NA

由于您的 std_chart函数只是 Quandl 查询的包装器,因此我建议您将代码基于“...”:

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")
于 2016-05-14T13:16:26.657 回答
1

无需将“”传递给函数,而是需要将 NULL 传递给函数。奇怪的是,像 Quandl 这样的函数的文档包括

变换= c(“”,“差异”,“rdiff”,“标准化”,“累积”,“rdiff_from”)

这似乎表明 "" 是一个有效的论点。所以而不是调用函数

Quandl(code,transform="")

这将产生错误,使用

Quandl(code, transform=NULL).
于 2016-05-14T13:05:02.693 回答