I’ve tested the new chatbot on the CTPP Data Portal, with generally positive results.
Questions I’ve asked include:
1. How can I modify the API scripts to work in the R statistical package?
2. How do I store my API key in an r statistical package environment variable?
The chatbot gave full and easy-to-implement code to store my personal CTPP API key. Good
Various versions of my request for API scripts in R package gave various results.
It was awkward to cut-and-paste my question and the answer I received from the AI
chatbot.
Basically:
1. load the R libraries jsonlite and httr
library(jsonlite)
library(httr)
2. Save your API key in your R environment
# Edit your R profile
usethis::edit_r_profile()
Sys.setenv(CTPP_KEY = "mytopsecretapikeyxxxxxxx")
api_key <- Sys.getenv("CTPP_KEY”)
3. Define API Endpoint: Specify the URL of the API endpoint you want to access
url <- "https://ctppdata.transportation.org/api/data/2021”
4. **Set Headers**: Create a list of headers required for the API request, including the
API key.
headers <- c(Accept = "application/json", "x-api-key" = api_key)
5. Prepare Parameters: Define the parameters needed for your API call.
# may include specifying the type of data you want (like geographic IDs)
params <- list(get = "b302100_e1,b302100_m1",geo =
"C0300US06001,C0300US06005",
size = 10,page = 1)
6. Make the Request: Use the httr package send a GET request to the API.
response <- GET(url, add_headers(.headers = headers), query = params)
############################################################################
The code is failing around step 5: defining the tables and geography for the API data
pull….
I really could use some human assistance to fix this R code. I heard there is a cabal of
MPO data people who can code anything and everything in R or Python. Can somebody help
me?
I’d like to develop examples, in R script, to retrieve data for various tables (Parts 1, 2
and 3) for various geographies (state, county, place, tract). Obviously I’ll share my R
code in my bithub repository.
I just need a collaborator / hand-holder.
I received no feedback on my April 4, 2025 post to this CTPP listserv. My guess is that
too few people have actually tried to use the API, or they’re too shy to provide feedback.
Hope to hear from you!
Chuck Purvis,
Hayward, California
PS, The single-year 2024 ACS data is scheduled for release in one month, on September 11,
2025. Should keep us busy for a few days. And the five-year, 2020-2024 ACS is scheduled
for December 11, 2025.
###