How can I find API-wrapping packages?

Learning objectives:

  • Use tools::CRAN_package_db() to search for packages.
  • Search the R-universe.
  • Use {anyapi} to search for packages.
library(dplyr)
library(stringr)
library(tidyr)
library(tools)
library(httr2)

General tips for searching

  • tolower(FIELD) to find “API”, “api”, “Api”, etc
  • \\b in regex pattern for “word boundary”
    • "\\bapi\\b" = “api surrounded by spaces, (), newline, etc”

Searching CRAN packages

# TODO: Re-enable this when CRAN isn't down.
api_pkgs <- tools::CRAN_package_db() |> 
  as_tibble() |> 
  filter(str_detect(tolower(Description), "\\bapi\\b")) |> 
  select(Package, Description)
nrow(api_pkgs)
head(api_pkgs)

Searching the R Universe

  • Web interface at https://r-universe.dev/
  • API in {universe} package? (broken as of 2023-11-13)
  • API at https://r-universe.dev/stats/powersearch

Searching the R Universe API

resp <- request("https://r-universe.dev") |> 
  req_url_path_append("stats/powersearch") |>
  req_url_query(q = "api") |> 
  req_perform() |> 
  resp_body_json()

uni_api_pkgs <- tibble(pkg = resp$results) |> 
  unnest_wider(pkg) |> 
  filter(str_detect(tolower(Description), "\\bapi\\b")) |> 
  distinct(Package, Description)

nrow(uni_api_pkgs)
head(uni_api_pkgs)

anyapi

  • {anyapi} package wraps these functions
    • (technically not yet)
  • If package doesn’t exist
    • Search for API spec
    • Create package on-the-fly to interact with the API

Meeting Videos

Cohort 1

Meeting chat log
LOG