ropensci / aRxiv
1
# arxiv_open
2
#
3
#' Open abstract for results of arXiv search
4
#'
5
#' Open, in web browser, the abstract pages for each of set of arXiv search results.
6
#'
7
#' @param search_results Data frame of search results, as returned from [arxiv_search()].
8
#' @param limit Maximum number of abstracts to open in one call.
9
#'
10
#' @details There is a delay between calls to
11
#' [utils::browseURL()], with the amount taken from the R
12
#' option `"aRxiv_delay"` (in seconds); if missing, the default
13
#' is 3 sec.
14
#'
15
#' @return (Invisibly) Vector of character strings with URLs of
16
#' abstracts opened.
17
#'
18
#' @seealso [arxiv_search()]
19
#'
20
#' @examples
21
#' \donttest{z <- arxiv_search('au:"Peter Hall" AND ti:deconvolution')
22
#' arxiv_open(z)}
23
#'
24
#' @export
25
arxiv_open <-
26
function(search_results, limit=20)
27
{
28 0
    stopifnot(limit >= 1)
29

30 0
    if(nrow(search_results) == 0)
31 0
        return(invisible(NULL))
32

33 0
    links <- search_results$link_abstract
34 0
    links <- links[links != ""]
35 0
    if(length(links) > limit) {
36 0
        warning("More abstracts (", length(links), ") than maximum to be opened (", limit, ").")
37 0
        links <- links[1:limit]
38
    }
39

40 0
    for(link in links) {
41 0
        delay_if_necessary()
42 0
        utils::browseURL(link)
43
    }
44

45 0
    invisible(links)
46
}

Read our documentation on viewing source code .

Loading