Skip to content

Commit bf636ee

Browse files
authored
Rename group/group_by arguments into by (#433)
* Rename `group`/`group_by` arguments into `by` * fix report_participants * fix news * use insight remotes * deprecation warning * lintr * ... * fix * update tests * fix * fix * fix * update snapshots * update readme * add remotes
1 parent 201e979 commit bf636ee

14 files changed

+205
-167
lines changed

DESCRIPTION

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: report
22
Type: Package
33
Title: Automated Reporting of Results and Statistical Models
4-
Version: 0.5.8.2
4+
Version: 0.5.8.3
55
Authors@R:
66
c(person(given = "Dominique",
77
family = "Makowski",
@@ -150,3 +150,4 @@ Collate:
150150
'utils_grouped_df.R'
151151
'zzz.R'
152152
Roxygen: list(markdown = TRUE)
153+
Remotes: easystats/insight, easystats/datawizard, easystats/parameters, easystats/performance, easystats/modelbased

NEWS.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# report 0.5.9
22

3+
Breaking
4+
5+
* Arguments named `group`, `at` and `group_by` will be deprecated in future
6+
releases. of _easystats_ packages. Please use `by` instead. This affects
7+
following functions in *report*:
8+
9+
* `report_participants()`
10+
* `report_sample()`
11+
312
Minor changes
413

514
* `report` now supports reporting of Bayesian model comparison with variables of class `brms::loo_compare`.

R/report.lm.R

+8-8
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ report_info.lm <- function(x,
483483
effectsize <- report_effectsize(x, ...)
484484
}
485485

486-
text <- .info_effectsize(x, effectsize = effectsize, include_effectsize = include_effectsize)
486+
info_text <- .info_effectsize(x, effectsize = effectsize, include_effectsize = include_effectsize)
487487

488488
if (is.null(parameters)) {
489489
parameters <- report_parameters(x, ...)
@@ -495,7 +495,7 @@ report_info.lm <- function(x,
495495
}
496496

497497
if ("ci_method" %in% names(att)) {
498-
text <- paste0(text, " ", .info_df(
498+
info_text <- paste0(info_text, " ", .info_df(
499499
ci = att$ci,
500500
ci_method = att$ci_method,
501501
test_statistic = att$test_statistic,
@@ -508,7 +508,7 @@ report_info.lm <- function(x,
508508
# }
509509

510510

511-
as.report_info(text)
511+
as.report_info(info_text)
512512
}
513513

514514

@@ -538,25 +538,25 @@ report_text.lm <- function(x, table = NULL, ...) {
538538
model,
539539
". ",
540540
perf,
541-
ifelse(nchar(perf) > 0, ". ", ""),
541+
ifelse(nzchar(perf, keepNA = TRUE), ". ", ""),
542542
intercept,
543543
params_text_full,
544544
"\n\n",
545545
info
546546
)
547547

548-
text <- paste0(
548+
summary_text <- paste0(
549549
"We fitted a ",
550550
summary(model),
551551
". ",
552552
summary(perf),
553-
ifelse(nchar(perf) > 0, ". ", ""),
553+
ifelse(nzchar(perf, keepNA = TRUE), ". ", ""),
554554
summary(intercept),
555555
params_text
556556
)
557557

558558

559-
as.report_text(text_full, summary = text)
559+
as.report_text(text_full, summary = summary_text)
560560
}
561561

562562

@@ -569,7 +569,7 @@ report_text.lm <- function(x, table = NULL, ...) {
569569
if (!is.null(coefname) && coefname %in% names(table)) {
570570
estimate <- attributes(table)$coefficient_name
571571
} else {
572-
estimate <- datawizard::data_find(table, candidates, regex = TRUE, verbose = FALSE)[1]
572+
estimate <- datawizard::extract_column_names(table, candidates, regex = TRUE, verbose = FALSE)[1]
573573
}
574574
estimate
575575
}

R/report_htest_ttest.R

+9-9
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,25 @@
3333

3434
.report_table_ttest <- function(table_full, effsize) {
3535
table_full <- cbind(table_full, attributes(effsize)$table)
36-
table <- datawizard::data_remove(
36+
table_small <- datawizard::data_remove(
3737
table_full,
3838
c("Parameter", "Group", "Mean_Group1", "Mean_Group2", "Method", "d_CI_low", "d_CI_high")
3939
)
40-
list(table = table, table_full = table_full)
40+
list(table = table_small, table_full = table_full)
4141
}
4242

4343

4444
# report_effectsize ---------------------
4545

4646
.report_effectsize_ttest <- function(x, table, dot_args, type, rules = "cohen1988") {
47-
args <- c(list(x), dot_args)
48-
table <- do.call(effectsize::effectsize, args)
47+
my_args <- c(list(x), dot_args)
48+
table <- do.call(effectsize::effectsize, my_args)
4949
ci <- attributes(table)$ci
5050
estimate <- names(table)[1]
5151
rules <- ifelse(is.null(dot_args$rules), rules, dot_args$rules)
5252

53-
args <- list(table, rules = rules, dot_args)
54-
interpretation <- do.call(effectsize::interpret, args)$Interpretation
53+
my_args <- list(table, rules = rules, dot_args)
54+
interpretation <- do.call(effectsize::interpret, my_args)$Interpretation
5555
rules <- .text_effectsize(attr(attr(interpretation, "rules"), "rule_name"))
5656

5757
if (estimate %in% c("d", "Cohens_d")) {
@@ -88,7 +88,7 @@
8888
.report_model_ttest <- function(x, table) {
8989
# If against mu
9090
if (names(x$null.value) == "mean") {
91-
# TODO: @DominiqueMakowski why do we need "table" here?
91+
# TODO: @DominiqueMakowski why do we need "table" here??
9292

9393
table$Difference <- x$estimate - x$null.value
9494
means <- paste0(" (mean = ", insight::format_value(x$estimate), ")")
@@ -106,12 +106,12 @@
106106
vars <- paste0(x$data.name)
107107
}
108108

109-
text <- paste0(
109+
final_text <- paste0(
110110
trimws(x$method),
111111
" testing the difference ",
112112
ifelse(grepl(" by ", x$data.name, fixed = TRUE), "of ", "between "),
113113
vars_full
114114
)
115115

116-
text
116+
final_text
117117
}

R/report_participants.R

+46-40
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
#' so countries that represent less than 10% will be combined in the "other" category).
2222
#' @param participants The name of the participants' identifier column (for
2323
#' 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
2525
#' for stratified description.
2626
#' @param spell_n Logical, fully spell the sample size (`"Three participants"`
2727
#' instead of `"3 participants"`).
2828
#' @inheritParams report.numeric
29+
#' @param group Deprecated. Use `by` instead.
2930
#'
3031
#' @return A character vector with description of the "participants", based on
3132
#' the information provided in `data`.
@@ -106,7 +107,7 @@
106107
#' sex = "Sex",
107108
#' gender = "Gender",
108109
#' participants = "Participant",
109-
#' group = "Condition"
110+
#' by = "Condition"
110111
#' )
111112
#'
112113
#' # Spell sample size
@@ -123,14 +124,21 @@ report_participants <- function(data,
123124
country = NULL,
124125
race = NULL,
125126
participants = NULL,
126-
group = NULL,
127+
by = NULL,
127128
spell_n = FALSE,
128129
digits = 1,
129130
threshold = 10,
131+
group = NULL,
130132
...) {
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+
131139
# Convert empty strings to NA
132140
data_list <- lapply(data, function(x) {
133-
x[which(x == "")] <- NA
141+
x[which(x == "")] <- NA # nolint
134142
x
135143
})
136144
data <- as.data.frame(data_list, stringsAsFactors = FALSE)
@@ -165,8 +173,8 @@ report_participants <- function(data,
165173
race <- .find_race_in_data(data)
166174
}
167175

168-
if (is.null(group)) {
169-
text <- .report_participants(
176+
if (is.null(by)) {
177+
final_text <- .report_participants(
170178
data,
171179
age = age,
172180
sex = sex,
@@ -181,9 +189,9 @@ report_participants <- function(data,
181189
...
182190
)
183191
} 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])) {
187195
current_text <- .report_participants(
188196
i,
189197
age = age,
@@ -200,15 +208,15 @@ report_participants <- function(data,
200208

201209
pre_text <- paste0(
202210
"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 "),
204212
"' group: "
205213
)
206214

207-
text <- c(text, paste0(pre_text, current_text))
215+
final_text <- c(final_text, paste0(pre_text, current_text))
208216
}
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 "))
210218
}
211-
text
219+
final_text
212220
}
213221

214222
#' @keywords internal
@@ -338,9 +346,7 @@ report_participants <- function(data,
338346
) %in% c("male", "m", "female", "f", NA, "na")]) /
339347
nrow(data) * 100, digits = digits),
340348
"% 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
344350
paste0(", ", insight::format_value(length(data[[sex]][tolower(
345351
data[[sex]]
346352
) %in% c(NA, "na")]) / nrow(data) * 100), "% missing")
@@ -375,9 +381,9 @@ report_participants <- function(data,
375381
data[[gender]]
376382
) %in% both_genders]) /
377383
nrow(data) * 100), "% non-binary",
378-
if (!insight::format_value(length(data[[gender]][tolower(
384+
if (insight::format_value(length(data[[gender]][tolower(
379385
data[[gender]]
380-
) %in% c(NA, "na")]) / nrow(data) * 100) == "0.00") {
386+
) %in% c(NA, "na")]) / nrow(data) * 100) != "0.00") {
381387
paste0(", ", insight::format_value(length(data[[gender]][tolower(
382388
data[[gender]]
383389
) %in% c(NA, "na")]) / nrow(data) * 100), "% missing")
@@ -387,31 +393,29 @@ report_participants <- function(data,
387393

388394
if (all(is.na(data[[education]]))) {
389395
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,
409403
digits = digits,
410404
...
411-
))
405+
)
406+
)
412407

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)
415419
}
416420

417421
text_country <- if (all(is.na(data[[country]]))) {
@@ -468,6 +472,7 @@ report_participants <- function(data,
468472
text_race <- paste("Race:", value_string)
469473
}
470474

475+
# nolint start
471476
paste0(
472477
size,
473478
" participants (",
@@ -491,6 +496,7 @@ report_participants <- function(data,
491496
), text_race)),
492497
")"
493498
)
499+
# nolint end
494500
}
495501

496502
#' @keywords internal

0 commit comments

Comments
 (0)