px_variable_label.px: Change VARIABLE-LABEL

View source: R/modify_variable2.R

px_variable_labelR Documentation

Change VARIABLE-LABEL

Description

Inspect or change VARIABLE-LABEL.

The variable label is the name that is shown in the PX-file.

Usage

px_variable_label(x, value, validate)

## S3 method for class 'px'
px_variable_label(x, value, validate = TRUE)

Arguments

x

A px object

value

Optional. A character string or data frame.

  • Use character to set VARIABLE-LABEL for all languages and STUB/HEADING variables.

  • Use data frame with columns 'variable-code', 'language' and 'variable-label' to set VARIABLE-LABEL for specific variables.

  • If missing, the current VARIABLE-LABEL is returned.

  • If NULL, VARIABLE-LABEL is removed for all variables.

validate

Optional. If TRUE a number of validation checks are performed on the px object, and an error is thrown if the object is not valid. If FALSE, the checks are skipped, which can be usefull for large px objects where the check can be time consuming. Use px_validate() to manually preform the check.

Value

A px object, a character string, or a data frame.

Examples

# Set VARIABLE-LABEL for individual variables
library(tibble)
x1 <-
  px(population_gl) |>
  px_variable_label(tribble(~`variable-code`, ~`variable-label`,
                            'gender',         'Gender',
                            'age',            'Age'))
px_variable_label(x1)

# Set VARIABLE-LABEL for individual languages
x2 <-
  x1 %>%
  px_languages(c('en', 'kl')) |>
  px_variable_label(tribble(~`variable-code`, ~language, ~`variable-label`,
                            'gender',         'en',      'Gender',
                            'gender',         'kl',      'Suiaassuseq',
                            'age',            'en',      'Age',
                            'age',            'kl',      'Ukiut'))
px_variable_label(x2)

# Remove VARIABLE-LABEL
x3 <- px_variable_label(x2, NULL)
px_variable_label(x3)

pxmake documentation built on April 11, 2025, 6:06 p.m.