How do I reproduce?:
library(Hmisc);x=data.frame(crash=rep(c(".","1","2","3","4","5"),2),y=1:12); describe(x)
This yields the error:
Error in if (print.ext) { : missing value where TRUE/FALSE needed
In addition: Warning message:
In all.is.numeric(names(weights), "vector") : NAs introduced by coercion
What's the cause?:
The problem https://github.com/harrelfe/Hmisc/blob/44f15e5587d0d88acbfd8969ab3e47706e1e24be/R/describe.s#L386 seems to originate from an attempt to format the output of the describe object (386 and 388 of describe.s). We try to see whether frequency will fit on the screen via a heuristic (200 and 20 char window), but we can't calculate how wide our output might be because one of our levels was converted to NA in the all.is.numeric function called by wtd.table , the nchar function yields an NA value, and summing over a vector with NA will yield NA without the na.rm flag.
Possible Solution
Given that this is really about guessing whether text will fit on screen in a reasonable manner, there seem to be several options on the table:
Simply add na.rm with the assumption that such a minor perturbation in calculating our screen fitting heuristic has no side effect (ex. too wide)
Replace the na value with something else after using the nchar function as a kind of 'fudge factor'
Alter extras in all.is.numeric such that we aren't as friendly about what counts as numeric
-- Another variation which probably reduces usability and may not be used by many users is to expose extras as an option in the top level describe function, but this seems like it's flexibility/complexity no one will use
I really like your book (only checked out the first edition and will have to look at the second). I'm not sure if this is enough information or follows proper etiquette but I think one of the solutions above will work and should be an easy fix.
Problem: It looks as though it's possible to crash the describe function by using using a character column which includes specific values. This originated from analyzing the dataset here: http://www.stat.columbia.edu/~gelman/arm/examples/radon/srrs2.dat
How do I reproduce?:
library(Hmisc);x=data.frame(crash=rep(c(".","1","2","3","4","5"),2),y=1:12); describe(x)
This yields the error:
Error in if (print.ext) { : missing value where TRUE/FALSE needed In addition: Warning message: In all.is.numeric(names(weights), "vector") : NAs introduced by coercion
What's the cause?: The problem https://github.com/harrelfe/Hmisc/blob/44f15e5587d0d88acbfd8969ab3e47706e1e24be/R/describe.s#L386 seems to originate from an attempt to format the output of the describe object (386 and 388 of describe.s). We try to see whether frequency will fit on the screen via a heuristic (200 and 20 char window), but we can't calculate how wide our output might be because one of our levels was converted to NA in the all.is.numeric function called by wtd.table , the nchar function yields an NA value, and summing over a vector with NA will yield NA without the na.rm flag.
Possible Solution Given that this is really about guessing whether text will fit on screen in a reasonable manner, there seem to be several options on the table:
I really like your book (only checked out the first edition and will have to look at the second). I'm not sure if this is enough information or follows proper etiquette but I think one of the solutions above will work and should be an easy fix.