dcomtois / summarytools

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

Bug in print generic implementation for list #186

Closed struckma closed 1 year ago

struckma commented 1 year ago

Dear maintainers, thank you for this great and versatile package. Unfortunately, I have to inform you about a bug in summarytools , where you have an implementation for the print generic for list objects. You assume, that all printed lists always have elements. Code to reproduce:

> # a fresh, unused R session...
> print(list()) # this works as expected
list()
> library(summarytools) # loading summarytools
> print(list()) # retry the formerly working print of an empty list
Error in x[[1]] : subscript out of bounds
> packageVersion("summarytools")
[1] ‘1.0.1’

The bug fix would be to change the function print.list, the line:

if (inherits(x[[1]], "summarytools")) {

should become

if (length(x) > 0 && inherits(x[[1]], "summarytools")) {

Thank you for considering a fix, have a great time

Stephan

dcomtois commented 1 year ago

Thanks Stephan, will be fixed soon.