-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathREADME.Rmd
More file actions
288 lines (237 loc) · 9.26 KB
/
README.Rmd
File metadata and controls
288 lines (237 loc) · 9.26 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
---
output:
rmarkdown::github_document:
html_preview: false
---
# Software Development Standards 
This project's main contents are located in the project's [Wiki](wiki#welcome-to-the-software-development-wiki).
# USCbiostats R packages
```{r setup, include=FALSE}
library(httr)
library(stringr)
library(knitr)
library(scholar) # <--- The key difference
```
```{r, include=FALSE}
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
```
```{r, include=FALSE}
# We'll assume `packages.csv` has columns:
# name, repo, on_bioc, scholar_id, pubid, google_scholar, description
# Lines starting with '#' in CSV are ignored.
pkgs <- read.csv("packages.csv", comment.char = "#", stringsAsFactors = FALSE)
# If on_bioc does not exist, create it
if (!"on_bioc" %in% names(pkgs)) {
pkgs$on_bioc <- FALSE
} else {
# Convert text "TRUE"/"FALSE" to logical
pkgs$on_bioc <- ifelse(pkgs$on_bioc %in% c("TRUE","True","true"), TRUE, FALSE)
}
# Check CRAN status
pkgs$on_cran <- TRUE
for (i in seq_len(nrow(pkgs))) {
nm <- pkgs$name[i]
url <- sprintf("https://cran.r-project.org/package=%s", nm)
resp <- tryCatch(GET(url), error = function(e) e)
if (inherits(resp,"error") || status_code(resp) != 200) {
pkgs$on_cran[i] <- FALSE
}
}
# Sort packages by name
pkgs <- pkgs[order(pkgs$name), , drop=FALSE]
pkgs <- pkgs[!(is.na(pkgs$name) | pkgs$name == ""), ]
# Build the data frame that will become our final table
dat <- data.frame(
Name = character(nrow(pkgs)),
Description = character(nrow(pkgs)),
Citations = character(nrow(pkgs)), # will fill in
stringsAsFactors = FALSE
)
for (i in seq_len(nrow(pkgs))) {
nm <- pkgs$name[i]
repo_url <- if (!is.na(pkgs$repo[i]) && nzchar(pkgs$repo[i])) {
pkgs$repo[i]
} else {
paste0("https://github.com/USCbiostats/", nm)
}
# The clickable package name
dat$Name[i] <- sprintf("[**%s**](%s)", nm, repo_url)
desc_txt <- pkgs$description[i] # base description
# If on CRAN, add badges
if (pkgs$on_cran[i]) {
desc_txt <- paste(
desc_txt,
sprintf("[](https://CRAN.R-project.org/package=%1$s)", nm),
sprintf("[](https://CRAN.R-project.org/package=%1$s)", nm)
)
}
# If on Bioc, add a badge
if (pkgs$on_bioc[i]) {
desc_txt <- paste(
desc_txt,
# Build status shield
sprintf(
"[](https://bioconductor.org/packages/release/bioc/html/%1$s.html)",
nm
),
# Downloads rank shield
sprintf(
"[](https://bioconductor.org/packages/release/bioc/html/%1$s.html)",
nm)
)
}
dat$Description[i] <- desc_txt
}
# Initialize Citations
dat$Citations <- ""
```
```{r, include=FALSE}
# -----------------------------
# 1) Scholar approach:
# -----------------------------
get_scholar_citation_count <- function(sid, pubid, pkg_name) {
# If there's a specific publication ID
if (!is.na(pubid) && nzchar(pubid)) {
# Use get_article_cite_history() + sum the 'cites'
article_hist <- tryCatch(
get_article_cite_history(sid, pubid),
error = function(e) NULL
)
if (is.data.frame(article_hist) && nrow(article_hist) > 0 && "cites" %in% names(article_hist)) {
return(sum(article_hist$cites))
} else {
return(NA_integer_)
}
} else {
# Otherwise, fallback to the fuzzy match on package name in get_publications()
pubs <- tryCatch(
get_publications(sid),
error = function(e) NULL
)
if (!is.null(pubs) && is.data.frame(pubs) && nrow(pubs) > 0) {
idx <- which(grepl(pkg_name, pubs$title, ignore.case=TRUE))
if (length(idx) > 0) {
# Return the first match's total cites
return(pubs$cites[idx[1]])
}
}
return(NA_integer_)
}
}
# -----------------------------
# 2) Old HTML scraping approach:
# -----------------------------
# We'll define a function that tries to parse a Google Scholar URL (like ?cites=...)
# using readLines or GET+iconv, then run a regex to find "XXX results" lines.
# If found, return XXX as integer. Otherwise NA.
get_html_scrape_citation_count <- function(gs_url) {
if (is.na(gs_url) || !nzchar(gs_url)) {
return(NA_integer_)
}
# We'll fetch as raw and convert.
page_txt <- tryCatch({
resp <- httr::GET(gs_url)
if (httr::status_code(resp) != 200) {
stop("HTTP status not 200")
}
raw_ct <- httr::content(resp, as="raw")
txt <- iconv(rawToChar(raw_ct, multiple=TRUE), from="UTF-8", to="UTF-8", sub="byte")
txt
}, error = function(e) {
return(NULL)
})
if (is.null(page_txt)) {
return(NA_integer_)
}
# We'll split into lines
lines <- strsplit(page_txt, "\n", fixed=TRUE)[[1]]
# Remove some tags. (Might or might not help.)
lines <- gsub("\\<[[:alnum:]_/-]+\\>", "", lines, perl=TRUE)
# The old code used a regex looking for something like "123 results (0.23 sec)"
# e.g. "([0-9,]+)[\\s\\n]+results?[\\s\\n]+\\([\\s\\n]*[0-9]+"
# But Scholar might say "About 123 results..."
# So we can attempt a simpler approach:
# "About X results" or "X results"
re <- "About\\s+([0-9,]+)\\s+results\\s*(\\([^)]*\\))?|
([0-9,]+)\\s+results\\s*(\\([^)]*\\))?"
# We'll try both capturing groups
m <- regexpr(re, lines, perl=TRUE, ignore.case=TRUE)
# Find the first line that matches
line_idx <- which(m != -1)
if (length(line_idx) == 0) {
return(NA_integer_)
}
# We'll just pick the first match
line_of_interest <- lines[line_idx[1]]
# Extract the numeric portion
# We'll do two sub captures, so:
match_txt <- regmatches(line_of_interest, m[1])
# We'll use a simpler approach with stringr if you prefer:
library(stringr)
# This pattern tries to find numbers in the text
nums_found <- str_extract_all(line_of_interest, "[0-9,]+")[[1]]
if (length(nums_found) == 0) {
return(NA_integer_)
}
# Convert e.g. "1,234" -> 1234
cites_int <- as.integer(gsub("[^0-9]", "", nums_found[1]))
cites_int
}
tot_citations <- 0L
# Now we loop over each package row
for (i in seq_len(nrow(pkgs))) {
pkg_name <- pkgs$name[i]
sid <- if ("scholar_id" %in% names(pkgs)) pkgs$scholar_id[i] else NA_character_
pubid <- if ("pubid" %in% names(pkgs)) pkgs$pubid[i] else NA_character_
old_link <- if ("google_scholar" %in% names(pkgs)) pkgs$google_scholar[i] else NA_character_
cval <- NA_integer_
# 1) Try scholar approach if sid is not empty
if (!is.na(sid) && nzchar(sid)) {
cval <- get_scholar_citation_count(sid, pubid, pkg_name)
if (!is.na(cval) && cval >= 0) {
# If we got a valid integer from Scholar
if (!is.na(pubid) && nzchar(pubid)) {
# We have a link to the actual publication
dat$Citations[i] <- sprintf("[%d](%s)", cval, old_link)
} else {
# We only have the count, no direct pub link
dat$Citations[i] <- as.character(cval)
}
tot_citations <- tot_citations + cval
next # Done with this package
}
}
# 2) Fallback: old HTML approach using google_scholar column
cval_html <- get_html_scrape_citation_count(old_link)
if (!is.na(cval_html) && cval_html >= 0) {
dat$Citations[i] <- sprintf("[%d](%s)", cval_html, old_link)
tot_citations <- tot_citations + cval_html
}
}
```
```{r printing, echo = FALSE}
knitr::kable(dat, row.names = FALSE)
```
As of `r Sys.Date()`, the packages listed here have been cited **`r tot_citations`** times
(source: Google Scholar).
To update this list, modify the file [packages.csv](packages.csv). The
`README.md` file is updated automatically using GitHub Actions, so there's no
need to "manually" recompile the README file after updating the list.
# Coding Standards
1. [Coding Standards](wiki#coding-standards)
2. [Software Thinking](wiki/coding-standards.md#software-thinking)
3. [Development Workflow](wiki/coding-standards.md#development-workflow)
4. [Misc](wiki/coding-standards.md#misc)
We do have some direct guidelines developed as issue templates [here](templates).
# Bioghost Server
1. [Introduction](wiki/Bioghost-server.md#introduction)
2. [Setup](wiki/Bioghost-server.md#setup)
3. [Cheat Sheet](wiki/Bioghost-server.md#cheat-sheet)
# HPC in R
* [Parallel computing in R](wiki/HPC-in-R.md#parallel-computing-in-r)
* [parallel](wiki/HPC-in-R.md#parallel)
* [iterators+foreach](wiki/HPC-in-R.md#foreach)
* [RcppArmadillo + OpenMP](wiki/HPC-in-R.md#rcpparmadillo-and-openmp)
# Happy Scientist Seminars
The Happy Scientist Seminars are educational seminars sponsored by Core D of IMAGE, the Biostats Program Project award. This series, the "Happy Scientist" seminar series, is aimed at providing educational material for members of Biostats, both students and faculty, about a variety of tools and methods that might prove useful to them. If you have any suggestions for subjects that you would like to learn about in future, please send email to Kim Siegmund at (kims@usc.edu). Our agenda will be driven by your specific interests as far as is possible.
A list of past seminars with material can be found [here](/happy_scientist/).