Package 'labeler'

Title: Easy to use and share data labels in R
Description: Functions to assign and use data labels in an easy and efficient way. With an easy-to-share structure.
Authors: Daniel E. de la Rosa [aut, cre], Adatar [cph]
Maintainer: Daniel E. de la Rosa <[email protected]>
License: MIT + file LICENSE
Version: 0.6.5
Built: 2024-11-15 05:53:27 UTC
Source: https://github.com/adatar-do/labeler

Help Index


Browse dictionary [Experimental]

Description

Allows you to browse the dictionary of the surveys in a web interface where you can check the name and label of the variables, as well as the data labels.

Usage

browse_dict(dict, ...)

Arguments

dict

database dictionary

...

for testing purposes

Value

a web interface with the data contained in the supplied dictionary

Examples

## Not run: 
dict <- list(
  SEX = list(
    lab = "Sex of the person",
    labs = c("Man" = 1, "Woman" = 2)
  ),
  MARITAL_STATUS = list(
    lab = "Marital status of the person",
    labs = c("Single" = 1, "Married" = 2, "Widower" = 3)
  ),
  HEIGHT = list(
    lab = "Person height",
    labs = c("Short" = 1, "Normal" = 2, "High" = 3)
  )
)
browse_dict(dict)

## End(Not run)

Generate a dictionary of given dataset [Experimental]

Description

Generate a dictionary of given dataset [Experimental]

Usage

get_dict(tbl)

Arguments

tbl

A labelled dataset

Value

A dictionary of the dataset

Examples

## Not run: 
 get_dict(tbl)

## End(Not run)

Replace non ASCII characters with ASCII equivalents [Experimental]

Description

Replace non ASCII characters with ASCII equivalents [Experimental]

Usage

parse_dict(dict)

Arguments

dict

A dictionary. See vignette('labeler', package = "labeler") for details.

Value

A dictionary with all non ASCII characters replaced with ASCII

Examples

## Not run: 
   dict = list(
             MARRIED = list(
               "Sí" = 1,
               "No" = 2
             )
           )
   parse_dict(dict)
 
## End(Not run)

Assign data labels to specified variables [Experimental]

Description

Assign data labels to specified variables [Experimental]

Usage

set_labels(tbl, dict, vars = NULL, ignore_case = FALSE, warn = TRUE)

Arguments

tbl

data.frame: Data.frame with the data

dict

data.frame: Dictionary with all the data labels to use

vars

character: If specified, only labels are assigned to those variables

ignore_case

logical: Indicate if case sensitive should be ignored.

warn

logical: Indicate if warnings should be shown.

Value

The data entered in the tbl argument but with data labels

See Also

Data labels vignette("labeler", package = "labeler")

Examples

## Not run: 
dict <- list(
  SEX = list(
    lab = "Sex of the person",
    labs = c(
      "Man" = 1,
      "Woman" = 2
    )
  )
)
df <- data.frame(SEX = c(1, 2))
str(df)
str(set_labels(df, dict = dict))

## End(Not run)

Use the data labels of a variable instead of its values [Experimental]

Description

Use the data labels of a variable instead of its values [Experimental]

Usage

use_labels(tbl, dict, vars = NULL, ignore_case = F, check = TRUE, warn = TRUE)

Arguments

tbl

data.frame: Data.frame with the data

dict

data.frame: Dictionary with all the data labels to use if they have not yet been assigned. See Details

vars

character: If specified, only labels are assigned to those variables

ignore_case

logical: Indicate if case sensitive should be ignored

check

logical: If TRUE (default), the function will check if values present in variable are valid data labels in dictionary.

warn

logical: Indicate if warnings should be shown.

Details

This function assumes that the data labels have been assigned to the data before, unless a dict is supplied, in which case the latter will be used to assign and use the data labels.

Value

The data supplied in the tbl argument, but instead of values using the corresponding data labels

See Also

Data labels vignette("labeler", package = "labeler")

Examples

## Not run: 
dict <- list(
  SEX = list(
    lab = "Sex of the person",
    labs = c(
      "Man" = 1,
      "Woman" = 2
    )
  )
)
enft <- data.frame(SEX = c(1, 2))
enft
use_labels(enft, dict = dict)

## End(Not run)