Skip to content

Commit

Permalink
fix: spss label variable
Browse files Browse the repository at this point in the history
  • Loading branch information
jinseob2kim committed May 8, 2024
1 parent 450c040 commit 3c97c9a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
9 changes: 6 additions & 3 deletions R/FilePsInput.R
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,13 @@ FilePs <- function(input, output, session, nfactor.limit = 20) {
}
}

for (vn in ref[["name.new"]]) {
w <- which(ref[["name.new"]] == vn)
out.label[variable == vn, var_label := ref[["name.old"]][w]]
if (tools::file_ext(input$file$name) != "sav") {
for (vn in ref[["name.new"]]) {
w <- which(ref[["name.new"]] == vn)
out.label[variable == vn, var_label := ref[["name.old"]][w]]
}
}

out.label <- rbind(out.label, data.table(variable = "pscore", class = "numeric", level = NA, var_label = "pscore", val_label = NA))

return(list(data = out, label = out.label, data_varStruct = list(variable = names(out)), except_vars = data.info()$except_vars))
Expand Down
8 changes: 5 additions & 3 deletions R/FileRepeatedInput.R
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,11 @@ FileRepeated <- function(input, output, session, nfactor.limit = 20) {
}
}

for (vn in ref[["name.new"]]) {
w <- which(ref[["name.new"]] == vn)
out.label[variable == vn, var_label := ref[["name.old"]][w]]
if (tools::file_ext(input$file$name) != "sav") {
for (vn in ref[["name.new"]]) {
w <- which(ref[["name.new"]] == vn)
out.label[variable == vn, var_label := ref[["name.old"]][w]]
}
}

return(list(data = out, label = out.label, naomit = data()$naomit, id.gee = input$repeated_vname))
Expand Down
8 changes: 5 additions & 3 deletions R/FileSurveyInput.R
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,11 @@ FileSurvey <- function(input, output, session, nfactor.limit = 20) {
}
}

for (vn in ref[["name.new"]]) {
w <- which(ref[["name.new"]] == vn)
out.label[variable == vn, var_label := ref[["name.old"]][w]]
if (tools::file_ext(input$file$name) != "sav") {
for (vn in ref[["name.new"]]) {
w <- which(ref[["name.new"]] == vn)
out.label[variable == vn, var_label := ref[["name.old"]][w]]
}
}


Expand Down
9 changes: 6 additions & 3 deletions R/csvFileInput.R
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,14 @@ csvFile <- function(input, output, session, nfactor.limit = 20) {
}
}

for (vn in ref[["name.new"]]) {
w <- which(ref[["name.new"]] == vn)
out.label[variable == vn, var_label := ref[["name.old"]][w]]
if (tools::file_ext(input$file$name) != "sav") {
for (vn in ref[["name.new"]]) {
w <- which(ref[["name.new"]] == vn)
out.label[variable == vn, var_label := ref[["name.old"]][w]]
}
}


return(list(
data = out,
label = out.label,
Expand Down
14 changes: 4 additions & 10 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,14 @@
#' @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)) {
if (is.factor(out.old[[v]])) {
for (v in names(label.value)){
if (any(out.label[variable == v, class] != "numeric")){
out.label[variable == v, val_label := label.value[[v]][level]]
}
}
Expand Down

0 comments on commit 3c97c9a

Please sign in to comment.