Skip to content

Instantly share code, notes, and snippets.

@erikgregorywebb
Created January 25, 2021 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikgregorywebb/0f634a1b9e88dd3fff4d3b246b347738 to your computer and use it in GitHub Desktop.
Save erikgregorywebb/0f634a1b9e88dd3fff4d3b246b347738 to your computer and use it in GitHub Desktop.
library(rvest)
library(stringr)
# get list of gists
all_links = c()
for (i in 1:25) {
url = paste('https://gist.github.com/erikgregorywebb?page=', i, sep ='')
print(url)
Sys.sleep(1)
page = read_html(url)
page_links = page %>% html_nodes('a') %>% html_attr('href')
links = page_links[str_detect(page_links, 'https://gist.github.com/erikgregorywebb/')]
all_links = c(all_links, links)
}
# extract r packages from each gist
all_packages = c()
for (i in 1:length(all_links)) {
url = all_links[i]
print(url)
Sys.sleep(1)
page = read_html(url)
code = page %>% html_node('.highlight') %>% html_text()
packages = str_extract_all(code, 'library\\(.*?\\)')
all_packages = c(all_packages, packages[[1]])
}
# determine top packages used
top_packages = all_packages %>% tibble(package = `.`) %>%
group_by(package) %>% count(sort = T) %>%
filter(is.na(package) == FALSE) %>%
ungroup() %>%
mutate(package = str_replace(package, 'library\\(', '')) %>%
mutate(package = str_replace(package, '\\)', ''))
@erikgregorywebb
Copy link
Author

rank package
1 tidyverse
2 rvest
3 dplyr
4 scales
5 stringr
6 lubridate
7 tidytext
8 ggplot2
9 jsonlite
10 scriptuRs
11 tidyr
12 igraph
13 zipcode
14 httr
15 readxl
16 wordcloud2
17 devtools
18 fuzzyjoin
19 gganimate
20 ggmap
21 ggraph
22 gifski
23 googledrive
24 googlesheets
25 pdftools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment