As a lifelong Pokemon player, I still find it hard to remember information about some Pokemon, as it can be impossible to remember information about every single one of the over 1,000 Pokemon, with even more being added soon with the next installment, Winds and Waves. While there are already several good resources to quickly search up this information, sometimes scrolling through the Bulbapedia pages can become tedious, as not all the information in it is entirely necessary to know.
I wanted to utilize this API to code my own makeshift Pokedex so that I can quickly access the basic information that most people are looking for when.
API Setup
The good thing about PokeAPI is that it is completely free to access without the need to make an account. It can be accessed using the following link.
The following are the packages I used to code this Pokedex
library(httr)library(jsonlite)library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.2.1 ✔ readr 2.2.0
✔ forcats 1.0.1 ✔ stringr 1.6.0
✔ ggplot2 4.0.3 ✔ tibble 3.3.1
✔ lubridate 1.9.5 ✔ tidyr 1.3.2
✔ purrr 1.2.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ purrr::flatten() masks jsonlite::flatten()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(magrittr)
Attaching package: 'magrittr'
The following object is masked from 'package:purrr':
set_names
The following object is masked from 'package:tidyr':
extract
Once these packages are installed and loaded, we can move on to coding the Pokedex itself.
Coding the Pokedex
The nice thing about the API is that it searches for the Pokemon you want simply by adding the Pokemon’s name to the end of the URL. First, we must establish and endpoint, and then we can use the paste() function to combine our endpoint with the Pokemon’s name we wish to attach to the end of the URL.
Now that all the information about the Pokemon is stored in a dataframe, we can begin searching for specific Pokemon.
Searching for Pokemon
Retrieving information about specific Pokemon is very simple, all we have to do is use the function we just created above. For this example, we will search for Pikachu.
Name ID Types Abilities HP Attack Defense Special_Attack
1 pikachu 25 electric static, lightning-rod 35 55 40 50
Special_Defense Speed
1 50 90
The dataframe that appears in the new window will display all of Pikachu’s information, its Pokedex number, types, abilities, and all of its stats. We can use this function again with a different pokemon just by changing the name in the parenthesis. For example, if we wanted to search for Charizard, simply change out the (“pikachu”) for (“charizard)
Conclusion
PokeAPI is a very easy API to work with, and that made retrieving data in R very simple to do. Simply by changing the name of the Pokemon in the URL, all the information we need about that Pokemon can be easily extracted and displayed.