Type: Package
Title: Access the Canadian Election Study Datasets
Version: 0.1.0
Maintainer: Paul A. Hodgetts <hodgetts.paul@outlook.com>
Description: Makes accessing and loading the Canadian Election Study (http://www.ces-eec.ca/, https://ces-eec.arts.ubc.ca/, https://search1.odesi.ca/#/) surveys into the R workspace more efficient by downloading a requested survey and loading it as a data object. This removes the need to locate, download, load, and change working directories when working with the Canadian Election Study surveys.
License: MIT + file LICENSE
URL: https://hodgettsp.github.io/cesR/
BugReports: https://github.com/hodgettsp/cesR/issues
Depends: R(≥ 3.5.0)
Encoding: UTF-8
Language: en-US
Imports: dplyr, haven, readr, labelled, tidyr, utils
RoxygenNote: 7.1.2
Suggests: testthat, knitr, rmarkdown, spelling
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2021-11-23 00:46:03 UTC; phodg
Author: Paul A. Hodgetts [aut, cre], Rohan Alexander ORCID iD [aut]
Repository: CRAN
Date/Publication: 2021-11-23 18:20:05 UTC

Create a dataframe object for a CES survey.

Description

get_ces() creates a dataframe object for a requested Canadian Election Study survey using an associated survey code to call and download the survey dataset. On creation of the data object, prints out the associated citation for use with the requested dataset and a link to the original location of the data file.

Usage

get_ces(srvy, pos = 1)

Arguments

srvy

A CES survey code call. See Survey Code Calls below. srvy value must be a character string.

pos

Environment assignment. Defaults to 1, which is an assignment to the global environment.

Details

Datasets

Datasets are loaded using .dta, .sav, or .tab file types. See File Types below for a list of included CES datasets and their file type. To quickly convert a dataset's values to factor type use labelled::to_factor() on the dataset.

Survey Code Calls

File Types

Incorrect/Repeated Code Calls

Incorrect (a non-existent survey code) will stop the function process and return an associated error message. Repeated code calls will load in the raw version of the requested table.

Extra Notes

Due to the naming of the columns in the 1965 and 1968 datasets it is recommended to download the associated codebook for the requested dataset.

Value

The called srvy at the designated environment position pos. Default environment position is set to be the global environment.

See Also

get_cescodes() function help.

Examples

## Not run: 
# call the 2019 CES online survey
get_ces("ces2019_web")

# convert variables to factor
labelled::to_factor(ces2019_web)

# preview dataset
head(ces2019_web)

## End(Not run)

Print a dataset of the CES survey codes and their associated calls.

Description

get_cescodes() prints out a data frame of the CES survey codes and the associated calls. Provides a quick way of looking up a CES survey code and the associated call.

Usage

get_cescodes(indx = 22)

Arguments

indx

A numeric value that determines the number of survey codes returned. Default is set to 22, or the total set of survey codes.

Details

Items under the Survey Code Calls and Index Code Calls can be copied and used with the get_ces() function.

Survey Codes

Survey Code Calls

Value

A printout of a designated number of Canadian Election Study survey codes and associated character codes used for the get_ces() function.

See Also

get_ces() function help.

Examples

# print out CES code calls
get_cescodes()

# call 1984 CES survey
get_ces("ces1984")


Creates a non-exhaustive dataframe of 21 variables with renamed columns.

Description

get_decon() creates a non-exhaustive dataset under the name decon consisting of 21 variables with renamed columns from the demographics, ideology, and economy sections of the 2019 CES online survey.

Usage

get_decon(pos = 1)

Arguments

pos

Environment assignment. Defaults to 1, which is an assignment to the global environment.

decon Variables

citizenship

Canadian citizenship status

yob

year of birth

gender

identified gender of the respondent

province_territory

Province or Territory of current residence

education

highest level of education completed

vote_likely

likelihood of voting on election day

vote_likely_ifable

likelihood to vote in first election for which respondent is eligible

votechoice

party most likely to vote for

votechoice_text

party most likely to vote for - text answers

votechoice_couldvote

party most likely to vote for if eligible to vote

votechoice_couldvote_text

party most likely to vote for if eligible to vote - text answers

votechoice_unlikely

party least likely to vote for

votechoice_unlikely_text

party least likely to vote for - text answers

votechoice_unlikely_couldvote

party least likely to vote for if eligible to vote

votechoice_unlikely_couldvote_text

party least likely to vote for if eligible to vote - text answers

vote_advancevote_choice

party voted for in the advanced ballot

vote_advancevote_choice_text

party voted for in the advanced ballot - text

vote_partylean

party toward which the respondent leans

vote_partylean_text

party toward which the respondent leans - text answers

vote_partylean_couldvote

party toward which the respondent leans if eligible

vote_partylean_couldvote_text

party toward which the respondent leans if eligible - text answers

votechoice_secondchoice

second choice party of respondent

votechoice_secondchoice_text

second choice party of respondent - text answers

votechoice_couldvote_secondchoice

second choice party of respondent if eligible

votechoice_couldvote_secondchoice_text

second choice party of respondent if eligible - text answers

votechoice_partynotvote_1

party respondent would note vote for - first ranking

votechoice_partynotvote_2

party respondent would note vote for - second ranking

votechoice_partynotvote_3

party respondent would note vote for - third ranking

votechoice_partynotvote_4

party respondent would note vote for - fourth ranking

votechoice_partynotvote_5

party respondent would note vote for - fifth ranking

votechoice_partynotvote_6

party respondent would note vote for - sixth ranking

votechoice_partynotvote_7

party respondent would note vote for - seventh ranking

votechoice_partynotvote_8

party respondent would note vote for - eighth ranking

votechoice_partynotvote_9

party respondent would note vote for - ninth ranking

votechoice_partynotvote_text

party respondent would note vote for - text answers

lr_scale

united column of lr_bef and lr_aft values; whether the respondent identifies on the political spectrum

lr_scale_bef

where the respondent identifies on the political spectrum; asked before party identification questions

lr_scale_aft

where the respondent identifies on the political spectrum; asked after party identification questions

religion

religion of respondent

sexuality_selected

sexual identity

sexuality_text

sexual identity; written answers

language_eng

language learned as child and still understand; selected response English

language_fr

language learned as a child and still understand; selected response French

language_abgl

language learned as a child and still understand; specified Aboriginal language

employment

employment status

income

total household income, before taxes, for the year 2018

income_cat

selected household income category

marital

marital status

econ_retro

response to question, 'over the past year, has Canada's economy:'

econ_fed

response to question, 'have the policies of the federal government made Canada's economy...'

econ_self

response to question, have the policies of the federal government made your financial situation...'

Details

NAs have not been removed. The politically left/right question variables (lr_bef and lr_aft) have also been joined into one column under the name lr_scale. All variables have been converted to factor type using labelled::to_factor and are listed below.

Value

The designed dataframe as a 'tbl_df' object under the name decon.

See Also

For further details, see https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/DUS88V Stephenson, Laura B; Harell, Allison; Rubenson, Daniel; Loewen, Peter John, 2020, "2019 Canadian Election Study - Online Survey", doi: 10.7910/DVN/DUS88V, Harvard Dataverse, V1

Examples

## Not run: 
# call decon dataset
get_decon()

# preview decon
head(decon)

## End(Not run)

Create a preview dataframe object of a CES survey.

Description

get_preview() creates a truncated dataframe for a requested Canadian Election Study survey using an associated code to call and download the survey dataset.

Usage

get_preview(srvy, obs = 6, pos = 1)

Arguments

srvy

A CES survey code call. See Survey Code Calls below. srvy value must be a character string.

obs

A numerical value that determines the number of observations returned. If a value for obs is not given, then default value is 6 observations. Variable must be given as a numerical value.

pos

Environment assignment. Defaults to 1, which is an assignment to the global environment.

Details

Datasets

Datasets are loaded using either .dta or .sav file types and converted to factor type using the to_factor() function from the labelled package.

Survey Code Calls

get_preview() uses the same survey code calls as the get_ces() function. These survey code calls are listed below.

Incorrect/Repeated Code Calls

Incorrect (a non-existent survey code) will stop the function process and return associated error messages. Repeated code calls will load in an unaltered version of the requested table.

Extra Notes

Due to the naming of the columns in the 1965 and 1968 datasets it is recommended to download the associated codebook for the requested dataset.

Value

The truncated version of the requested survey dataset srvy with the set number of observations obs to the designated environment pos.

See Also

get_ces() function help. get_cescodes() function help.

Examples

## Not run: 
# print out CES call codes
get_cescodes()

# call the 1993 CES dataset
get_ces("ces1993")

# preview the first 10 observations of the dataset
get_preview("ces1993", 10)

## End(Not run)


Prints out the survey question column label for a given column in a given dataset.

Description

get_question() prints out the survey question associated with a given column in a given dataset name.

Usage

get_question(do, q)

Arguments

do

a CES survey data object (given as a character string)

q

a column name in a CES survey data object (given as a character string)

Details

The order of the parameters for get_question are data object then column name. Both parameters must be character strings and cannot be reversed. To return the associated survey question, the get_question function relies on the var_label function from the labelled package.

Value

The associated question q in a loaded dataset do.

See Also

get_ces() function help. get_cescodes() help.

Examples

# print out CES code calls
get_cescodes()

# call CES survey
get_ces("ces1988")

# request the survey question for column a6
get_question("ces1988", "a6")