dcomtois / summarytools

R Package to Quickly and Neatly Summarize Data
523 stars 78 forks source link

descr crashes when only one summary statistics is specified #159

Closed alexploner closed 2 years ago

alexploner commented 2 years ago

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!

dcomtois commented 2 years ago

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

dcomtois commented 2 years ago

Fixed.