Skip to content

Commit

Permalink
styler
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Mar 7, 2024
1 parent 31685dc commit acb33ae
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions R/data_xtabulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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?")
}

Expand Down

0 comments on commit acb33ae

Please sign in to comment.