camr_add_codebook_entry: Add a Codebook Entry to a Data Frame

View source: R/R07-Codebook.R

camr_add_codebook_entryR Documentation

Add a Codebook Entry to a Data Frame

Description

Function to update the attributes for a column in a data frame to contain a codebook entry. This ensures easy portability (at least within the framework of R) of the codebook for a data set.

Usage

camr_add_codebook_entry(
  dtf,
  variable,
  description = "",
  category = "",
  data_type = "",
  subcategory = "",
  values_and_labels = "",
  inventory = "",
  units_of_measurement = "",
  descriptive_summary = "",
  codes_for_missing_data = NULL,
  deidentified = "FALSE",
  collected_over = "",
  created_from = "",
  data_quality_checks = "",
  notes = "",
  custom_category = NULL,
  custom_data_type = NULL,
  custom_subcategory = NULL,
  missing_attribute_label = "missing",
  digits = 2,
  add_missing_to_attr = NULL,
  non_standard = TRUE
)

camr_ace(...)

Arguments

dtf

A data frame, preferably one using standardized naming conventions for columns (see camr_column_abbreviations).

variable

The column name for the variable whose attributes should be updated to include a codebook entry. Non-standard evaluation possible.

description

A character string, a brief human-readable description of what the variable is.

category

An optional character string, the category label for the variable. If left blank, the function automatically determines the category via camr_column_abbreviations.

data_type

An optional character string, the data type label for the variable. If left blank, the function automatically determines the data type via camr_column_abbreviations.

subcategory

An optional character string, the subcategory label for the variable. If left blank, the function automatically determines the subcategory via camr_column_abbreviations.

values_and_labels

Either the empty character set or a named list of two vectors, (1) content containing the distinct values for the variable, and (2) additional_content containing the label associated with each value in (1).

inventory

Either (1) output from the camr_inventories function, (2) the empty character set, or (3) a named list of two vectors, where content contains details on inventory an additional_content labels each type of detail (name, number of items, etc.).

units_of_measurement

A character string, the units of measurement for the variable.

descriptive_summary

Either the empty character set or a named list of two vectors, (1) content containing summary statistics for the variable, and (2) additional_content containing the label associated with each statistic in (1).

codes_for_missing_data

An optional vector with codes for missing data. If NULL uses default codes. If variable has an attribute with the codes, the codes in the attribute list override this argument.

deidentified

Either FALSE if the variable is not deidentified (i.e., contains potential patient health information) or TRUE otherwise.

collected_over

Either the empty character set or a named list of two vectors, (1) content containing distinct values for groups, time points, etc., over which the variable was collected, and (2) additional_content containing the column name associated with the values in (1).

created_from

An optional character vector, the original REDCap variables from which the variable was created.

data_quality_checks

An optional character string, notes on any data quality checks relevant to the variable.

notes

An optional character vector, any additional notes to include in the codebook entry.

custom_category

An optional matrix with two columns, 'Abbr' and 'Label', for custom abbreviations and labels for variable categories.

custom_data_type

An optional matrix with two columns, 'Abbr' and 'Label', for custom abbreviations and labels for data types.

custom_subcategory

An optional matrix with two columns, 'Abbr' and 'Label', for custom abbreviations and labels for variable subcategories.

missing_attribute_label

A character string, the name of the element in the list of attributes containing codes for missing data.

digits

The number of decimal places to round to for the descriptive summaries.

add_missing_to_attr

An optional logical value; if FALSE will not add codes for missing data to the attributes of Variable. If NULL defaults to adding if no pre-existing attribute is found.

non_standard

A logical value; if TRUE uses non-standard evaluation for variable.

Value

The data frame dtf, with the attributes for the column specified by variable updated to contain a data frame of additional class codebook_entry.

Author(s)

Kevin Potter

Examples

data( "example_CAM_data_set" )
dtf <- example_CAM_data_set

# Add codebook entry to data frame
dtf <- dtf |>
  camr_add_codebook_entry(
    IDS.INT.Screening,
    description = "Identifier assigned at screening session"
  )

dtf |> camr_pull_codebook_entry( IDS.INT.Screening )

dtf <- dtf |>
  camr_add_codebook_entry(
    IDS.CHR.Participant,
    "Identifier assigned at enrollment"
  )

dtf |> camr_pull_codebook_entry( IDS.CHR.Participant )

dtf <- dtf |>
  camr_add_codebook_entry(
    INV.INT.HADS_anxiety,
    inventory = camr_inventories( "HADS", "Anxiety" ),
    descriptive_summary = "continuous",
    collected_over = camr_ice(
      "combine",
      dtf |> camr_collected_over( INV.INT.HADS_anxiety, SSS.CHR.Session ),
      dtf |> camr_collected_over( INV.INT.HADS_anxiety, SSS.CHR.Event )
    )
  )
dtf |> camr_pull_codebook_entry( INV.INT.HADS_anxiety )


rettopnivek/camrprojects documentation built on March 26, 2024, 9:17 a.m.