Skip to content

Commit 0c24886

Browse files
authored
Merge pull request #146 from ropensci-review-tools/use-case
finish simil-fns sec of vignette #118
2 parents fb43556 + 2182599 commit 0c24886

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: pkgmatch
22
Title: Find R Packages Matching Either Descriptions or Other R Packages
3-
Version: 0.5.0.002
3+
Version: 0.5.0.003
44
Authors@R: c(
55
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-2172-5265")),

codemeta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"codeRepository": "https://github.com/ropensci-review-tools/pkgmatch",
99
"issueTracker": "https://github.com/ropensci-review-tools/pkgmatch/issues",
1010
"license": "https://spdx.org/licenses/MIT",
11-
"version": "0.5.0.002",
11+
"version": "0.5.0.003",
1212
"programmingLanguage": {
1313
"@type": "ComputerLanguage",
1414
"name": "R",

vignettes/F_extended-use-case.Rmd

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,11 @@ by pkgmatch.
156156

157157
pkgmatch can also be used when writing R functions or scripts, to answer the
158158
question of which R packages may already exist which do what I am trying to
159-
code. The easiest way to illustrate this is with a concrete example:
159+
code. The easiest way to illustrate this is with a concrete example, like the
160+
following attempt to use [the `httr2` package](https://httr2.r-lib.org/) to
161+
extract data from a search API:
160162

161163
```{r search-code}
162-
library (httr2)
163164
search_api_results <- function (q) {
164165
url <- "https://mysearchapi.com/search"
165166
q <- httr2::httr_request (url) |>
@@ -192,7 +193,8 @@ whether any of those packages might help develop our function. We can also
192193
search for the closest matching _functions_ instead of packages, although
193194
function matching is restricted to the rOpenSci corpus only.
194195
```{r fn-fn-search, eval = FALSE}
195-
pkgmatch_similar_fns (s)
196+
fns <- pkgmatch_similar_fns (s)
197+
fns
196198
```
197199
```{r fn-fn-search-out, echo = FALSE}
198200
c (
@@ -201,3 +203,49 @@ c (
201203
"webmockr::build_httr_request"
202204
)
203205
```
206+
207+
Again, web pages for all of those functions can be opened by passing the `fns`
208+
result to [the `pkgmatch_browse()`
209+
function](https://docs.ropensci.org/pkgmatch/reference/pkgmatch_browse.html).
210+
That will open the documentation pages on
211+
[docs.ropensci.org](https://docs.ropensci.org), with all function documentation
212+
entries include a link to the corresponding source code at the top of the page.
213+
This demonstrates how pkgmatch can be used to identify similar source code to
214+
any given code input.
215+
216+
## Searches based on entire packages
217+
218+
Entire packages can also be used as input to pkgmatch functions. The simplest
219+
way to do this is to submit the name of an installed package, like this:
220+
221+
```{r whole-pkg-search, eval = FALSE}
222+
pkgs <- pkgmatch_similar_pkgs ("osmdata", corpus = "cran")
223+
```
224+
225+
As explained in [the _How does pkgmatch work?_
226+
vignette](https://docs.ropensci.org/pkgmatch/articles/B_how-does-it-work.html),
227+
pkgmatch extracts all code and text from the nominated packages and uses these
228+
to generate three sets of embeddings: of all package code, and of all text both
229+
with and without text from individual function descriptions. Matches with other
230+
packages are based on combinations of matches with these three sets of
231+
embeddings, as well as matches based on inverse document frequencies for
232+
package text (as also explained in [the _How does pkgmatch work?_
233+
vignette](https://docs.ropensci.org/pkgmatch/articles/B_how-does-it-work.html#token-frequency-similarities)).
234+
The above call yields this result:
235+
236+
```{r whole-pkg-search-output-fakey, eval = FALSE}
237+
pkgs
238+
```
239+
```{r whole-pkg-search-output, echo = FALSE}
240+
list (
241+
text = c ("factormodel", "crul", "healthequal", "httr2", "crumble"),
242+
code = c ("shinyKGode", "crul", "sphereML", "irtawsi", "httr2")
243+
)
244+
```
245+
246+
As expected, the `crul` package appears in the top results for matching both
247+
text and code (although not in first place, for reasons described in [the
248+
_Why are the results not what I expect?_
249+
vignette](https://docs.ropensci.org/pkgmatch/articles/E_why-are-the-results-not-what-i-expect.html)).
250+
Moreover, the only two packages matched on both code and text are `crul`
251+
itself, and the highly-similar [`httr2` package](https://httr2.r-lib.org/).

0 commit comments

Comments
 (0)