rstudio / r-system-requirements

System requirements for R packages
MIT License
115 stars 19 forks source link

system dependencies request for multiple R packages #90

Open waddella opened 2 years ago

waddella commented 2 years ago

It would be great if the system requirements for multiple R packages could be requested in one call. I have created a related issue with example code on https://github.com/r-lib/remotes/issues/650 where I was pointed to this project.

Here are my use cases. Assuming we start from a vanilla OS with R installed and I would like to setup an R environment with the packages png, gh, ggplot2, credentials, gitcreds, showimage, gert, and systemfonts installed. I would like to have the list of all system requirements given

  1. I only have the target package requirement, i.e. I want to run (added recursive argument) and have install.packages take care at run-time of the system requirements:
    target_pkgs <- c("png", "gh", "ggplot2", "credentials", "gitcreds", "showimage", "gert", "systemfonts")
    remotes::system_requirements(os = "ubuntu", os_release = "20.04", package = target_pkgs, recursive = TRUE)
    install.packages(c("png", "gh", "ggplot2", "credentials", "gitcreds", "showimage", "gert", "systemfonts"))
  2. I know all the packages that need to be installed (target and upstream dependencies)
    target_pkgs <- c("png", "gh", "ggplot2", "credentials", "gitcreds", "showimage", "gert", "systemfonts")
    dep_pkgs <- tools::package_dependencies(target_pkgs)
    all_pkgs <- c(target_pkgs, unlist(dep_pkgs))
    remotes::system_requirements(os = "ubuntu", os_release = "20.04", package = all_pkgs )
    install.packages(all_pkgs)

    Note those two use cases are very similar and 2. is enough from a API to get to 1.

riccardoporreca commented 2 years ago

See https://github.com/r-lib/pak/issues/327, which shows the API is actually already supporting this via multiple instances of the pkgname query parameter.

bersbersbers commented 2 years ago

I am a bit surprised that people are surprised that this is working. I have been using the following code for a bit, basically putting together a fake, single-line DESCRIPTION file which can be fed to the API:

url <- glue::glue(
  "https://packagemanager.rstudio.com/__api__/repos/1/sysreqs?",
  "distribution={distribution}&release={release}&suggests={suggests}"
)
body <- paste("Imports:", paste(packages, collapse = ", "))
res <- httr::content(httr::POST(url, body = body))

This may be obsolete now that multiple pkgnames are possible, but the latter does not offer anything that wasn't possible before, or am I wrong?

riccardoporreca commented 2 years ago

@bersbersbers, multiple pkgnames were apparently already supported for the GET method, since long I suppose, and are not just "now" available. Perhaps just to avoid (ab)using the POST method with a fake DESCRIPTION... so in a sense using the fake description does not offer anything else than a hacky way of achieving something that was already possible in a more natural way ;)

It is in any case good to have both approaches tracked in this issue for the posterity and the community!

glin commented 2 years ago

Hey, sorry for missing this before, but I can confirm that the GET /repos/{id}/sysreqs endpoint can be used to query multiple packages in one request.

I believe the POST /repos/{id}/sysreqs endpoint (with DESCRIPTION file) was added as a convenient way to include a package's dependencies in the query, and to also support custom packages that aren't on CRAN. Either endpoint could be used to get the system requirements for multiple packages though, so you can use whatever works best.

To make this less confusing, we could add some pointers to the API documentation in the README for this repo, and maybe even some example API requests.