21
21
# ' so countries that represent less than 10% will be combined in the "other" category).
22
22
# ' @param participants The name of the participants' identifier column (for
23
23
# ' instance in the case of repeated measures).
24
- # ' @param group A character vector indicating the name(s) of the column(s) used
24
+ # ' @param by A character vector indicating the name(s) of the column(s) used
25
25
# ' for stratified description.
26
26
# ' @param spell_n Logical, fully spell the sample size (`"Three participants"`
27
27
# ' instead of `"3 participants"`).
28
28
# ' @inheritParams report.numeric
29
+ # ' @param group Deprecated. Use `by` instead.
29
30
# '
30
31
# ' @return A character vector with description of the "participants", based on
31
32
# ' the information provided in `data`.
106
107
# ' sex = "Sex",
107
108
# ' gender = "Gender",
108
109
# ' participants = "Participant",
109
- # ' group = "Condition"
110
+ # ' by = "Condition"
110
111
# ' )
111
112
# '
112
113
# ' # Spell sample size
@@ -123,14 +124,21 @@ report_participants <- function(data,
123
124
country = NULL ,
124
125
race = NULL ,
125
126
participants = NULL ,
126
- group = NULL ,
127
+ by = NULL ,
127
128
spell_n = FALSE ,
128
129
digits = 1 ,
129
130
threshold = 10 ,
131
+ group = NULL ,
130
132
... ) {
133
+ # # TODO: deprecate later
134
+ if (! is.null(group )) {
135
+ insight :: format_warning(" Argument `group` is deprecated and will be removed in a future release. Please use `by` instead." ) # nolint
136
+ by <- group
137
+ }
138
+
131
139
# Convert empty strings to NA
132
140
data_list <- lapply(data , function (x ) {
133
- x [which(x == " " )] <- NA
141
+ x [which(x == " " )] <- NA # nolint
134
142
x
135
143
})
136
144
data <- as.data.frame(data_list , stringsAsFactors = FALSE )
@@ -165,8 +173,8 @@ report_participants <- function(data,
165
173
race <- .find_race_in_data(data )
166
174
}
167
175
168
- if (is.null(group )) {
169
- text <- .report_participants(
176
+ if (is.null(by )) {
177
+ final_text <- .report_participants(
170
178
data ,
171
179
age = age ,
172
180
sex = sex ,
@@ -181,9 +189,9 @@ report_participants <- function(data,
181
189
...
182
190
)
183
191
} else {
184
- text <- NULL
185
- data [[group ]] <- as.character(data [[group ]])
186
- for (i in split(data , data [group ])) {
192
+ final_text <- NULL
193
+ data [[by ]] <- as.character(data [[by ]])
194
+ for (i in split(data , data [by ])) {
187
195
current_text <- .report_participants(
188
196
i ,
189
197
age = age ,
@@ -200,15 +208,15 @@ report_participants <- function(data,
200
208
201
209
pre_text <- paste0(
202
210
" the '" ,
203
- paste0(names(i [group ]), " - " , vapply(i [group ], unique , " character" ), collapse = " and " ),
211
+ paste0(names(i [by ]), " - " , vapply(i [by ], unique , " character" ), collapse = " and " ),
204
212
" ' group: "
205
213
)
206
214
207
- text <- c(text , paste0(pre_text , current_text ))
215
+ final_text <- c(final_text , paste0(pre_text , current_text ))
208
216
}
209
- text <- paste(" For" , datawizard :: text_concatenate(text , sep = " , for " , last = " and for " ))
217
+ final_text <- paste(" For" , datawizard :: text_concatenate(final_text , sep = " , for " , last = " and for " ))
210
218
}
211
- text
219
+ final_text
212
220
}
213
221
214
222
# ' @keywords internal
@@ -338,9 +346,7 @@ report_participants <- function(data,
338
346
) %in% c(" male" , " m" , " female" , " f" , NA , " na" )]) /
339
347
nrow(data ) * 100 , digits = digits ),
340
348
" % other" ,
341
- if (! insight :: format_value(length(data [[sex ]][tolower(
342
- data [[sex ]]
343
- ) %in% c(NA , " na" )]) / nrow(data ) * 100 ) == " 0.00" ) {
349
+ if (insight :: format_value(length(data [[sex ]][tolower(data [[sex ]]) %in% c(NA , " na" )]) / nrow(data ) * 100 ) != " 0.00" ) { # nolint
344
350
paste0(" , " , insight :: format_value(length(data [[sex ]][tolower(
345
351
data [[sex ]]
346
352
) %in% c(NA , " na" )]) / nrow(data ) * 100 ), " % missing" )
@@ -375,9 +381,9 @@ report_participants <- function(data,
375
381
data [[gender ]]
376
382
) %in% both_genders ]) /
377
383
nrow(data ) * 100 ), " % non-binary" ,
378
- if (! insight :: format_value(length(data [[gender ]][tolower(
384
+ if (insight :: format_value(length(data [[gender ]][tolower(
379
385
data [[gender ]]
380
- ) %in% c(NA , " na" )]) / nrow(data ) * 100 ) = = " 0.00" ) {
386
+ ) %in% c(NA , " na" )]) / nrow(data ) * 100 ) ! = " 0.00" ) {
381
387
paste0(" , " , insight :: format_value(length(data [[gender ]][tolower(
382
388
data [[gender ]]
383
389
) %in% c(NA , " na" )]) / nrow(data ) * 100 ), " % missing" )
@@ -387,31 +393,29 @@ report_participants <- function(data,
387
393
388
394
if (all(is.na(data [[education ]]))) {
389
395
text_education <- " "
390
- } else {
391
- if (is.numeric(data [[education ]])) {
392
- text_education <- summary(
393
- report_statistics(
394
- data [[education ]],
395
- n = FALSE ,
396
- centrality = " mean" ,
397
- missing_percentage = NULL ,
398
- digits = digits ,
399
- ...
400
- )
401
- )
402
-
403
- text_education <- sub(" Mean =" , " Mean education =" , text_education , fixed = TRUE )
404
- } else {
405
- data [which(data [[education ]] %in% c(NA , " NA" )), education ] <- " missing"
406
- txt <- summary(report_statistics(
407
- as.factor(data [[education ]]),
408
- levels_percentage = TRUE ,
396
+ } else if (is.numeric(data [[education ]])) {
397
+ text_education <- summary(
398
+ report_statistics(
399
+ data [[education ]],
400
+ n = FALSE ,
401
+ centrality = " mean" ,
402
+ missing_percentage = NULL ,
409
403
digits = digits ,
410
404
...
411
- ))
405
+ )
406
+ )
412
407
413
- text_education <- paste0(" Education: " , txt )
414
- }
408
+ text_education <- sub(" Mean =" , " Mean education =" , text_education , fixed = TRUE )
409
+ } else {
410
+ data [which(data [[education ]] %in% c(NA , " NA" )), education ] <- " missing"
411
+ txt <- summary(report_statistics(
412
+ as.factor(data [[education ]]),
413
+ levels_percentage = TRUE ,
414
+ digits = digits ,
415
+ ...
416
+ ))
417
+
418
+ text_education <- paste0(" Education: " , txt )
415
419
}
416
420
417
421
text_country <- if (all(is.na(data [[country ]]))) {
@@ -468,6 +472,7 @@ report_participants <- function(data,
468
472
text_race <- paste(" Race:" , value_string )
469
473
}
470
474
475
+ # nolint start
471
476
paste0(
472
477
size ,
473
478
" participants (" ,
@@ -491,6 +496,7 @@ report_participants <- function(data,
491
496
), text_race )),
492
497
" )"
493
498
)
499
+ # nolint end
494
500
}
495
501
496
502
# ' @keywords internal
0 commit comments