From acb33aef4da0a94c007a052d8709e089288c99e0 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 7 Mar 2024 13:08:01 +0100 Subject: [PATCH] styler --- R/data_xtabulate.R | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/R/data_xtabulate.R b/R/data_xtabulate.R index e2b746efe..f355ef8bb 100644 --- a/R/data_xtabulate.R +++ b/R/data_xtabulate.R @@ -349,24 +349,24 @@ print_html.dw_data_xtabulates <- function(x, big_mark = NULL, ...) { # do we have any value for weights_expression? if (!is.null(weights_expression) && - # due to deparse() and substitute, NULL becomes "NULL" - we need to check for this - !identical(weights_expression, "NULL") && - # we should only run into this problem, when a variable from a data frame - # is used in the data_tabulate() method for vectors - thus, we need to check - # whether the weights_expression contains a "$" - `iris$not_found` is "NULL" - # we need this check, because the default-method of data_tabulate() is called - # from the data.frame method, where `weights = weights`, and then, - # deparse(substitute(weights)) is "weights" (not "NULL" or "iris$not_found"), - # leading to an error when it's actually not (if "weights" is NULL) - # Example: - #> efc$weights <- abs(rnorm(n = nrow(efc), mean = 1, sd = 0.5)) - # Here, efc$wweight is NULL - #> data_tabulate(efc$c172code, weights = efc$wweight) - # Here, wweight errors anyway, because object "wweight" is not found - #> data_tabulate(efc$c172code, weights = wweight) - grepl("$", weights_expression, fixed = TRUE) && - # if all the above apply, weights must be NULL - only error in this case - is.null(weights)) { + # due to deparse() and substitute, NULL becomes "NULL" - we need to check for this + !identical(weights_expression, "NULL") && + # we should only run into this problem, when a variable from a data frame + # is used in the data_tabulate() method for vectors - thus, we need to check + # whether the weights_expression contains a "$" - `iris$not_found` is "NULL" + # we need this check, because the default-method of data_tabulate() is called + # from the data.frame method, where `weights = weights`, and then, + # deparse(substitute(weights)) is "weights" (not "NULL" or "iris$not_found"), + # leading to an error when it's actually not (if "weights" is NULL) + # Example: + #> efc$weights <- abs(rnorm(n = nrow(efc), mean = 1, sd = 0.5)) + # Here, efc$wweight is NULL + #> data_tabulate(efc$c172code, weights = efc$wweight) + # Here, wweight errors anyway, because object "wweight" is not found + #> data_tabulate(efc$c172code, weights = wweight) + grepl("$", weights_expression, fixed = TRUE) && + # if all the above apply, weights must be NULL - only error in this case + is.null(weights)) { insight::format_error("The variable specified in `weights` was not found. Possibly misspelled?") }