Skip to content

Instantly share code, notes, and snippets.

@avallecam
Created July 11, 2025 15:57
Show Gist options
  • Select an option

  • Save avallecam/63e57f6d0b8af43167cc0c9d440dd1b1 to your computer and use it in GitHub Desktop.

Select an option

Save avallecam/63e57f6d0b8af43167cc0c9d440dd1b1 to your computer and use it in GitHub Desktop.
How to validate a linelist with column age factor?
``` r
library(tidyverse)
set.seed(1)
age_df <- tibble::tibble(age_int = floor(rnorm(
n = 4, mean = 4, sd = 3
)))
age_df
#> # A tibble: 4 × 1
#> age_int
#> <dbl>
#> 1 2
#> 2 4
#> 3 1
#> 4 8
age_df %>%
linelist::make_linelist(age = "age_int") %>%
linelist::validate_linelist()
#> '.' is a valid linelist object
age_df %>%
dplyr::mutate(age_fct = fct(as.character(age_int))) %>%
linelist::make_linelist(age = "age_int",
age_factor = "age_fct",
allow_extra = TRUE) %>%
linelist::validate_linelist(
allow_extra = TRUE,
ref_types = linelist::tags_types(age_factor = "factor", allow_extra = TRUE)
)
#> '.' is a valid linelist object
```
<sup>Created on 2025-07-11 with [reprex v2.1.1](https://reprex.tidyverse.org)</sup>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment