diff --git a/DESCRIPTION b/DESCRIPTION index eeee80702..b72b9b48c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -79,3 +79,4 @@ Config/Needs/website: rstudio/bslib, r-lib/pkgdown, easystats/easystatstemplate +Remotes: easystats/insight diff --git a/R/format.R b/R/format.R index a73fbdbcf..84374fa13 100644 --- a/R/format.R +++ b/R/format.R @@ -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) } } diff --git a/tests/testthat/_snaps/describe_distribution.md b/tests/testthat/_snaps/describe_distribution.md index 28d08d954..1e9d73ebc 100644 --- a/tests/testthat/_snaps/describe_distribution.md +++ b/tests/testthat/_snaps/describe_distribution.md @@ -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 @@ -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 --- @@ -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