diff --git a/R/data_rename.R b/R/data_rename.R index 4810e43c7..c69f8d9bc 100644 --- a/R/data_rename.R +++ b/R/data_rename.R @@ -266,13 +266,11 @@ data_rename <- function(data, # if so, iterate all tokens for (token in matches) { # evaluate token-object from the environment - values <- tryCatch( - .dynEval(str2lang(gsub("\\{(.*)\\}", "\\1", token))), - error = function(e) { - insight::format_error(paste0( - "The object `", token, "` was not found. Please check if it really exists." - )) - } + values <- .dynEval( + str2lang(gsub("\\{(.*)\\}", "\\1", token)), + ifnotfound = insight::format_error(paste0( + "The object `", token, "` was not found. Please check if it really exists." + )) ) # check for correct length if (length(values) != length(pattern)) { diff --git a/tests/testthat/test-data_rename.R b/tests/testthat/test-data_rename.R index 50d98c0d0..79f4427b3 100644 --- a/tests/testthat/test-data_rename.R +++ b/tests/testthat/test-data_rename.R @@ -166,7 +166,7 @@ test_that("data_rename enough letters", { mtcars[1:5, ], iris[1:5, ], efc[1:5, ], ChickWeight[1:5, ], ToothGrowth[1:5, ], USArrests[1:5, ], airquality[1:5, ] ) - expect_names( + expect_named( data_rename(x, replacement = "long_letter_{letter}"), c( "long_letter_a1", "long_letter_b1", "long_letter_c1", "long_letter_d1",