Site icon R-bloggers

An API for Everything There Is to Know About Packages

[This article was first published on rOpenSci - open tools for open science, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

On R-Universe you can discover and learn everything there is to know about R packages. But did you know it does only provide a human-friendly website, but also programmatic access to all information through APIs! Thanks to those APIs you can list universes, list packages in an universe, get information on packages, and perform searches; all without any need for authentication.

The R-Universe APIs are both handy and reliable. You can build upon them, as both rOpenSci and community members have done. This post shows some examples of use cases with the R-Universe API.

Know which packages are yours

The toolbox for rOpenSci community management tasks, promoutils, calls an R-Universe API to list and get information on rOpenSci packages. This list of packages is in particular used in the function that outputs data on help-wanted issues.

Display packages developed at your organization

If your organization develops R packages, you can use its R-Universe as the source of truth for your package collection. For instance, the R-Universe of ggsegverse corresponds to, well, the ggsegverse. Therefore, on the ggsegverse website, the listing of packages is created by querying https://ggsegverse.r-universe.dev/api/packages, the endpoint for information on all packages in the universe.

Likewise, the docs page of ggsegverse relies on the R-Universe API to retrieve links to vignettes for each package.

Server-side or client-side API requests

The ggsegverse website performs client-side requests: it queries the R-Universe API when you open the webpage, through a JS script. You can also check this through the web developer tools:

The rendering of the nice package cards happens through another JS script that uses information such as the package’s title, description, number of stars, etc.

In contrast, for package listings on author and package pages, the rOpenSci website uses server-side requests: the API is called when Hugo renders our website. For instance, for the list of packages at the bottom of Jeroen Ooms’ author page, we query the R-Universe API link from our website configuration and filter the packages by GitHub login.

On a Quarto website, you could have a code chunk using R to query the R-Universe APIs, through the universe R package for instance.

In any case, if you use server-side requests, you need to re-render your website regularly to avoid your packages’ listing to get out-of-date. The nice thing about client-side requests is that the package lists will be always up-to-date!

Search Packages

With R-universe, you can search packages, not only through the web interface but also through an API.

The project The Wharehouse, that helps users find packages according to given keywords, uses R-universe as one its information sources.

Conclusion

In this post we provided some use cases of the R-Universe APIs. Try them out, or read the docs to get a sense of all the information that’s shared through the different endpoints. If you maintain some infrastructure that uses an R-Universe API, feel free to report a use case!

To leave a comment for the author, please follow the link and comment on their blog: rOpenSci - open tools for open science.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Exit mobile version