Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
144 lines (97 sloc) 5.25 KB
---
title: Search and discover CRAN packages with pkgsearch!
date: '2019-11-26'
slug: pkgsearch
tags:
- pkgsearch
---
We have just released version 3.0.1 of the `pkgsearch` package [on CRAN](https://cran.r-project.org/package=pkgsearch)! :tada: `pkgsearch` munges CRAN metadata and lets you
access it through several lenses: **search packages by keyword, popularity, recent activity, package name and more.**
Get `pkgsearch`'s latest version from
a [safe](https://rud.is/b/2019/03/03/cran-mirror-security/) CRAN mirror near
you:
```r
install.packages("pkgsearch")
```
This release, compared to `pkgsearch` 2.0.0, brings
:mag_right: Better package search functionality
* New RStudio addin to search for packages in a GUI: `pkg_search_addin()`.
* New function `advanced_search()` for more search flexibility.
:mag_right: New functionality
* `cran_package()`, `cran_packages()` and `cran_package_history()` functions to query metadata about certain packages.
* `cran_events()` function to list recent CRAN events, new, updated or archived packages.
* `cran_top_downloaded()` function to query packages with the most downloads.
* `cran_trending()` function to return the trending CRAN packages.
That's... a lot! Let's have some fun with the package.
## Explore packages in a GUI
You can use `pkgsearch` with an interface. See more in the video below. You can also launch the interface in a browser without RStudio, [refer to the addin docs](https://r-hub.github.io/pkgsearch/reference/pkg_search_addin.html).
```{r addin, echo = FALSE}
blogdown::shortcode("vimeo", "375618736")
```
## Other use cases
The `pkgsearch` package is the answer to many questions you might have about CRAN packages, thanks to its exposing it through different lenses.
```{r load}
library("pkgsearch")
```
### Packages to do mocking
Remember our [blog post about mocking when unit testing](/2019/10/29/mocking/)? How could we search CRAN packages related to mocking?
```{r mock}
pkg_search("mocking")
```
### Dependencies of a package over time?
```{r tweet, echo = FALSE}
blogdown::shortcode("tweet", "1186667832718876673")
```
YES, we know! :grin: :raised_hand: So say we want to query the dependencies of `tsibble`, we can use `cran_package_history()` for that.
```{r tsibble1}
library("magrittr")
cran_package_history("tsibble")[, c("Package", "Version", "dependencies")] %>%
tidyr::unnest(dependencies)
```
Or of one particular version of `tsibble`, then we can run `cran_packages()` (or `cran_package()` with its `version` argument, that returns a list).
```{r tsibble2}
cran_packages("tsibble@0.2.0")
info <- cran_package("tsibble", version = "0.2.0")
info[c("Imports", "Suggests", "Depends")]
```
### When was the CRAN incoming queue closed?
From time to time [CRAN incoming queue is closed](https://stat.ethz.ch/pipermail/r-package-devel/2019q3/004242.html), for instance earlier this year from August 9 to August 18. Can we see that in the data?
```{r echo=FALSE, warning=FALSE, results='hide'}
Sys.setenv(LANGUAGE="en")
Sys.setlocale("LC_TIME","en_US.UTF-8")
```
```{r cranvacay, cache=TRUE}
library("ggplot2")
cran_events <- cran_events(limit = 5000)
events_df <- tibble::tibble(
date = anytime::anytime(purrr::map_chr(cran_events, "date")),
type = purrr::map_chr(cran_events, "event")
)
ggplot(events_df) +
geom_segment(aes(x = date, xend = date,
col = type),
y = 0, yend = 1) +
viridis::scale_colour_viridis(discrete = TRUE) +
theme_minimal() +
hrbrthemes::theme_ipsum(base_size = 16,
axis_title_size = 16) +
xlab("Time") +
theme(
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.title.y = element_blank(),
legend.position = "bottom") +
ggtitle("Latest 5,000 CRAN events",
subtitle = "Data obtained via the R-hub pkgsearch R package")
```
So yes, we do see the CRAN (well-deserved!) break in the data!
## Related work
Without surprise `pkgsearch` is our favorite CRAN metadata munger since it is _ours_, but we know of other great tools!
* The [`packagefinder` package](https://cran.r-project.org/web/packages/packagefinder/index.html) by Joachim Zuckarelli aims at providing a Comfortable Search for R Packages on CRAN Directly from the R Console.
* [`CRANberries`](http://dirk.eddelbuettel.com/cranberries/about/) by Dirk Eddelbuettel "aggregates information about new, updated and removed packages from the CRAN network for R available as this html version and a corresponding RSS feed." and a Twitter feed. Handy!
## Conclusion
In this post we gave an overview of `pkgsearch` functionalities. It could become your go-to package for searching and exploring CRAN packages thanks to its exposing CRAN metadata in different ways: packages related to a keyword, trending packages, information about a package, etc. And you can use it either from the R console or a GUI!
The best place to get to know `pkgsearch` is [its brand-new documentation website built with `pkgdown`](https://r-hub.github.io/pkgsearch), and the best place to provide feedback or contribute is [its GitHub repo](https://github.com/r-hub/pkgsearch). We look forward to hearing from your use cases, and hope your enthusiasm for the package can push it to the `cran_trending()` VIP list! :wink:
```{r last-ex}
pkg_search("search CRAN")
```
You can’t perform that action at this time.