Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Mar 4, 2024
1 parent e91f77d commit bf758c9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions R/data_modify.R
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,14 @@ data_modify.grouped_df <- function(data, ..., .if = NULL, .at = NULL, .modify =
}

# finally, we can evaluate expression and get values for new variables
new_variable <- switch(
insight::safe_deparse(symbol),
symbol_string <- insight::safe_deparse(symbol)
if (!is.null(symbol_string) && all(symbol_string == "n()")) {
# "special" functions
"n()" = nrow(data),
new_variable <- nrow(data)
} else {
# default evaluation of expression
try(with(data, eval(symbol)), silent = TRUE)
)
}

# successful, or any errors, like misspelled variable name?
if (inherits(new_variable, "try-error")) {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-value_at.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
test_that("value_at", {
data(efc, package = "datawizard")
expect_equal(value_at(efc$e42dep, 5), 4, ignore_attr = TRUE)
expect_equal(value_at(efc$e42dep, 4), NA, ignore_attr = TRUE)
expect_equal(value_at(efc$e42dep, 4, remove_na = TRUE), 4, ignore_attr = TRUE)
expect_equal(value_at(efc$c12hour, 4), NA_real_, ignore_attr = TRUE)
expect_equal(value_at(efc$c12hour, 4, remove_na = TRUE), 168, ignore_attr = TRUE)
expect_equal(value_at(efc$c12hour, 5:7), efc$c12hour[5:7], ignore_attr = TRUE)
expect_equal(value_at(efc$e42dep, 123456, default = 55), 55, ignore_attr = TRUE)
expect_null(value_at(efc$e42dep, 123456))
Expand Down

0 comments on commit bf758c9

Please sign in to comment.