Provides access to collegiate athletics data from the City University of New York (CUNY), the largest urban public university system in the United States. Includes tools for discovering and retrieving sports data from an included SQLite database. The data covers individual CUNY schools, players, games, seasons, and other aspects of CUNY athletics, providing accessible datasets for teaching, student learning, and sports analytics.
CUNYsports is an R package for accessing and exploring collegiate athletics data from the City University of New York (CUNY).
The package provides a simple interface for retrieving sports data from an included SQLite database. The database contains information about teams, players, games, seasons, schools, opponents, and other aspects of CUNY athletics.
Currently, only basketball related data is available. However, work is being done to include all sports.
The project is part of the CUNY Sports Analytics Initiative at The Open Data Lab.
CUNY athletics data are publicly available across individual college athletics websites, however, the data is not very accessible.
CUNYsports provides a centralized and reproducible way to work with these data in R.
The package includes:
The package is designed to support sports analytics, student research, dashboards, scouting reports, data visualization, teaching, and other analyses of CUNY athletics.
The initial release of CUNYsports focuses on CUNY men's and women's basketball.
Basketball data include:
The project is designed to expand to additional CUNY sports over time.
You can install the development version of CUNYsports from GitHub with:
devtools::install_github("nyc-open-data-lab/CUNYsports")
Then load the package:
library(CUNYsports)
CUNYsports provides a small set of functions for exploring and accessing the database.
Use cuny_table_names() to see all tables currently available in the database.
cuny_table_names()
This is a useful starting point when exploring the package.
If you know what kind of data you want but do not know the exact table name, use cuny_find_tables().
For example:
cuny_find_tables("basketball")
You can also search for more specific topics:
cuny_find_tables("player")
cuny_find_tables("game")
cuny_find_tables("scoring")
The function searches the package's table catalog and returns tables whose metadata match the search term.
Once you identify a table of interest, use cuny_table_info() to view its documentation.
cuny_table_info("basketball_all_seasons_player_overall_final")
Table metadata include information such as:
Use cuny_columns_info() to view documentation for the variables contained in a table.
cuny_columns_info("basketball_all_seasons_player_overall_final")
The column catalog provides information such as:
Use cuny_pull_table() to retrieve a complete database table as an R data frame.
player_stats <- cuny_pull_table(
"basketball_all_seasons_player_overall_final"
)
You can then work with the data using standard R tools:
library(dplyr)
player_stats |>
filter(gender == "W")
or:
player_stats |>
filter(gender == "M")
A typical CUNYsports workflow looks like this:
library(CUNYsports)
library(dplyr)
# See what data are available
cuny_table_names()
# Find player-related tables
cuny_find_tables("player")
# Read documentation for a table
cuny_table_info(
"basketball_all_seasons_player_overall_final"
)
# Examine its columns
cuny_columns_info(
"basketball_all_seasons_player_overall_final"
)
# Retrieve the data
players <- cuny_pull_table(
"basketball_all_seasons_player_overall_final"
)
# Begin analysis
players |>
filter(gender == "W")
This workflow can be thought of as:
flowchart LR
A["Discover"] --> B["Understand"] --> C["Retrieve"] --> D["Analyze"]
A --- A1["cuny_table_names()<br/>cuny_find_tables()"]
B --- B1["cuny_table_info()<br/>cuny_columns_info()"]
C --- C1["cuny_pull_table()"]
D --- D1["Your analysis"]
CUNYsports stores its athletics data in an included SQLite database.
The database uses a relational structure consisting of analytical tables and reusable dimension tables.
The current basketball database contains tables covering:
Men's and women's basketball records are stored together and can be distinguished using the gender variable.
Shared dimension tables provide standardized identifiers and attributes for entities used throughout the database.
These include:
dim_seasonsdim_schoolsdim_playersdim_gamesdim_opponentsdim_player_yearThese dimensions support consistent joins and longitudinal analyses across the database.
Advanced users can access the SQLite database directly with cuny_db().
con <- cuny_db()
For example:
DBI::dbListTables(con)
The connection can also be used with database-backed workflows:
dplyr::tbl(
con,
"basketball_all_seasons_player_overall_final"
)
When finished, disconnect from the database:
DBI::dbDisconnect(con)
For most users, cuny_pull_table() provides the simplest way to retrieve data.
| Function | Purpose |
|---|---|
cuny_table_names() |
View all available database tables |
cuny_find_tables() |
Search for tables using catalog metadata |
cuny_table_info() |
View documentation for a table |
cuny_columns_info() |
View documentation for columns in a table |
cuny_pull_table() |
Retrieve a complete table into R |
cuny_db() |
Open a direct connection to the SQLite database |
Two catalogs are included with the package:
table_catalogContains table-level metadata describing the structure, coverage, relationships, and potential uses of each table in the database.
column_catalogContains column-level metadata describing variables within each database table, including their meaning, data type, example values, and role within the database.
The helper functions cuny_table_info() and cuny_columns_info() provide convenient interfaces to these catalogs.
The underlying data are derived from publicly available CUNY athletics websites.
The data engineering pipeline collects and standardizes information across CUNY institutions before constructing relational tables for distribution through the package.
Because websites vary across CUNY schools and seasons, the project includes cleaning and standardization to make cross-school and analysis easier.
CUNYsports is part of the CUNY Sports Analytics Initiative, a project of The Open Data Lab focused on building open data infrastructure for CUNY athletics.
The broader initiative uses these data to support projects including:
The goal is not to collect athletics data, but to make those data easier for students, researchers, coaches, fans, and the broader CUNY community to explore and use.
Planned areas of development include:
CUNYsports is developed as part of The Open Data Lab, an open-source initiative focused on making public and institutional data easier to access, analyze, and use.
The package is developed and maintained by Christian Martinez with contributions from students and collaborators working on the CUNY Sports Analytics Initiative.
CUNYsports is released under the MIT License.