Skip to content

Commit

Permalink
XML replaced with xml2, fix #98
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Feb 3, 2016
1 parent 698719a commit 75b96e5
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 15 deletions.
2 changes: 0 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ Imports:
methods,
stats,
jsonlite,
XML,
httr (>= 1.0.0),
plyr,
bibtex,
dplyr,
R6
Suggests:
testthat,
roxygen2 (>= 4.0.1),
knitr
RoxygenNote: 5.0.1
6 changes: 3 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ export(get_styles)
export(id_converter)
export(pmid2doi)
importFrom(R6,R6Class)
importFrom(XML,xmlAttrs)
importFrom(XML,xmlParse)
importFrom(XML,xpathSApply)
importFrom(bibtex,read.bib)
importFrom(dplyr,bind_rows)
importFrom(dplyr,rbind_all)
Expand All @@ -69,3 +66,6 @@ importFrom(plyr,llply)
importFrom(plyr,rbind.fill)
importFrom(stats,setNames)
importFrom(utils,modifyList)
importFrom(xml2,read_xml)
importFrom(xml2,xml_attr)
importFrom(xml2,xml_find_all)
10 changes: 4 additions & 6 deletions R/cr_citation_count.r
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ cr_citation_count <- function(doi, url = "http://www.crossref.org/openurl/",
key = "cboettig@ropensci.org", ...)
{
## Assemble a url query such as:
#http://www.crossref.org/openurl/?id=doi:10.3998/3336451.0009.101&noredirect=true&pid=API_KEY&format=unixref
args <- list(id = paste("doi:", doi, sep=""), pid = as.character(key),
args <- list(id = paste("doi:", doi, sep = ""), pid = as.character(key),
noredirect = as.logical(TRUE))
# args$format=as.character("unixref")
cite_count <- GET(url, query = args, ...)
stop_for_status(cite_count)
ans <- xmlParse(ct_utf8(cite_count))
if(get_attr(ans, "status") == "unresolved") NA else as.numeric(get_attr(ans, "fl_count"))
ans <- xml2::read_xml(ct_utf8(cite_count))
if (get_attr(ans, "status") == "unresolved") NA else as.numeric(get_attr(ans, "fl_count"))
}

get_attr <- function(xml, attr){
xpathSApply(xml, sprintf("//*[@%s]", attr), function(x) xmlAttrs(x)[[attr]])
xml2::xml_attr(xml2::xml_find_all(xml, sprintf("//*[@%s]", attr)), attr)
}
3 changes: 2 additions & 1 deletion R/cr_ft_text.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#' # xml and plain text links
#' out <- cr_works(filter=c(has_full_text = TRUE))
#' dois <- out$data$DOI
#' cr_ft_links(dois[1], "pdf")
#' cr_ft_links(dois[2], "xml")
#' cr_ft_links(dois[1], "plain")
#' cr_ft_links(dois[1], "all")
Expand Down Expand Up @@ -227,7 +228,7 @@ cr_auth <- function(url, type) {
getTEXT <- function(x, type, auth, ...){
res <- GET(x, auth, ...)
switch(type,
xml = XML::xmlParse(ct_utf8(res)),
xml = xml2::read_xml(ct_utf8(res)),
plain = ct_utf8(res))
}

Expand Down
2 changes: 1 addition & 1 deletion R/rcrossref-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#' @importFrom stats setNames
#' @importFrom dplyr rbind_all bind_rows tbl_df
#' @importFrom R6 R6Class
#' @importFrom XML xmlParse xpathSApply xmlAttrs
#' @importFrom xml2 read_xml xml_attr xml_find_all
#' @importFrom bibtex read.bib
#' @importFrom httr GET POST stop_for_status content_type_json accept_json content
#' write_disk accept http_status parse_url add_headers config
Expand Down
4 changes: 2 additions & 2 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ get_err <- function(x) {
if (x$headers$`content-type` == "text/plain") {
tmp <- xx
} else if (x$headers$`content-type` == "text/html") {
html <- XML::htmlParse(xx)
tmp <- XML::xpathSApply(html, '//h3[@class="info"]', xmlValue)
html <- xml2::read_html(xx)
tmp <- xml2::xml_text(xml2::xml_find_one(html, '//h3[@class="info"]'))
} else if (x$headers$`content-type` == "application/json;charset=UTF-8") {
tmp <- jsonlite::fromJSON(xx, FALSE)
} else {
Expand Down
1 change: 1 addition & 0 deletions man/cr_ft_text.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 75b96e5

Please sign in to comment.