Learn R Programming

ces: Canadian Election Study Data Package

This R package provides easy access to Canadian Election Study (CES) datasets for analysis in R.

Installation

You can install the released version of ces from CRAN with:

install.packages("ces")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("laurenceomfoisy/ces")

Example

library(ces)

# Get the 2019 CES data (metadata is preserved by default)
ces_2019 <- get_ces("2019")

# If you need to disable metadata preservation (uncommon)
# ces_2019_minimal <- get_ces("2019", preserve_metadata = FALSE)

# View available datasets
list_ces_datasets()

# Create a codebook for the dataset
codebook <- create_codebook(ces_2019)

# Examine variable metadata
metadata <- examine_metadata(ces_2019, variable_pattern = "vote")

# Get subset of variables about voting behavior
voting_data <- get_ces_subset("2019", variables = c("vote_choice", "turnout"))

# Download the official codebook PDF
download_pdf_codebook("2019")

# Download a single dataset
download_ces_dataset("2019", path = "~/CES_data")

# Download all datasets at once
download_all_ces_datasets(path = "~/CES_data")

Features

  • Easy access to CES datasets from various years (1965-2021)
  • Consistent data format across years
  • Simple filtering and subsetting functions
  • Automatic generation of variable codebooks
  • Complete preservation of variable metadata (labels, value labels)
  • Metadata examination tools
  • Export capabilities for sharing dataset documentation
  • Official PDF codebook downloads for all datasets

Troubleshooting

For package developers: If you encounter a note about "unable to verify current time" during package check, use this environment setting:

# Disable time verification entirely
Sys.setenv("_R_CHECK_SYSTEM_CLOCK_" = "0")
devtools::check()

This is the CRAN-approved way to eliminate timestamp verification issues.

Acknowledgments and Disclaimers

Data Sources

This package accesses data from multiple sources including the Borealis Data repository and the Canadian Election Study website. We gratefully acknowledge both Borealis Data and the Canadian Election Study team for maintaining and providing access to these valuable datasets.

The package author is not affiliated with the Canadian Election Study or Borealis Data. Users of this package should properly cite the original Canadian Election Study data in their research publications.

Original cesR Package

We thank Paul A. Hodgetts and Rohan Alexander for their original cesR package that provided R access to Canadian Election Study data.

Package Development

This package was developed with assistance from Claude Sonnet 3.7 and 4.0 (Anthropic) and Google Jules, AI assistants that helped with structuring the package, writing documentation, and implementing the core functionality.

Contributing and Feature Requests

Feel free to contact the package author about adding new features or if you have additional CES datasets you would like to see included in the package.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Copy Link

Version

Install

install.packages('ces')

Monthly Downloads

186

Version

1.0.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Laurence-Olivier M. Foisy

Last Published

August 29th, 2025

Functions in ces (1.0.2)

get_download_dir

Get default download directory that works across platforms
list_ces_datasets

List Available Canadian Election Study Datasets
safe_dir_create

Safely create a directory with proper checks
ces-package

Canadian Election Study Data Package
download_pdf_codebook

Download Canadian Election Study PDF Codebook
examine_metadata

Examine Variable Metadata in a CES Dataset
download_ces_dataset

Download a Canadian Election Study Dataset
export_codebook

Export Codebook to CSV or Excel
create_codebook

Create a Codebook for Canadian Election Study Dataset
download_all_ces_datasets

Download All Canadian Election Study Datasets
clean_ces_data_preserve_metadata

Clean Canadian Election Study Dataset while Preserving Metadata
clean_ces_data

Clean Canadian Election Study Dataset
check_file_conflict

Check if file exists and handle overwrite safely
get_ces_subset

Get Subset of Variables from Canadian Election Study Dataset
safe_download

Safe file download with platform-specific handling
get_ces

Get Canadian Election Study Dataset
show_variant_message

Show variant information message when multiple variants are available
extract_data_from_zip

Extract data file from ZIP archive
normalize_path

Platform-specific utility functions