通过在R中使用函数getSeries的错误消息

时间:2018-09-30 03:31:17

标签: r

我需要在此处从此例程/程序包下载一些数据:

library(SSOAP)
library(XML)
library(RCurl)

wsdl <- getURL("https://www3.bcb.gov.br/sgspub/JSP/sgsgeral/FachadaWSSGS.wsdl", 
               ssl.verifypeer = FALSE)
doc  <- xmlInternalTreeParse(wsdl)

def <- processWSDL(doc)
ff  <- genSOAPClientInterface(def = def)


getSeries <- function(codigos, data.ini = "01/01/1998", data.fim = "01/01/2011", remove.old = TRUE) {
  xmlstr <- ff@functions$getValoresSeriesXML(codigos, data.ini, data.fim, 
                                             .opts = list(ssl.verifypeer = FALSE))
  doc <- xmlInternalTreeParse(xmlstr)

  cleanup <- xpathApply(doc,"//SERIE", function(s) {
    id <- xmlGetAttr(s, "ID")
    s1 <- xmlSApply(s, function(x) xmlSApply(x, xmlValue))
    s1 <- t(s1)
    dimnames(s1) <- list(NULL, dimnames(s1)[[2]])
    df <- as.data.frame(s1, stringsAsFactors=FALSE)
    df$SERIE <- id
    df
  })
  df <- Reduce(rbind, cleanup)

  df$data  <- as.Date(sapply(strsplit(df$DATA,  "/"),
                             function(x) paste(c(x[2:1], 1), collapse="-")), "%Y-%m-%d")
  df$valor <- as.numeric(df$VALOR)
  df$serie <- factor(df$SERIE)

  if(remove.old){
    df$BLOQUEADO <- NULL
    df$SERIE <- NULL
    df$DATA <- NULL
    df$VALOR <- NULL
  }
  df
}

# Testing the function

codigos <- c(4606, 4607, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616)
df <- getSeries(codigos)

我收到此错误消息:

Error in ans["xsi:type"] <- XMLSchemaTypes[[m]][["xsi:type"]] : 
  replacement has length zero

这是怎么回事?

此函数(getSeries)的github在这里:

https://gist.github.com/arademaker/1550651

已经安装了软件包和最新的JAVA,但仍然无法解决此问题。

有帮助吗?

0 个答案:

没有答案