diff --git a/R/validate_inputs.R b/R/validate_inputs.R index c146dc04c6..8a5adc2cc1 100644 --- a/R/validate_inputs.R +++ b/R/validate_inputs.R @@ -58,12 +58,12 @@ #' # set up input validation #' iv <- InputValidator$new() #' iv$add_rule("letter", sv_in_set(LETTERS, "choose a capital letter")) -#' iv$add_rule("number", ~ if (as.integer(.) %% 2L == 1L) "choose an even number") +#' iv$add_rule("number", ~ if (as.integer(.data$.) %% 2L == 1L) "choose an even number") #' iv$enable() #' # more input validation #' iv_par <- InputValidator$new() #' iv_par$add_rule("color", sv_required(message = "choose a color")) -#' iv_par$add_rule("color", ~ if (length(.) > 1L) "choose only one color") +#' iv_par$add_rule("color", ~ if (length(.data$.) > 1L) "choose only one color") #' iv_par$add_rule( #' "size", #' sv_between( @@ -87,7 +87,7 @@ #' )) #' ) #' -#' plot(eruptions ~ waiting, faithful, +#' plot(.data$eruptions ~ .data$waiting, faithful, #' las = 1, pch = 16, #' col = input[["color"]], cex = input[["size"]] #' ) diff --git a/man/validate_inputs.Rd b/man/validate_inputs.Rd index 50ae876d0e..159f7b62b7 100644 --- a/man/validate_inputs.Rd +++ b/man/validate_inputs.Rd @@ -66,12 +66,12 @@ server <- function(input, output) { # set up input validation iv <- InputValidator$new() iv$add_rule("letter", sv_in_set(LETTERS, "choose a capital letter")) - iv$add_rule("number", ~ if (as.integer(.) \%\% 2L == 1L) "choose an even number") + iv$add_rule("number", ~ if (as.integer(.data$.) \%\% 2L == 1L) "choose an even number") iv$enable() # more input validation iv_par <- InputValidator$new() iv_par$add_rule("color", sv_required(message = "choose a color")) - iv_par$add_rule("color", ~ if (length(.) > 1L) "choose only one color") + iv_par$add_rule("color", ~ if (length(.data$.) > 1L) "choose only one color") iv_par$add_rule( "size", sv_between( @@ -95,7 +95,7 @@ server <- function(input, output) { )) ) - plot(eruptions ~ waiting, faithful, + plot(.data$eruptions ~ .data$waiting, faithful, las = 1, pch = 16, col = input[["color"]], cex = input[["size"]] ) diff --git a/tests/testthat/setup-options.R b/tests/testthat/setup-options.R new file mode 100644 index 0000000000..78be1f9b5f --- /dev/null +++ b/tests/testthat/setup-options.R @@ -0,0 +1,20 @@ +# `opts_partial_match_old` is left for exclusions due to partial matching in dependent packages (i.e. not fixable here) +# it might happen that it is not used right now, but it is left for possible future use +# use with: `withr::with_options(opts_partial_match_old, { ... })` inside the test +opts_partial_match_old <- list( + warnPartialMatchDollar = getOption("warnPartialMatchDollar"), + warnPartialMatchArgs = getOption("warnPartialMatchArgs"), + warnPartialMatchAttr = getOption("warnPartialMatchAttr") +) +opts_partial_match_new <- list( + warnPartialMatchDollar = TRUE, + warnPartialMatchArgs = TRUE, + warnPartialMatchAttr = TRUE +) + +if (isFALSE(getFromNamespace("on_cran", "testthat")()) && requireNamespace("withr", quietly = TRUE)) { + withr::local_options( + opts_partial_match_new, + .local_envir = testthat::teardown_env() + ) +}