isubirana / compareGroups

R package to easily build publication-ready univariate or bivariate descriptive tables from a data set.
https://isubirana.github.io/compareGroups/
35 stars 13 forks source link

Name length issue when hiding multiple variable levels #38

Open gabevar opened 9 months ago

gabevar commented 9 months ago

Hi,

Thank you so much for your incredible work on this package. It's my go to for any data exploration, and I know that's the case for colleagues as well.

I've run into something that I think may be either an issue with the vignette or with the recent code update. In the vignette, you recommend that we pass a vector of named values to the hide argument of createTable:

createTable(res, hide.no='no', hide = c(sex="Male"))

In the latest update, running this is producing the following warning:

Show in New Window Error in names(temp) <- attr(x, "varnames.orig") : 'names' attribute [19] must be the same length as the vector [18]

Digging into your code, it looks like there's a discrepancy between the length of a "compareGroups" object and the number of "varnames.orig". I've added some comments to your code (from createTable.R)

x <- comp hide<-as.list(hide) if (!is.null(attr(hide,"names"))){ temp <- rep(NA,length(x)) # length of 18 names(temp)<- attr(x,"varnames.orig") # length of 19 if (!all(names(hide)%in%names(temp))) warning(paste("variables",paste(names(hide)[!names(hide)%in%names(temp)],collapse=", "),"specified in 'hide' not found")) kkk<-names(hide)[names(hide)%in%attr(x,"varnames.orig")] temp[kkk]<-hide[kkk] hide<-temp } else if (length(hide)==1) hide<-rep(hide,length(x))

Short-term this can be fixed in another language (e.g., word/latex/html) but I thought I'd highlight it. I can't attach a .rds file with my compareGroups object, but if need be I can create a test dataset that reproduces the error.

Thank you for all your work!

isubirana commented 9 months ago

First of all, thank you for using the compareGroups package and for you kind words. I'm glad it is usefull for your work. Answering to your question, I don't find any problem in the code. So, if would be very helpful if you provide/send an example in order to reproduce it. If a data set is necessary to do so, you can send it to me by e-mail.