Skip to content

Instantly share code, notes, and snippets.

@joelnitta
Created January 5, 2019 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joelnitta/facf19c503942bf3984202e036e41c1a to your computer and use it in GitHub Desktop.
Save joelnitta/facf19c503942bf3984202e036e41c1a to your computer and use it in GitHub Desktop.
List all functions and packages used by R scripts in a project
# List all functions and packages used by R scripts in a project.
library(NCmisc)
# IMPORTANT: Also load any libraries used by the project
# Make list of all functions by package
funcs <-
list.files(here::here(), pattern ="\\.R$", recursive = TRUE, full.names = TRUE) %>%
map(list.functions.in.file) %>%
flatten
# Check on the functions that weren't assigned to any package.
# These may have been missed either because they are custom functions
# defined in this project, or the package for that function hasn't been loaded.
funcs[names(funcs) == "character(0)"] %>% unlist %>% as.character %>% sort
# Extract just the unique package names
packages <-
funcs %>%
names %>%
str_extract("package:[[:alnum:]]*") %>%
str_split(",") %>%
unlist %>%
str_remove("package:") %>%
unique %>%
sort
packages
# See which packages aren't in the tidyverse
setdiff(packages, tidyverse_packages())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment