-
Notifications
You must be signed in to change notification settings - Fork 1
/
19-usage.Rmd
57 lines (52 loc) · 1.45 KB
/
19-usage.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Usage {#usage}
## Citations {#taxize-citations}
```{r strxt-fxn, echo=FALSE}
strxt <- function(string, pattern) {
regmatches(string, gregexpr(pattern, string, perl = TRUE))[[1]]
}
comp <- function(x) Filter(Negate(is.null), x)
```
```{r usage-get-citaitons, echo=FALSE, cache=TRUE}
library(crul)
library(jsonlite)
url <- "https://github.com/ropenscilabs/ropensci_citations/raw/master/citations_used.json"
con <- crul::HttpClient$new(url)
res <- con$get()
res$raise_for_status()
x <- jsonlite::fromJSON(res$parse("UTF-8"))
df <- x[x$name == "taxize", ]
cites <- df$citation
```
There's currently `r NROW(df)` `taxize` citations.
```{r usage-citation-parsing, echo=FALSE, cache=TRUE, results="asis"}
library(handlr)
library(dplyr)
parse_cit <- function(x) {
z = tryCatch(HandlrClient$new(x), error = function(e) e)
if (inherits(z, "error")) return(NULL)
if (is.null(z$doi)) {
yr <- strxt(x, "\\s\\(?[0-9]{4}\\.?\\)?")
yr <- gsub("\\s+|\\.|\\(|\\)", "", yr)
if (length(yr) > 1) yr <- yr[1]
list(
year = yr,
citation = x
)
} else {
z$read("citeproc")
list(
year = strxt(z$parsed$date_published, "[0-9]{4}"),
citation = x
)
}
}
res <- lapply(cites, parse_cit)
res <- comp(res)
alldata <- data.table::rbindlist(res)
alldata$year <- as.numeric(alldata$year)
adtbl <- tbl_df(alldata)
adtbl <- arrange(adtbl, desc(year))
for (i in seq_len(NROW(adtbl))) {
cat(paste0("* ", adtbl[i, "citation"]), sep = "\n")
}
```