An open API service indexing awesome lists of open source software.

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

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}

[![Project Status: Inactive – The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows.](https://www.repostatus.org/badges/latest/inactive.svg)](https://www.repostatus.org/#inactive)
[![R-CMD-check](https://github.com/matt-dray/trapinch/workflows/R-CMD-check/badge.svg)](https://github.com/matt-dray/trapinch/actions)
[![Codecov test coverage](https://codecov.io/gh/matt-dray/trapinch/branch/main/graph/badge.svg)](https://app.codecov.io/gh/matt-dray/trapinch?branch=main)
[![Blog
post](https://img.shields.io/badge/rostrum.blog-post-008900?labelColor=000000&logo=data%3Aimage%2Fgif%3Bbase64%2CR0lGODlhEAAQAPEAAAAAABWCBAAAAAAAACH5BAlkAAIAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAEAAQAAAC55QkISIiEoQQQgghRBBCiCAIgiAIgiAIQiAIgSAIgiAIQiAIgRAEQiAQBAQCgUAQEAQEgYAgIAgIBAKBQBAQCAKBQEAgCAgEAoFAIAgEBAKBIBAQCAQCgUAgEAgCgUBAICAgICAgIBAgEBAgEBAgEBAgECAgICAgECAQIBAQIBAgECAgICAgICAgECAQECAQICAgICAgICAgEBAgEBAgEBAgICAgICAgECAQIBAQIBAgECAgICAgIBAgECAQECAQIBAgICAgIBAgIBAgEBAgECAgECAgICAgICAgECAgECAgQIAAAQIKAAAh%2BQQJZAACACwAAAAAEAAQAAAC55QkIiESIoQQQgghhAhCBCEIgiAIgiAIQiAIgSAIgiAIQiAIgRAEQiAQBAQCgUAQEAQEgYAgIAgIBAKBQBAQCAKBQEAgCAgEAoFAIAgEBAKBIBAQCAQCgUAgEAgCgUBAICAgICAgIBAgEBAgEBAgEBAgECAgICAgECAQIBAQIBAgECAgICAgICAgECAQECAQICAgICAgICAgEBAgEBAgEBAgICAgICAgECAQIBAQIBAgECAgICAgIBAgECAQECAQIBAgICAgIBAgIBAgEBAgECAgECAgICAgICAgECAgECAgQIAAAQIKAAA7)](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