summarytools icon indicating copy to clipboard operation
summarytools copied to clipboard

descr crashes when only one summary statistics is specified

Open alexploner opened this issue 2 years ago • 1 comments

R 4.1.0 on Ubuntu 21.10, summarytools 1.0.0

Calls to descr that only specify one summary statistic will crash:

> descr(rnorm(100), stats = "mean")
Error in if (colnames(output)[i] == "sd") { : argument is of length zero

Regardless whether I feed it a vector or a data frame:

> descr(cars, stats = "mean")
Error in if (colnames(output)[i] == "sd") { : argument is of length zero

From a quick look with debug, the problem seems to be this line of code in descr:

output <- output[, stats]

where the output object loses its data frame status; replacing it with

output <- output[, stats, drop = FALSE]

should solve the issue.

Thanks for a great package!

alexploner avatar Mar 15 '22 10:03 alexploner

Thx for reporting this, should be fixed in next release.

dcomtois avatar May 19 '22 04:05 dcomtois

Fixed.

dcomtois avatar Sep 20 '22 05:09 dcomtois