ropensci / aRxiv
1
# convert XML result from arxiv_search to a list format
2
result2list <-
3
function(searchresult)
4
{
5 1
    content <- httr::content(searchresult, "text")
6 0
    if(is.na(content)) return(NULL)
7

8 1
    doc <- XML::xmlParse(httr::content(searchresult, "text"), asText=TRUE)
9 1
    nodes <- rapply(list(doc), function(a) XML::getNodeSet(a, path="/"),
10 1
                    how="replace")
11 1
    result <- rapply(nodes, function(x) XML::xmlToList(x), how="replace")[[1]][[1]][[1]]
12

13 1
    result
14
}
15

16
# pull all elements of list with a certain name
17
pull_by_key <-
18
function(a_list, key)
19
{
20 1
    a_list[names(a_list)==key]
21
}
22

23
# get the entries as a list
24
get_entries <-
25
function(listresult)
26
{
27 1
   pull_by_key(listresult, "entry")
28
}
29

30
# just get the number of entries
31
count_entries <-
32
function(listresult)
33
{
34 1
    sum(names(listresult)=="entry")
35
}
36

37
# convert list of results (from result2list) into data.frame
38
#   test for this in tests/testthat/test-clean.R
39
listresult2df <-
40
function(listresult, sep="|")
41
{
42 1
    if(length(listresult)==0)
43 1
        return(empty_result())
44

45 1
    mat <- vapply(listresult, clean_record, sep=sep,
46 1
                  clean_record(listresult[[1]], sep=sep))
47

48
    # strip off a bunch of "entry" values
49 1
    colnames(mat) <- 1:ncol(mat)
50

51 1
    as.data.frame(t(mat), stringsAsFactors=FALSE)
52

53
}

Read our documentation on viewing source code .

Loading