-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_dependencies.R
34 lines (27 loc) · 1.01 KB
/
get_dependencies.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
library(here)
library(knitr)
library(tidyverse)
get_packages <- function(file){
lines <- readLines(file, warn = FALSE)
library_lines <- lines[grep("^library\\(", lines)]
packages <- gsub("library\\(", "", library_lines)
packages <- gsub("\\)", "", packages)
return(packages)
}
# list R files
files <- list.files(path = here::here(), pattern = "\\.R$", recursive = TRUE, full.names = TRUE)
# list Rmd files
files <- c(files,
list.files(path = here::here(), pattern = "\\.Rmd$", recursive = TRUE, full.names = TRUE)
)
# get pacakges
packages <- lapply(files, get_packages)
packages <- unique(unlist(packages))
pkgdata <- tibble::tibble(package = packages,
version = sapply(packages, function(p) paste(packageVersion(p), collapse = ".")))
readr::write_csv(pkgdata, here::here("packages.csv"))
for (p in packages) library(p, character.only = TRUE)
sink(file = here::here("sessionInfo"))
sessionInfo()
sink()
knitr::write_bib(packages, file = here::here("packages.bib"))