read_codebook: Read a code book in standard format(s) as a csv file

Description Usage Arguments Details Value Author(s) Examples

Description

read_codebook reads a code book stored as a csv file for either checking against a data file or relabelling factor levels or labelling variables.

Usage

1
2
3
read_codebook(x, codebook_directory = NULL, column_names = NULL,
  na = c("", "NA", ".", " "),
  data_management_plan = "All possible details should be here")

Arguments

x

filename of codebook to parse

codebook_directory

directory containing codebook. Default : current directory

column_names

named character vector containing column names in Code Book file. The vector contains components variable_name = variable name, variable_original = original name (if variable_name was changed), label for printing/plotting, variable_levels = factor levels, variable_limits or min and max for continuous measurements, missing_values = numeric or strings for values of variable to be set as missing comments = comments about the variable which may include the measurement instrument or references about the measurement. Note that default values may be found with options(codebookr.column_names)

na

a character vector of strings which are to be interpreted as ‘NA’ values. Blank fields are also considered to be missing values in logical, integer, numeric and complex fields. Default: c("", "NA", ".", " ")

data_management_plan

a list containing information like url, location, authors, date, version and so on. Default: "All possible details should be here"

Details

Often, when analysing data, data dictionaries or code books are provided with data files. Rather than a word doc or pdf files, the format required here is in a very specific format stored as a csv file. Once read in, attributes such as factor labels/levels and variable labels can be added to the data.frame and/or also used to check factor labels and variable names are consistent with the code book. Note that while various methods may be available which attempt to convert word docs or pdf's to a spreadsheet and/or csv file, extreme care should be taken as these are far from perfect.

Value

S3 object of type class codebook

Author(s)

Peter Baker pete@petebaker.id.au

Examples

1
2
3
4
5
6
file.copy(system.file('demoFiles', 'data1_codebook.csv',
                      package='codebookr'), 'data1_codebook.csv')
data1_codebook <- read_codebook("data1_codebook.csv",
         column_names = list(variable_levels = "Factor.Levels",
                             variable_original = "Old.Variable",
                             min = "Min", max = "Max"))

petebaker/codebookr documentation built on May 6, 2019, 12:05 a.m.