read_health_dict: Read Health Data Dictionaries

View source: R/read-dict.R

read_health_dictR Documentation

Read Health Data Dictionaries

Description

read_health_dict reads into R pre-formatted popdata data dictionaries, while health_dict_to_spec converts a health dict to a readr spec.

Usage

read_health_dict(path, sheet, ...)

health_dict_to_spec(health_dict, special = NULL)

Arguments

path

Path to the xls/xlsx file.

sheet

Sheet to read. Either a string (the name of a sheet), or an integer (the position of the sheet). Ignored if the sheet is specified via range. If neither argument specifies the sheet, defaults to the first sheet.

...

arguments passed to readxl::read_excel

health_dict

a data.frame, output of read_health_dict()

special

a named list of readr column specifications for columns where you want to override the format in the dictionary file

Details

read_health_dict: Files are in .xlsx format and therefore require both a path and sheet argument. The rest of the function is a thin wrapper around reaxl::read_excel with some formatting taking place.

health_dict_to_spec converts a health dict created by read_health_dict to a readr spec. This will use the dictionary to create specifications even for date and datetime columns, and allows overriding the default column specs by using the special parameter.

Value

read_health_dict: A clean data.frame of health data dictionary

health_dict_to_spec: a named list of readr column specifications that can be passed on to the col_types argument of any of the readr functions, or dat_to_parquet() and friends.

Examples

dict <- read_health_dict(dipr_example("sample_hlth_dict.csv"))
dict
health_dict_to_spec(dict, special = list(code1 = readr::col_integer()))

bcgov/dipr documentation built on June 1, 2022, 12:32 p.m.