codelist: Create a codelist object

View source: R/codelist.R

codelistR Documentation

Create a codelist object

Description

Create a codelist object

Usage

codelist(
  codes,
  labels = NULL,
  descriptions = NULL,
  parent = NULL,
  locale = NULL,
  missing = NULL
)

Arguments

codes

a vector with the codes.

labels

optional vector with the labels. Will be converted to character and should have the same length as codes. When labels is not given as.character(codes) is used for the labels.

descriptions

optional vector with the descriptions of the codes. Will be converted to character and should have the same length as codes.

parent

optional vector with the parents of the codes. Should be of the same type and length as codes and should contain only values present in codes or missing values. This can be used to define simple hierarchies. Codes with NA as their parent are the top-level (level 0) codes in the hierarchy.

locale

optional vector with the locale of the labels, descriptions etc. of the codes. This should be a character vector with the same length as codes. When the code list contains multiple locales each code should be present in each locale.

missing

optional logical vector indicating whether or not the corresponding code can be treated as a missing value. This can be used to encode different types of missingness.

Value

Returns a codelist object which is a data.frame with at minimum the columns 'code' and 'label' and optionally 'description', 'parent', 'locale' and 'missing'. See below for a description of the columns:

code

The codes. It is expected that these are either characters or integers although other types are probably supported. For a given locale (see below) they should be unique. Missing values are not allowed.

label

The labels of the codes. These are characters. Missing values are not allowed.

description

Optional. The description of the codes. These are characters. Missing values are not allowed.

missing

Optional. Logical vector indicating whether or not the corresponding code can be treated as a special value. This can be used to have different codes for different types of missingness. Missing values are not allowed.

locale

Optional. Character vector indicating for the given row which locale the label and description belong to. The default use is to have different translations of the labels and descriptions. However, this can also be used, for example, to specify short and long labels. When there is more than one locale, there should be multiple lines for each code, one for each locale.

parent

Optional. The parent of the code. This can be used to specify simple hierarchies. These should be of the same type as the 'code' column and values should be present in the 'code' column or be 'NA'. When the parent is 'NA' it is assumed this is a top level code. The hierarchy should form a tree.

The validity of the code list can be checked using cl_is_valid.


codelist documentation built on April 12, 2025, 2:25 a.m.