Created
November 25, 2022 16:38
-
-
Save nicolaspayette/b52f39a129f6b0834c477cd8dd6b51ad to your computer and use it in GitHub Desktop.
Print a sort list of packages used in an R script file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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