knitr::opts_chunk$set( comment = "#>", tidy = FALSE, error = FALSE, fig.width = 8, fig.height = 8) options(width = 90) options(max.print = 200)
Install the latest pkgsearch release from CRAN:
install.packages("pkgsearch")
The development version is on GitHub:
pak::pak("r-hub/pkgsearch")
Do you need to find packages solving a particular problem, e.g. "permutation test"?
library("pkgsearch") library("pillar") # nicer data frame printing pkg_search("permutation test")
pkgsearch uses an R-hub web service and a careful ranking that puts popular packages before less frequently used ones.
For the search mentioned above, and other points of entry to CRAN metadata, you can use pkgsearch RStudio add-in!
Select the "CRAN package search" addin from the menu, or start it with
pkg_search_addin()
.
Do you want to find the dependencies the first versions of testthat
had
and when each of these versions was released?
cran_package_history("testthat")
Do you want to know what packages are trending on CRAN these days?
pkgsearch
can help!
cran_trending() cran_top_downloaded()
Are you curious about the latest releases or archivals?
cran_events()
By default it returns a short summary of the ten best search hits. Their
details can be printed by using the format = "long"
option of pkg_search()
,
or just calling pkg_search()
again, without any arguments, after a search:
library(pkgsearch) pkg_search("C++")
pkg_search()
The more()
function can be used to display the next batch of search hits,
batches contain ten packages by default. ps()
is a shorter alias to
pkg_search()
:
ps("google")
more()
The search server uses the stems of the words in the indexed metadata, and the search phrase. This means that "colour" and "colours" deliver the exact same result. So do "coloring", "colored", etc. (Unless one is happen to be an exact package name or match another non-stemmed field.)
ps("colour", size = 3) ps("colours", size = 3)
The most important feature of a search engine is the ranking of the results. The best results should be listed first. pkgsearch uses weighted scoring, where a match in the package title gets a higher score than a match in the package description. It also uses the number of reverse dependencies and the number of downloads to weight the scores:
ps("colour")[, c("score", "package", "revdeps", "downloads_last_month")]
The search engine prefers matching whole phrases over single words. E.g. the search phrase "permutation test" will rank coin higher than testthat, even though testthat is a much better result for the single word "test". (In fact, at the time of writing testthat is not even on the first page of results.)
ps("permutation test")
If the whole phrase does not match, pkgsearch falls back to individual matching words. For example, a match from either words is enough here, to get on the first page of results:
ps("test http")
The search engine uses a dictionary to make sure that package metadata and queries given in British and American English yield the same results. E.g. note the spelling of colour/color in the results:
ps("colour") ps("color")
Especially when searching for package maintainer names, it is convenient to use the corresponding ASCII letters for non-ASCII characters in search phrases. E.g. the following two queries yield the same results. Note that case is also ignored.
ps("gabor", size = 5) ps("Gábor", size = 5)
timeout
: pkgsearch follows the timeout
options for HTTP requests
(i.e. for pkg_search()
and advanced_search()
. timeout
is the limit
for the total time of the HTTP request, and it is in seconds. See
?options
for details.See the complete documentation.
MIT @ Gábor Csárdi, RStudio, R Consortium.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.