Load EPI CPS Extracts via epiextractr

Note: Users will need to install epiextractr for this example. Refer to EPI packages for R for installation instructions.

Load required libraries

library(tidyverse)
library(epiextractr)

Download CPS files

# download CPS ORG files  
download_cps( sample = 'org', extracts_dir = 'C:/YOUR_PATH/cps', overwrite = TRUE)

# download CPS Basic (4085.3 MB) 
download_cps(sample='basic', extracts_dir ='C:/YOUR_PATH/cps', overwrite = TRUE)

# download CPS May (38.8 MB)
download_cps(sample='may', extracts_dir = 'C:/YOUR_PATH/cps', overwrite = TRUE)

This will download the latest EPI CPS ORG extracts in .feather format from https://microdata.epi.org and place them in the directory C:\data\cps.

Load your CPS extracts!

After the data is downloaded, load a selection of CPS data for your analysis:

org <- load_cps("org", 2010:2022, year, orgwgt, wage, age, statefips, wbho, 
                .extracts_dir = 'C:/YOUR_PATH/cps')

(Optional) Set and forget CPS data files by creating/editing an .Renviron file

To simplify usage, you can omit the .extracts_dir argument by setting the environment variables to your extracts directory. This allows you to call CPS extracts from a single, dedicated folder, eliminating redundant downloads of CPS files.

# Find the .Renviron file
renviron_path <- file.path(Sys.getenv("HOME"), ".Renviron")

# Open the file for editing
file.edit(renviron_path)

# Paste the environment variable settings into your .Renviron file,
# and make sure the paths are set to the location of your CPS files

EPIEXTRACTS_CPSBASIC_DIR=C:/YOUR_PATH/cps
EPIEXTRACTS_CPSMAY_DIR=C:/YOUR_PATH/cps
EPIEXTRACTS_CPSORG_DIR=C:/YOUR_PATH/cps

After editing your .Renviron file, save your changes and restart R to apply them.

If you’ve set your .Renviron file paths to point to the folder containing your CPS files, you can omit the .extracts_dir() command

org <- load_cps("org", 2010:2022, year, orgwgt, wage, age, statefips, wbho)
Back to top