Skip to content

dusadrian/declared

Folders and files

NameName
Last commit message
Last commit date

Latest commit

81c94af · Oct 11, 2024
Oct 6, 2024
Oct 11, 2024
Sep 5, 2024
Sep 2, 2024
Oct 11, 2024
Sep 9, 2024
Sep 9, 2024
Sep 5, 2024
May 8, 2023
Aug 31, 2022
May 8, 2023
Aug 31, 2022
Oct 11, 2024
Aug 10, 2022
Mar 31, 2024
Sep 4, 2024
Jul 16, 2023
Dec 7, 2023
Sep 22, 2022
Aug 23, 2022
Aug 23, 2022
Aug 31, 2022

Repository files navigation

declared

Lifecycle: experimental CRAN status AppVeyor build status Codecov test coverage

The goal of declared is to improve the functionality of imported social science microdata, particularly labelled data. While there are excellent packages available for these purposes, such as haven and labelled, they have some fundamental design features that run, in some situations, against users' expectations. This has a lot to do with the treatment of declared missing values, that are instrumental for the social sciences. The aim of declared is to offer an alternative class called "declared", whilst ensuring as much compatibility as possible with these popular packages.

Installation

The development version of package declared can be installed using this command:

install.packages("declared", repos = "dusadrian.r-universe.dev")

Example

library(haven)
x1 <- labelled_spss(
  x = c(1:5, -91),
  labels = c("Missing" = -91),
  na_value = -91
)

print(x1)
#> <labelled_spss<double>[6]>
#> [1]   1   2   3   4   5 -91
#> Missing values: -91
#> 
#> Labels:
#>  value   label
#>    -91 Missing

mean(x1)
#> [1] -12.66667

Instead of using the labelled::labelled() class or its inherited version in haven, the declared package offers a similar class that behaves more as it is expected–because it interprets certain “missing” values NA codes as existing, declared missing values.

library(declared)
x2 <- declared(
  x = c(1:5, -91),
  labels = c("Missing" = -91),
  na_value = -91
)

print(x2)
#> <declared<numeric>[6]>
#> [1]       1       2       3       4       5 NA(-91)
#> Missing values: -91
#> 
#> Labels:
#>  value   label
#>    -91 Missing

mean(x2)
#> [1] 3