Skip to content

Commit 836bb15

Browse files
committed
Update labels, zap formats
1 parent 168ffbf commit 836bb15

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

data-raw/nsduh_2023.R

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,22 @@ nsduh_slim %>%
6060
nsduh_slim %>%
6161
select(-where(is.factor))
6262

63+
# Update labels and zap formats
64+
65+
update_label <- function(var) {
66+
attr(nsduh_slim[[var]], "label") <<- attr(puf2023_102124[[var]], "label")
67+
}
68+
69+
walk(names(nsduh_slim), update_label)
70+
71+
haven::zap_formats(nsduh_slim)
72+
73+
str(nsduh_slim)
74+
6375
nsduh_slim_md <- tibble(
6476
Variable = names(nsduh_slim),
6577
Class = sapply(nsduh_slim, class),
66-
Label = map_chr(names(nsduh_slim), \(x) attr(puf2023_102124[[x]], "label"))
78+
Label = map_chr(names(nsduh_slim), \(x) attr(nsduh_slim[[x]], "label"))
6779
) %>%
6880
mutate(
6981
Class2 = map_chr(Class, ~ str_flatten(.x, collapse = ";")),
@@ -85,4 +97,4 @@ ncol(nsduh_2023)
8597

8698
usethis::use_data(nsduh_2023, overwrite = TRUE)
8799

88-
unlink(here::here("nsduh-temp"), recursive = TRUE)
100+
unlink(here::here("nsduh-temp"), recursive = TRUE)

data/nsduh_2023.rda

688 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)