5 min read

Identifying R Functions & Packages Used in GitHub Repos (funspotr part 1)

Tags: dplyr funspotr yaml purrr fs readr here

TLDR: funspotr provides helpers for spotting the functions and packages in R and Rmarkdown files and associated github repositories. See Examples for catalogues of the functions/packages used in posts by Julia Silge, David Robinson, and others. See follow-up posts for examples with github gists and how to pass parsed code collections into a network plot:

Documenting rstats posts

I was inspired by a few tweets I saw documenting the methods used in posts by popular #rstats communicators/developers:

As a complement to these resources, I thought it’d be helpful to see precisely which functions and packages were used in each post. See Julia Silge Blog and David Robinson Tidy Tuesday for tables containing the unique functions and associated packages used in each of their posts. I also created tables for functions in the R for Data Science Chapters and Bryan Shalloway Blog.

These Examples were made using the funspotr package that provides helpers for identifying R functions & packages in self-contained R files and associated github repositories. See funspotr website for documentation on how to apply funspotr to #rstats file(s) or repos1 as well as to see how the package works and current limitations. Message me if you use funspotr or feel free to open an issue if you’d be interested in adding additional funspotr-examples that I can link to!

Examples

The files in the github repos below were parsed and saved in funspotr-examples2 – specifically using R/save-examples.R to parse each file and record each instance of a function’s use to data/funs3.

Below, I only return the first use of a function in each post4 – except for R for Data Science Chapters where I only show the first use of a function across the entire book5.

library(dplyr)
library(readr)
library(DT)

Julia Silge Blog

Also posted table to google drive here.

The following package dependencies were not installed locally during parsing. Any function from these packages (along with any custom functions) will most likely be assigned pkgs = "(unknown)":
Lingua; EN; silgelib; packagesurvey; drlib; sqlstackr; tvthemes; parttree

readr::read_csv("https://raw.githubusercontent.com/brshallo/funspotr-examples/main/data/funs/jsilge-blog-funs-20220114.csv") %>% 
  distinct() %>% 
  DT::datatable(rownames = FALSE,
              class = 'cell-border stripe',
              filter = 'top',
              escape = FALSE,
              options = list(pageLength = 10))

David Robinson Tidy Tuesday

Also posted table to google drive here.

The following package dependencies were not installed locally during parsing. Any function from these packages (along with any custom functions) will most likely be assigned pkgs = "(unknown)":
ggflags; ebbr; rKenyaCensus; tidymetrics; shinymetrics; drlib; shinybones; treesnip; StatsBombR

readr::read_csv("https://raw.githubusercontent.com/brshallo/funspotr-examples/main/data/funs/drob-tidy-tuesdays-funs-20220114.csv") %>% 
  distinct() %>% 
  DT::datatable(rownames = FALSE,
              class = 'cell-border stripe',
              filter = 'top',
              escape = FALSE,
              options = list(pageLength = 10))

R for Data Science Chapters

Also posted table to google drive here.

Pulling these files was slightly more complicated than the other examples (which were just simple calls to funspotr::github_spot_funs(repo, branch) ). In this case I first read in an index file so as to limit parsing to only those files that are used directly as chapters – see R/save-examples.R for details. Note too that R4DS is currently under an overhaul with version 2 coming-out, so the index I use doesn’t intuitively line-up with every chapter currently in the book.

The following package dependencies were not installed locally during parsing. Any function from these packages (along with any custom functions) will most likely be assigned pkgs = "(unknown)":
writexl

readr::read_csv("https://raw.githubusercontent.com/brshallo/funspotr-examples/main/data/funs/r4ds-chapter-files-funs-20220117.csv") %>% 
  distinct(funs, .keep_all = TRUE) %>% 
  select(-in_multiple_pkgs) %>% 
  DT::datatable(rownames = FALSE,
              class = 'cell-border stripe',
              filter = 'top',
              escape = FALSE,
              options = list(pageLength = 10))

Bryan Shalloway Blog

Also posted table to google drive here.

Any custom functions will most likely be assigned pkgs = "(unknown)":

readr::read_csv("https://raw.githubusercontent.com/brshallo/funspotr-examples/main/data/funs/brshallo-blog-funs-20220114.csv") %>% 
  distinct() %>% 
  DT::datatable(rownames = FALSE,
              class = 'cell-border stripe',
              filter = 'top',
              escape = FALSE,
              options = list(pageLength = 10))

  1. funspotr could also be used for R code analysis – e.g. review most frequent functions, changes in trends, etc.↩︎

  2. Parsing all the files takes a few minutes, so was easier to split apart from blog and package.↩︎

  3. Mostly just used funspotr::github_spot_funs()↩︎

  4. Rather than each instance of them as is posted on funspotr-examples↩︎

  5. Or at least across the files used for documenting the chapters. Showing unique functins across all files makes more sense in this case compared to the others because rather than each file being truly self-contained the files together make-up a collective.↩︎