Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: display package dependencies #2520

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions R/build-home-deps.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
build_home_depencies <- function(pkg = ".") {
pkg <- as_pkgdown(pkg)

deps <- dependencies_table(pkg)
cats <- split(deps$package, deps$type)
cats <- purrr::map_chr(cats, paste0, collapse = ", ")

# Need to translate category titles
paste0("<p>", names(cats), ": ", cats, "</p>")
}

dependencies_table <- function(pkg = ".") {
pkg <- as_pkgdown(pkg)

deps <- pkg$desc$get_deps()
deps <- deps[order(deps$type, deps$package), c("package", "type")]
deps <- deps[deps$package != "R", ]

recursive <- sort(unique(unlist(tools::package_dependencies(deps$package[deps$type %in% c("Depends", "Imports")]))))
recursive <- setdiff(recursive, deps$package)
deps <- rbind(deps, data.frame(package = recursive, type = "Recursive"))

deps$package <- purrr::map_chr(deps$package, package_link)
rownames(deps) <- NULL

deps
}

package_link <- function(package) {
href <- downlit::href_package(package)

if (is.na(href)) {
if (is_base_package(package)) {
href <- NA
Copy link
Collaborator

@salim-b salim-b Jun 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For base R packages, we could link to one of the unofficial documentation renderings, e.g.

} else {
href <- paste0("https://cran.r-project.org/web/packages/", package)
Copy link
Collaborator

@salim-b salim-b Jun 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think CRAN would rather want us to create canonical links like

href <- paste0(" https://CRAN.R-project.org/package=", package)

(hostname is case-insensitive, of course)

}
}

a(package, href)
}

is_base_package <- function(x) {
x %in% c(
"base", "compiler", "datasets", "graphics", "grDevices", "grid",
"methods", "parallel", "splines", "stats", "stats4", "tcltk",
"tools", "utils"
)
Comment on lines +44 to +48
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better use x %in% rownames(installed.packages(priority="base"))?

cf. https://stackoverflow.com/questions/21567057/programmatically-get-list-of-base-packages

}
1 change: 1 addition & 0 deletions R/build-home-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ data_home_sidebar_links <- function(pkg = ".") {

links <- c(
link_url(sprintf(tr_("View on %s"), repo$repo), repo$url),
link_url(sprintf("See dependencies"), repo$repo), repo$url),
link_url(tr_("Browse source code"), repo_home(pkg)),
link_url(tr_("Report a bug"), pkg$desc$get_field("BugReports", default = NULL)),
purrr::map_chr(links, ~ link_url(.$text, .$href))
Expand Down
Loading