From ad342a1acaf92167b371bc7192c92d1d53b21461 Mon Sep 17 00:00:00 2001 From: Jinseob Kim Date: Wed, 8 May 2024 22:59:32 +0900 Subject: [PATCH] fix mk.lev2 --- R/utils.R | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/R/utils.R b/R/utils.R index 75015cec..e9e69161 100644 --- a/R/utils.R +++ b/R/utils.R @@ -7,21 +7,19 @@ #' @importFrom DT %>% mk.lev2 <- function(out.old, out.label) { . <- variable <- val_label <- level <- NULL - label.value <- sapply(out.old, function(x) attr(x, "labels")) %>% - .[!sapply(., is.null)] %>% - sapply(function(x) { - dd <- names(x) - names(dd) <- x - return(dd) - }) + label.value <- sapply(out.old, function(x) attr(x, "labels")) %>% .[!sapply(., is.null)] %>% sapply(function(x){dd <- names(x);names(dd) <- x;return(dd)}) label.variable <- sapply(out.old, function(x) attr(x, "label")) %>% .[!sapply(., is.null)] - for (v in names(label.variable)) { + for (v in names(label.variable)){ out.label[variable == v, var_label := label.variable[v]] } - for (v in names(label.value)) { - out.label[variable == v, val_label := label.value[[v]][level]] + for (v in names(label.value)){ + if (is.factor(out.old[[v]])){ + out.label[variable == v, val_label := label.value[[v]][level]] + } } return(out.label[]) } + +