Skip to contents

Retrieves attributes from a tibble object created by haven.

Usage

get.atr(tibble, which, NULLasNA = TRUE, exact = FALSE)

get.nas(tibble, aslist = TRUE)

get.varlab(tibble)

Arguments

tibble

a tibble object.

which

a non-empty character string specifying which attribute is to be accessed.

NULLasNA

a logical value indicating if NULL attributes should be listed as NA. Default is TRUE.

exact

logical: should which be matched exactly?

aslist

a logical value indicating if output should be a list.

Value

A list or a data frame.

Examples

# tibble generated by haven
input <- system.file("extdata/reds", package = "ILSAmerge")
x <- do.call(rbind,justload(inputdir = input,population = "BCGV1"))
x
#> # A tibble: 40 × 314
#>    IDCNTRY             IDSCHOOL ITLANGC      IP1G00A   IP1G00B      IP1G00C     
#>    <dbl+lbl>           <dbl+lb> <dbl+lbl>    <dbl+lbl> <dbl+lbl>    <dbl+lbl>   
#>  1 784 [United Arab E… 1001     53 [Arabic]  2 [Mid]   3 [March]    9 (NA) [Omi…
#>  2 784 [United Arab E… 1002     53 [Arabic]  1 [Early] 2 [February] 3 [Late]    
#>  3 784 [United Arab E… 1003     53 [Arabic]  1 [Early] 2 [February] 3 [Late]    
#>  4 784 [United Arab E… 1004      1 [English] 3 [Late]  2 [February] 3 [Late]    
#>  5 784 [United Arab E… 1005     53 [Arabic]  1 [Early] 3 [March]    3 [Late]    
#>  6 784 [United Arab E… 1006     53 [Arabic]  2 [Mid]   2 [February] 2 [Mid]     
#>  7 784 [United Arab E… 1007     53 [Arabic]  1 [Early] 3 [March]    3 [Late]    
#>  8 784 [United Arab E… 1008     53 [Arabic]  1 [Early] 3 [March]    2 [Mid]     
#>  9 784 [United Arab E… 1009     53 [Arabic]  2 [Mid]   3 [March]    1 [Early]   
#> 10 784 [United Arab E… 1010     53 [Arabic]  2 [Mid]   6 [June]     3 [Late]    
#> # ℹ 30 more rows
#> # ℹ 308 more variables: IP1G00D <dbl+lbl>, IP1GIAA <dbl+lbl>,
#> #   IP1GIAB <dbl+lbl>, IP1GIAC <dbl+lbl>, IP1GIAD <dbl+lbl>, IP1GIAE <dbl+lbl>,
#> #   IP1GIAF <dbl+lbl>, IP1GIAG <dbl+lbl>, IP1GIBA <dbl+lbl>, IP1GIBB <dbl+lbl>,
#> #   IP1GIBC <dbl+lbl>, IP1GIBD <dbl+lbl>, IP1G01A <dbl+lbl>, IP1G01B <dbl+lbl>,
#> #   IP1G01C1 <dbl+lbl>, IP1G01C2 <dbl+lbl>, IP2G01A1 <dbl+lbl>,
#> #   IP1G01AA <dbl+lbl>, IP1G02A <dbl+lbl>, IP1G02B <dbl+lbl>, …

# Get an attribute
get.atr(tibble = x, which = "label")[1:3]
#> $IDCNTRY
#> [1] "COUNTRY ID"
#> 
#> $IDSCHOOL
#> [1] "SCHOOL ID"
#> 
#> $ITLANGC
#> [1] "LANGUAGE OF QUESTIONNAIRE (NUMERIC)"
#> 
get.atr(tibble = x, which = "labels")[1:3]
#> $IDCNTRY
#>              Denmark             Ethiopia                India 
#>                  208                  231                  356 
#>                Kenya   Russian Federation               Rwanda 
#>                  404                  643                  646 
#>             Slovenia United Arab Emirates         Burkina Faso 
#>                  705                  784                  854 
#>              Uruguay           Uzbekistan 
#>                  858                  860 
#> 
#> $IDSCHOOL
#> [1] NA
#> 
#> $ITLANGC
#>    English     French    Spanish    Amharic  Af Somali Afan Oromo      Hindi 
#>          1          2          3          4          5          6          7 
#>     Danish    Russian    Slovene      Uzbek     Arabic    Omitted 
#>         11         29         31         33         53         99 
#> 
get.atr(tibble = x, which = "format.spss")[1:3]
#> $IDCNTRY
#> [1] "F5.0"
#> 
#> $IDSCHOOL
#> [1] "F4.0"
#> 
#> $ITLANGC
#> [1] "F2.0"
#> 

# Get NAs
get.nas(tibble = x,aslist = TRUE)[10:20]
#> $IP1GIAC
#> [1] 99
#> 
#> $IP1GIAD
#> [1] 99
#> 
#> $IP1GIAE
#> [1] 99
#> 
#> $IP1GIAF
#> [1] 99
#> 
#> $IP1GIAG
#> [1] 99
#> 
#> $IP1GIBA
#> [1] 6 9
#> 
#> $IP1GIBB
#> [1] 9
#> 
#> $IP1GIBC
#> [1] 9
#> 
#> $IP1GIBD
#> [1] 9
#> 
#> $IP1G01A
#> [1] 9
#> 
#> $IP1G01B
#> [1] 9
#> 
get.nas(tibble = x,aslist = FALSE)[10:20,]
#>       name NAs
#> 10 IP1GIAC  99
#> 11 IP1GIAD  99
#> 12 IP1GIAE  99
#> 13 IP1GIAF  99
#> 14 IP1GIAG  99
#> 15 IP1GIBA 6;9
#> 16 IP1GIBB   9
#> 17 IP1GIBC   9
#> 18 IP1GIBD   9
#> 19 IP1G01A   9
#> 20 IP1G01B   9

# Get variable labels
get.varlab(tibble = x)[10:20,]
#>       name                                              varlab
#> 10 IP1GIAC TOP1\\DURATION\\SCH CLOSED FOR STUDENTS WITH REMOTE
#> 11 IP1GIAD    TOP1\\DURATION\\SCH PARTIALLY CLOSED WITH REMOTE
#> 12 IP1GIAE              TOP1\\DURATION\\SCH OPENED SIG CHANGES
#> 13 IP1GIAF             TOP1\\DURATION\\SCH OPENED SOME CHANGES
#> 14 IP1GIAG                          TOP1\\DURATION\\NO CHANGES
#> 15 IP1GIBA                 TOP1\\EXEMPTIONS\\STD SPECIAL NEEDS
#> 16 IP1GIBB                       TOP1\\EXEMPTIONS\\STD AT RISK
#> 17 IP1GIBC             TOP1\\EXEMPTIONS\\STD ESSENTIAL WORKERS
#> 18 IP1GIBD               TOP1\\EXEMPTIONS\\STD SELECTED LEVELS
#> 19 IP1G01A                               TOP1\\LESSONS\\BEFORE
#> 20 IP1G01B                   TOP1\\LESSONS\\DURING ONLY REMOTE