liud4 / rVMAP

Data Management code for VMAC-MAP study
Other
3 stars 0 forks source link

factor variables do not have labels in most recent merge #17

Closed omair-a-khan closed 5 years ago

omair-a-khan commented 5 years ago

as a temporary solution, do something like the following:

labels.df <- bind_rows(
  tibble(
    variable = grep("factor", all.var.list, v = T), 
    label = purrr::map_chr(gsub(".factor|.base", "", grep("factor", all.var.list, v = T)), function(x) Hmisc::label(merged.df[[x]]))
  ),
  tibble(
    variable = grep("factor", all.var.list, v = T, invert = T),
    label = purrr::map_chr(grep("factor", all.var.list, v = T, invert = T), function(x) Hmisc::label(proj.data.df[[x]]))
  ),
  c(variable = "ma.scan.date.diff.yr", label = "Time between follow up (MA), years"),
  c(variable = "wml.scan.date.diff.yr", label = "Time between follow up (WML), years")
)

###...

for (var.i in labels.df$variable) {
  Hmisc::label(proj.data.df[, var.i]) <- labels.df[labels.df$variable == var.i, "label"]
}
omair-a-khan commented 5 years ago

I opened an issue in the Hmisc repo to see if there is another way to bypass this: https://github.com/harrelfe/Hmisc/issues/110

omair-a-khan commented 5 years ago

This is not an issue with rVMAP code. This is due to how labels are handled in droplevels(). No one has updated the issue thread (harrelfe/Hmisc#110), so I will close this issue.