R Under development (unstable) (2024-10-14 r87233 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(qwraps2) > > # basic formatting > g_mean <- exp(mean(log(mtcars$mpg))) > g_var <- exp( var(log(mtcars$mpg)) * (nrow(mtcars) - 1) / nrow(mtcars)) > g_sd <- exp(sqrt( var(log(mtcars$mpg)) * (nrow(mtcars) - 1) / nrow(mtcars))) > > stopifnot(identical(gmean(mtcars$mpg), g_mean)) > stopifnot(identical(gvar(mtcars$mpg), g_var)) > stopifnot(identical(gsd(mtcars$mpg), g_sd)) > > g_mean <- frmt(g_mean) > g_sd <- frmt(g_sd) > stopifnot(identical(gmean_sd(mtcars$mpg), paste(g_mean, "$\\pm$", g_sd))) > > # error given if show_n is not as expected > stopifnot(inherits(tryCatch(gmean_sd(mtcars$mpg, show_n = TRUE), error = function(e) e), "error")) > > > # warning if na.rm is used > stopifnot(inherits(tryCatch(gmean_sd(mtcars$mpg, na.rm = TRUE), warning = function(w) w), "warning")) > > # warning if na_rm is provided along with na.rm > stopifnot(inherits(tryCatch(gmean_sd(mtcars$mpg, na_rm = TRUE, na.rm = TRUE), warning = function(w) w), "warning")) > > > proc.time() user system elapsed 0.29 0.01 0.31