1111# ' as with \code{2} is used, but the analytical variable is placed in
1212# ' first position. Depending on what function was used for grouping,
1313# ' the results will be different in subtle ways. See \emph{Details}.
14- # ' @param na.rm Logical. Affects grouped \code{\link{freq}} objects only.
15- # ' Discard rows with \code{NA} values on at least one of the grouping
16- # ' variables. \code{FALSE} by default. (To exclude NA values on the main
17- # ' variable as well as \emph{pct_valid} & \emph{pct_valid_cum} columns, use
18- # ' \code{freq()}'s `report.nas` and `cumul` arguments.)
1914# ' @param drop.var.col Logical. For \code{\link{descr}} objects, drop the
2015# ' \code{variable} column. This is possible only when statistics are
2116# ' produced for a single variable; when multiple variables are present,
6156# ' @importFrom tibble tibble as_tibble
6257# ' @importFrom dplyr bind_rows bind_cols
6358# ' @export
64- tb <- function (x , order = 1 , na.rm = FALSE , drop.var.col = FALSE ,
59+ tb <- function (x , order = 1 , drop.var.col = FALSE ,
6560 recalculate = TRUE , fct.to.chr = FALSE , ... ) {
6661
6762 # For dispatched list elements having a NULL group
@@ -88,7 +83,7 @@ tb <- function(x, order = 1, na.rm = FALSE, drop.var.col = FALSE,
8883}
8984
9085# ' @exportS3Method tb default
91- tb.default <- function (x , order = 1 , na.rm = FALSE , drop.var.col = FALSE ,
86+ tb.default <- function (x , order = 1 , drop.var.col = FALSE ,
9287 recalculate = TRUE , fct.to.chr = FALSE , ... ) {
9388
9489 st_type <- attr(x , " st_type" )
@@ -100,13 +95,13 @@ tb.default <- function(x, order = 1, na.rm = FALSE, drop.var.col = FALSE,
10095
10196 do.call(
10297 method ,
103- list (x = x , order = order , na.rm = na.rm , drop.var.col = drop.var.col ,
98+ list (x = x , order = order , drop.var.col = drop.var.col ,
10499 recalculate = recalculate , fct.to.chr = fct.to.chr , ... )
105100 )
106101}
107102
108103# ' @exportS3Method tb summarytools
109- tb.summarytools <- function (x , order = 1 , na.rm = FALSE , drop.var.col = FALSE ,
104+ tb.summarytools <- function (x , order = 1 , drop.var.col = FALSE ,
110105 recalculate = TRUE , fct.to.chr = FALSE , ... ) {
111106
112107 st_type <- attr(x , " st_type" )
@@ -118,24 +113,24 @@ tb.summarytools <- function(x, order = 1, na.rm = FALSE, drop.var.col = FALSE,
118113
119114 do.call(
120115 method ,
121- list (x = x , order = order , na.rm = na.rm , drop.var.col = drop.var.col ,
116+ list (x = x , order = order , drop.var.col = drop.var.col ,
122117 recalculate = recalculate , fct.to.chr = fct.to.chr , ... )
123118 )
124119}
125120
126121
127122# ' @exportS3Method tb by
128- tb.by <- function (x , order = 1 , na.rm = FALSE , drop.var.col = FALSE ,
123+ tb.by <- function (x , order = 1 , drop.var.col = FALSE ,
129124 recalculate = TRUE , fct.to.chr = FALSE , ... ) {
130125 do.call(
131126 tb.stby ,
132- list (x = x , order = order , na.rm = na.rm , drop.var.col = drop.var.col ,
127+ list (x = x , order = order , drop.var.col = drop.var.col ,
133128 recalculate = recalculate , fct.to.chr = fct.to.chr , ... )
134129 )
135130}
136131
137132# ' @exportS3Method tb stby
138- tb.stby <- function (x , order = 1 , na.rm = FALSE , drop.var.col = FALSE ,
133+ tb.stby <- function (x , order = 1 , drop.var.col = FALSE ,
139134 recalculate = TRUE , fct.to.chr = FALSE , ... ) {
140135
141136 st_type <- attr(x [[1 ]], " st_type" )
@@ -147,19 +142,16 @@ tb.stby <- function(x, order = 1, na.rm = FALSE, drop.var.col = FALSE,
147142
148143 do.call(
149144 method ,
150- list (x = x , order = order , na.rm = na.rm , drop.var.col = drop.var.col ,
145+ list (x = x , order = order , drop.var.col = drop.var.col ,
151146 recalculate = recalculate , fct.to.chr = fct.to.chr , ... )
152147 )
153148}
154149
155150# Handles lists containing freq objects when freq() is called on a df
156151# ' @exportS3Method tb list
157- tb.list <- function (x , order = 1 , na.rm = FALSE , drop.var.col = FALSE ,
152+ tb.list <- function (x , order = 1 , drop.var.col = FALSE ,
158153 recalculate = FALSE , fct.to.chr = TRUE , ... ) {
159154
160- if (isTRUE(na.rm ))
161- message(" na.rm is only applicable to by-group results" )
162-
163155 if (isTRUE(recalculate ))
164156 message(" recalculate is only applicable to by-group results" )
165157
@@ -177,7 +169,7 @@ tb.list <- function(x, order = 1, na.rm = FALSE, drop.var.col = FALSE,
177169
178170 # Get first set of results
179171 gr_res <- do.call(tb_freq ,
180- list (x = x [[1 ]], order = 1 , na.rm = FALSE ,
172+ list (x = x [[1 ]], order = 1 ,
181173 recalculate = FALSE , fct.to.chr = TRUE ))
182174
183175 colnames(gr_res )[1 ] <- " value"
@@ -189,7 +181,7 @@ tb.list <- function(x, order = 1, na.rm = FALSE, drop.var.col = FALSE,
189181
190182 for (group in 2 : length(x )) {
191183 gr_res <- do.call(tb_freq ,
192- list (x = x [[group ]], order = 1 , na.rm = FALSE ,
184+ list (x = x [[group ]], order = 1 ,
193185 recalculate = FALSE , fct.to.chr = TRUE ))
194186
195187 colnames(gr_res )[1 ] <- " value"
@@ -206,7 +198,7 @@ tb.list <- function(x, order = 1, na.rm = FALSE, drop.var.col = FALSE,
206198 return (output )
207199}
208200
209- tb_stby_freq <- function (x , order = 1 , na.rm = FALSE , drop.var.col = FALSE ,
201+ tb_stby_freq <- function (x , order = 1 , drop.var.col = FALSE ,
210202 recalculate = TRUE , fct.to.chr = FALSE , ... ) {
211203
212204 # initialise variables relevant only to stby() objects
@@ -239,7 +231,7 @@ tb_stby_freq <- function(x, order = 1, na.rm = FALSE, drop.var.col = FALSE,
239231
240232 # Dispatch to tb_freq
241233 grp_stats <- lapply(x , function (group ) {
242- tb(group , fct.to.chr = TRUE )
234+ tb(group , fct.to.chr = fct.to.chr )
243235 })
244236
245237 # Eliminate null groups
@@ -256,13 +248,6 @@ tb_stby_freq <- function(x, order = 1, na.rm = FALSE, drop.var.col = FALSE,
256248 output <- dplyr :: bind_rows(grp_stats )
257249 var_name <- colnames(output )[nb_gr_var + 1 ]
258250
259- # Remove rows having grouping vars = NA when na.rm = TRUE
260- if (isTRUE(na.rm )) {
261- na_rows <- which(rowSums(is.na(output [,1 : nb_gr_var ])) > 0 )
262- if (length(na_rows ) > 0 )
263- output <- output [- na_rows ,]
264- }
265-
266251 # Adjust ordering of rows and columns ('order' arg)
267252 if (order %in% c(2 ,3 )) {
268253 output <- output [
@@ -342,7 +327,7 @@ tb_stby_freq <- function(x, order = 1, na.rm = FALSE, drop.var.col = FALSE,
342327 return (output )
343328}
344329
345- tb_stby_descr <- function (x , order = 1 , na.rm = FALSE , drop.var.col = FALSE ,
330+ tb_stby_descr <- function (x , order = 1 , drop.var.col = FALSE ,
346331 recalculate = NA , fct.to.chr = FALSE , ... ) {
347332
348333 grp_stats <- lapply(x , function (group ) {
@@ -412,12 +397,9 @@ tb_stby_descr <- function(x, order = 1, na.rm = FALSE, drop.var.col = FALSE,
412397}
413398
414399# Single freq object -------------------------------------------------------
415- tb_freq <- function (x , order = 1 , na.rm = FALSE , drop.var.col = FALSE ,
400+ tb_freq <- function (x , order = 1 , drop.var.col = FALSE ,
416401 recalculate = FALSE , fct.to.chr = FALSE , ... ) {
417-
418- if (isTRUE(na.rm ))
419- message(" na.rm ignored for single results; use freq(x, report.nas = FALSE)" )
420-
402+
421403 # Flags for columns to keep in the output
422404 report.nas <- attr(x , " format_info" )$ report.nas
423405 cumul <- attr(x , " format_info" )$ cumul
@@ -510,7 +492,7 @@ tb_freq <- function(x, order = 1, na.rm = FALSE, drop.var.col = FALSE,
510492}
511493
512494# Single descr object ------------------------------------------------------
513- tb_descr <- function (x , order = 1 , na.rm = FALSE , drop.var.col = FALSE ,
495+ tb_descr <- function (x , order = 1 , drop.var.col = FALSE ,
514496 recalculate = FALSE , fct.to.chr = FALSE , ... ) {
515497
516498 if (! isTRUE(attr(x , " data_info" )$ transposed )) {
0 commit comments