dcomtois / summarytools

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

ctable error after update to R 4.2.0 Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, : invalid value 0 for 'digits' argument #163

Closed drpturner closed 2 years ago

drpturner commented 2 years ago

Since a recent update to R4.2.0 (Win11 64bit), accross the board I get the following error when running ctable()

Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, : invalid value 0 for 'digits' argument

freq() and all other summarytools commands seem ok.

This is true for new (test) data and when re-running scripts which previously worked fine.

drpturner commented 2 years ago

A follow up to this one. Interestingly the fix and update to v1.0.1 did not appear to fix my specific use case (but it does resolve the text example from the tobacco data).

My ctable issue seems to be due the fact that my row and column variables are numeric. See below for a test (and the fix) using the attached mock data. This is new with R 4.2.0 as previous to this the numeric variables worked fine.

library(summarytools) test <- read.csv("test.csv")

str(test) tibble [17,980 × 3] (S3: tbl_df/tbl/data.frame) $ rowname : chr [1:17980] "1" "2" "3" "4" ... $ present.mswp: num [1:17980] 0 0 0 1 0 0 1 0 0 0 ... $ present.cult: num [1:17980] 0 1 0 1 0 0 1 0 0 0 ...

ctable(test$present.mswp, test$present.cult) Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, : invalid value 0 for 'digits' argument

ctable(as.character(test$present.mswp), as.character(test$present.cult)) Cross-Tabulation, Row Proportions
as.character(test$present.mswp) * as.character(test$present.cult)


                                as.character(test$present.cult)               0              1            Total

as.character(test$present.mswp)
0 15583 (97.6%) 378 ( 2.4%) 15961 (100.0%) 1 897 (44.4%) 1122 (55.6%) 2019 (100.0%) Total 16480 (91.7%) 1500 ( 8.3%) 17980 (100.0%)



                                as.character(test$present.cult)               0              1            Total

as.character(test$present.mswp)
0 15583 (97.6%) 378 ( 2.4%) 15961 (100.0%) 1 897 (44.4%) 1122 (55.6%) 2019 (100.0%) Total 16480 (91.7%) 1500 ( 8.3%) 17980 (100.0%)


test.csv

RAnnan1 commented 1 year ago

I am having the same issue as this https://github.com/dcomtois/summarytools/issues/163#issue-1226158524 following an update. How do I resolve?

RAnnan1 commented 1 year ago

with(MWH, ctable(Location, TurnoutMonthsSince, prop = 'r')) Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, : invalid value 0 for 'digits' argument

bid27 commented 5 months ago

I am still having this same issue too, with only categorical/factor data when using ctable and pulling column values. Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L, : invalid value 0 for 'digits' argument