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

system dependencies request for multiple R packages #90

Open
waddella opened this issue Sep 16, 2021 · 4 comments
Open

system dependencies request for multiple R packages #90

waddella opened this issue Sep 16, 2021 · 4 comments

Comments

@waddella
Copy link

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 r-lib/remotes#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
Copy link

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

@bersbersbers
Copy link

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
Copy link

@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
Copy link
Contributor

glin commented Nov 3, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants