Error using getSeries function to pull BACEN data

1

Could you help me?

I need to download data from the central bank using this routine here:

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)

I get the following error:

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

What's happening?

The gitHub of this routine is here: https://gist.github.com/arademaker/1550651

I tried a lot of packages, I installed Java but I can not solve the problem.

Any help?

    
asked by anonymous 30.09.2018 / 05:01

0 answers