Closed lemna closed 7 years ago
Hi Peter,
interesting bug. It seems that by() returns a NULL
when a variable is missing. I guess the easiest solution is to add a wrapper to the by() function that replaces the NULL
with whatever it should be. I tried adding just:
if (any(sapply(t, is.null))){
for (i in which(sapply(t, is.null)))
t[[i]] <- NA
}
and it does take care of the fn_name error. In addition I think the addEmptyValuesToMakeListCompatibleWithMatrix
should fill the matrix with NA and not 0 - not sure why I designed it in this way. This still leaves the last issue - this is on a higher design level, I would use an alternative design:
descs <-
lapply(levels(trial_missing_both$visit), function(x)
getDescriptionStatsBy(x = trial_missing_both$outcome[trial_missing_both$visit == x],
by = trial_missing_both$arm[trial_missing_both$visit == x],
continuous_fn = descriptive_function))
mergeDesc(descs,
htmlTable_args = list(rgroup = levels(trial_missing_second$visit),
n.rgroup = sapply(descs, nrow)))
This does leave you with an ugly rowname :-( but you could have a look at this section:
if (is.null(rownames(results)) && nrow(results) == 1)
rownames(results) <- name
A PR is of course always welcome. Thanks for the excellent report.
Hi Max,
I would prefer the following for the last issue:
missing_value
to provide output with the expected dimensionsThe advantage is that in a script you don't have to guess or check what n.rgroup
will be, and the correct rgroup
will be used. What do you think?
Peter.
Sure, I don't have a strong opinion about it. The naming of argument allows ridiculously many parameters and why no use it?
Thanks! Merged. Will upload to CRAN this week.
Hi Max,
I regularly run into the following situation with clinical trial data:
getDescriptionStatsBy
that generates output with length > 1mergeDesc
andlapply
to run this function over a number of observationsThere are two problems with this solution:
n.rgroup
should be, and causes inconsistent table layout.The first case is relatively easy. I've written some code to deal with it that won't change anything in existing calls to
getDescriptionStatsBy
. Would you accept a PR for this?I am not sure how you would like the function to react in case 2. IMO, it should return a named vector with indicators for empty values. This named vector would be a new argument to
getDescriptionStatsBy
. The default value of this empty vector would be NULL so as not to disturb existing code. What do you think?Thanks, Peter.
Toy example: