Closed rirdebseds closed 8 years ago
I am afraid you will have to contact the maintainer of the XBRL package (https://cran.r-project.org/web/packages/XBRL/index.html) to report issues related to these functions.
But I think you can avoid the problem by checking url with url.exists
before running the xbrlDoAll
function. In your case the problem was most likely in the connection to edgar server.
For example:
xbrl_url <- "http://www.sec.gov/Archives/edgar/data/21344/000002134413000050/ko-20130927.xml"
if( !RCurl::url.exists(xbrl_url) ) {
stop("Connection error")
}
From both RStudio and console R version 3.3.0 (2016-05-03) I am getting an IO error from the high and low level XBRL library commands that ends up locking my R session.
Code used is the example code from the CRAN pdf, and tested with multiple different xbrl xml files on SEC site as well as stored locally.
The level 1 function, xbrlDoAll, fails straight away with an IO error and then R hangs. The level 2 functions work until you get to xbrl$openInstance(inst), which throws the I/O error. If you continue to then ecexute xbrl$processSchema(xbrl$getSchemaName()) you will hang R - possibly what is happening when calling the level 1 function.
The level 3 function xbrlParse(inst) throws the same IO error. For convenience here is the example code:
## Setting stringsAsFactors = FALSE is highly recommended
## to avoid data frames to create factors from character vectors.
options(stringsAsFactors = FALSE)
## Load the library
library(XBRL)
## XBRL instance file to be analyzed, accessed
## directly from SEC website:
inst <- "http://www.sec.gov/Archives/edgar/data/21344/000002134413000050/ko-20130927.xml"
## Level 1: Function that does all work and returns
## a list of data frames with extracted information:
## Not run:
xbrl.vars <- xbrlDoAll(inst, verbose=TRUE)
## Level 2: Using the XBRL() "mutable state" function:
xbrl <- XBRL()
xbrl$setCacheDir("XBRLcache")
xbrl$openInstance(inst)
## Perform a discovery of the taxonomy:
xbrl$processSchema(xbrl$getSchemaName())
## Process instance file:
xbrl$processContexts()
xbrl$processUnits()
xbrl$processFacts()
xbrl$processFootnotes()
xbrl$closeInstance()
xbrl.vars <- xbrl$getResults()
inst <- "~/R/StockTickers/XBRLdocs/ph-20160331.xml"
xbrl$setCacheDir("~/R/StockTickers/XBRLdocs")
## End(Not run)
## Level 3: Using specialized functions that call C++ code directly:
## Parse the instance (doc is an pointer to external memory that needs to be freed):
doc <- xbrlParse(inst)
## Get a data frame with facts:
fct <- xbrlProcessFacts(doc)
## Get a data frame with contexts:
cts <- xbrlProcessContexts(doc)
## Get a data frame with units:
unt <- xbrlProcessUnits(doc)
## Free the external memory used:
xbrlFree(doc)