Skip to content

Instantly share code, notes, and snippets.

@eliocamp
Created June 30, 2020 17:00
Show Gist options
  • Save eliocamp/3b8948af77a1ea97c789d3d50f6be9de to your computer and use it in GitHub Desktop.
Save eliocamp/3b8948af77a1ea97c789d3d50f6be9de to your computer and use it in GitHub Desktop.
Get system dependencies using sysreqs.r-hub.io
## List system dependenceis for a local project (with a DESCRIPTION file)
## and create an "apt install" command that installs them. Put it in your
## dockerfile and be happy.
library(magrittr)
all_types <- c("Imports", "Depends", "Suggests")
description_file <- here::here("DESCRIPTION")
direct_deps <- all_types %>%
lapply(desc::desc_get_field, default = NULL, file = description_file) %>%
unlist() %>%
strsplit("\n") %>%
.[[1]] %>%
trimws() %>%
gsub(",", "", .)
recursive_deps <- direct_deps %>%
tools::package_dependencies(which = all_types) %>%
unlist() %>%
unique()
dependencies <- sort(unique(c(direct_deps, recursive_deps)))
sys_deps <- lapply(dependencies, function(d) {
url <- paste0("https://sysreqs.r-hub.io/pkg/", d)
req <- polite::bow(url, "sys-deps", delay = 1) %>%
polite::scrape()
if (length(req) != 0) {
unlist(lapply(req[[1]], function(r) r$platforms$DEB))
} else {
return(NULL)
}
}
)
clean_sys_deps <- unique(unlist(sys_deps[!vapply(sys_deps, is.null, TRUE)]))
command <- paste0("sudo apt install ", paste(clean_sys_deps, collapse = " "), " -y")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment