Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Mar 4, 2024
1 parent 1c7fda8 commit 79a242b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ Config/Needs/website:
rstudio/bslib,
r-lib/pkgdown,
easystats/easystatstemplate
Remotes: easystats/insight
12 changes: 6 additions & 6 deletions R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ format.parameters_distribution <- function(x, digits = 2, format = NULL, ci_widt
ci_lvl <- attributes(x)$ci
centrality_ci <- attributes(x)$first_centrality

if (!is.null(centrality_ci)) {
ci_suffix <- paste0(" (", centrality_ci, ")")
} else {
if (is.null(centrality_ci)) {
ci_suffix <- ""
} else {
ci_suffix <- paste0(" (", centrality_ci, ")")
}

if (!is.null(ci_lvl)) {
colnames(x)[which(colnames(x) == "CI_low")] <- sprintf("%i%% CI%s", round(100 * ci_lvl), ci_suffix)
} else {
if (is.null(ci_lvl)) {
colnames(x)[which(colnames(x) == "CI_low")] <- sprintf("CI%s", ci_suffix)
} else {
colnames(x)[which(colnames(x) == "CI_low")] <- sprintf("%i%% CI%s", round(100 * ci_lvl), ci_suffix)
}
}

Expand Down
34 changes: 26 additions & 8 deletions tests/testthat/_snaps/describe_distribution.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# describe_distribution - factor

Code
describe_distribution(factor(substring("statistics", 1:10, 1:10)))
Output
Mean | SD | Range | Skewness | Kurtosis | n | n_Missing
---------------------------------------------------------
| | [a, t] | -0.77 | -0.13 | 10 | 0

# describe_distribution - character

Code
describe_distribution(as.character(ToothGrowth$supp))
Output
Mean | SD | Range | Skewness | Kurtosis | n | n_Missing
-----------------------------------------------------------
| | [VC, OJ] | 0 | -2.07 | 60 | 0

# describe_distribution formatting

Code
Expand All @@ -14,10 +32,10 @@
Output
Variable | Mean | SD | IQR | 90% CI | Range | Skewness | Kurtosis | n | n_Missing
---------------------------------------------------------------------------------------------------------------
mpg | 20.09 | 6.03 | 7.53 | [ 18.70, 21.61] | [10.40, 33.90] | 0.67 | -0.02 | 32 | 0
cyl | 6.19 | 1.79 | 4.00 | [ 5.69, 6.62] | [ 4.00, 8.00] | -0.19 | -1.76 | 32 | 0
disp | 230.72 | 123.94 | 221.53 | [194.91, 269.80] | [71.10, 472.00] | 0.42 | -1.07 | 32 | 0
hp | 146.69 | 68.56 | 84.50 | [128.62, 168.03] | [52.00, 335.00] | 0.80 | 0.28 | 32 | 0
mpg | 20.09 | 6.03 | 7.53 | [ 18.52, 21.40] | [10.40, 33.90] | 0.67 | -0.02 | 32 | 0
cyl | 6.19 | 1.79 | 4.00 | [ 5.75, 6.62] | [ 4.00, 8.00] | -0.19 | -1.76 | 32 | 0
disp | 230.72 | 123.94 | 221.53 | [195.47, 257.75] | [71.10, 472.00] | 0.42 | -1.07 | 32 | 0
hp | 146.69 | 68.56 | 84.50 | [127.28, 168.31] | [52.00, 335.00] | 0.80 | 0.28 | 32 | 0

---

Expand All @@ -26,8 +44,8 @@
Output
Variable | Trimmed (10%) | SD | IQR | 90% CI | Range | Skewness | Kurtosis | n | n_Missing
----------------------------------------------------------------------------------------------------------------------
mpg | 19.70 | 6.03 | 7.53 | [ 18.25, 21.47] | [10.40, 33.90] | 0.67 | -0.02 | 32 | 0
cyl | 6.23 | 1.79 | 4.00 | [ 5.68, 6.92] | [ 4.00, 8.00] | -0.19 | -1.76 | 32 | 0
disp | 222.52 | 123.94 | 221.53 | [193.15, 266.02] | [71.10, 472.00] | 0.42 | -1.07 | 32 | 0
hp | 141.19 | 68.56 | 84.50 | [121.71, 162.27] | [52.00, 335.00] | 0.80 | 0.28 | 32 | 0
mpg | 19.70 | 6.03 | 7.53 | [ 17.92, 21.35] | [10.40, 33.90] | 0.67 | -0.02 | 32 | 0
cyl | 6.23 | 1.79 | 4.00 | [ 5.61, 6.77] | [ 4.00, 8.00] | -0.19 | -1.76 | 32 | 0
disp | 222.52 | 123.94 | 221.53 | [181.61, 258.52] | [71.10, 472.00] | 0.42 | -1.07 | 32 | 0
hp | 141.19 | 68.56 | 84.50 | [125.27, 160.73] | [52.00, 335.00] | 0.80 | 0.28 | 32 | 0

0 comments on commit 79a242b

Please sign in to comment.