https://github.com/matt-dray/trapinch
:book::space_invader: R Package: get data from the PokéAPI service
https://github.com/matt-dray/trapinch
pokeapi pokemon r-package
Last synced: 5 months ago
JSON representation
:book::space_invader: R Package: get data from the PokéAPI service
- Host: GitHub
- URL: https://github.com/matt-dray/trapinch
- Owner: matt-dray
- License: other
- Created: 2023-01-10T23:33:44.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-05T10:57:31.000Z (over 3 years ago)
- Last Synced: 2025-10-12T13:36:16.727Z (9 months ago)
- Topics: pokeapi, pokemon, r-package
- Language: R
- Homepage: https://www.rostrum.blog/2023/02/02/trapinch/
- Size: 269 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# {trapinch} 
[](https://www.repostatus.org/#inactive)
[](https://github.com/matt-dray/trapinch/actions)
[](https://app.codecov.io/gh/matt-dray/trapinch?branch=main)
[](https://www.rostrum.blog/2023/02/02/trapinch/)
A simple R package to interface with [the PokéAPI service](https://pokeapi.co/), based on [{httr2}](https://httr2.r-lib.org/).
Why 'Trapinch'? Because [it's a Pokémon](https://bulbapedia.bulbagarden.net/wiki/Trapinch_(Pok%C3%A9mon)) whose name contains 'R API' and it wasn't claimed on [Repokemon](https://cheeaun.github.io/repokemon/) yet, lol.
## Installation
You can install {trapinch} from GitHub with help from [{remotes}](https://remotes.r-lib.org/):
```{r install, eval=FALSE}
if (!require(remotes)) install.packages("remotes")
remotes::install_github("matt-dray/trapinch")
```
The package depends on R version 4.1 since it uses `R_user_dir()` and the base pipe, `|>`.
## Examples
Functions are all prefaced `get_*()` and return a list. The generic request function is `get_pokeapi()`, to which you can provide an `endpoint` and `resource` of interest. Each endpoint also has its own function to which you need only supply the resource of interest, like `get_pokemon()` or `get_type()`.
For example, retrieve a named Pokémon's details:
```{r example-pokemon}
bulba <- trapinch::get_pokemon("bulbasaur")
bulba$moves[[1]]$move$name
```
Or retrieve an item's details:
```{r example-item}
ball <- trapinch::get_item("poke-ball")
ball$flavor_text_entries[[1]]$text
```
If you're wondering what endpoints and resources exist, you can find them in the `resource_lookups` list object. The endpoints:
```{r endpoints}
names(trapinch::resource_lookups)
```
And an example resource table for Pokémon types:
```{r resource}
head(trapinch::resource_lookups[["type"]])
```
See [the PokéAPI documentation](https://pokeapi.co/docs/v2) for full details of what can be returned.
# Similar projects
Wrappers in several languages are named on [the PokéAPI website](https://pokeapi.co/docs/v2#wrap), but none are for R. I did find a couple of smaller-scale, non-{httr2} packages on GitHub: [UBC-MDS's {pokedex}](https://github.com/UBC-MDS/pokedex) and [Eva Nguyen's {pokeWrapper}](https://nguyeneva.github.io/2020-02-06-rwrapper/). I had, however, [overlooked](https://fosstodon.org/@ashbaldry/109806406291422128) an important one: [Ash Baldry](https://ashbaldry.github.io/) has already written the [{pokeapi} package](https://github.com/ashbaldry/pokeapi), which uses {httr2} and was released several months prior to {trapinch}. Whoops!
# Thanks
This package was made easier with help from the:
* [PokéAPI documentation](https://pokeapi.co/docs/v2)
* [{httr2} documentation](https://httr2.r-lib.org/index.html)
* [{httptest2} documentation](https://enpiar.com/httptest2/index.html)
* [HTTP Testing book](https://books.ropensci.org/http-testing/) from rOpenSci