Skip to content

Instantly share code, notes, and snippets.

@nicolaspayette
Created November 25, 2022 16:38
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 nicolaspayette/b52f39a129f6b0834c477cd8dd6b51ad to your computer and use it in GitHub Desktop.
Save nicolaspayette/b52f39a129f6b0834c477cd8dd6b51ad to your computer and use it in GitHub Desktop.
Print a sort list of packages used in an R script file.
# Prints a sort list of packages actually used in a script file.
# Note that the packages must be loaded for this to work.
show_packages_used <- \(script_file_name) {
script_file_name %>%
NCmisc::list.functions.in.file() %>%
names() %>%
stringr::str_extract_all("(?<=package:).\\w*", simplify = TRUE) %>%
c() %>%
purrr::keep(~ . != "") %>%
unique() %>%
sort() %>%
cat(sep = "\n")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment