Skip to content

Instantly share code, notes, and snippets.

@Yousuf28
Forked from joelnitta/list_proj_pkgs.R
Created November 27, 2023 20:33
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 Yousuf28/139aef3b0a2acf107cb59d0e3724427c to your computer and use it in GitHub Desktop.
Save Yousuf28/139aef3b0a2acf107cb59d0e3724427c 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