dcomtois / summarytools

R Package to Quickly and Neatly Summarize Data
504 stars 77 forks source link

freq error with variables imported by haven #142

Closed dkermer closed 3 years ago

dkermer commented 3 years ago

I use the haven package to read SPSS files, but then I can't use freq on the variables. Although many ultimately get converted to factors, which work great,, it would be helpful to be able to use freq initially. The function descr does work without error.

> freq(data$var)
Error in if (data_info$Data.type == trs("numeric")) { : 
  argument is of length zero

In the freq.R script in the section starting at line 521, various variable classes are tested for. However, none of the listed classes match what haven uses.

> class(data$var)
"haven_labelled" "vctrs_vctr"     "double"

I don't know how determine whether adding an "else if" for one of those classes would fix this error, so I will share this guess in hopes that someone can help fix it. If it helps, mode(data$var) does return "numeric".

dcomtois commented 3 years ago

Oh, I thought I had implemented a default or "fall-back" value for Data.type, but something's amiss. Thanks for bringing it up, will fix asap.

dcomtois commented 3 years ago

I tried to reproduce the problem but I can't. What version of summarytools do you have? If you have the latest CRAN version, I think if you update by installing from Github, you should get correct results. An update is going to CRAN soon.

dcomtois commented 3 years ago

Closing, if problem persists just reply. Thx.