Skip to content

Commit

Permalink
Update standalone files + standardize snapshot tests (#1579)
Browse files Browse the repository at this point in the history
* Use recent standalone files

* Recent standalone don't accept integers

* Use regular snapshot tests. Avoid nesting `expect_error()`

* Standardize snapshot tests. and use `cnd_class = TRUE` if `expect_error()` was used.

Put cnd_class on the first line to make it easy to remove it as needed.

* tidyselect 1.2.1

* Add workaround for old R snapshot failure

* avoid snapshot for this test since it changes slightly across R versions

* remove cnd_class = TRUE

* Separate snapshot tests for errors.

* Update corresponding snapshots
  • Loading branch information
olivroy authored Oct 25, 2024
1 parent fcedd52 commit 3a9a93c
Show file tree
Hide file tree
Showing 51 changed files with 985 additions and 679 deletions.
3 changes: 2 additions & 1 deletion R/append.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ df_append <- function(x, y, after = NULL, remove = FALSE) {
after <- match(after, x_names)
}

check_number_whole(after, min = 0L, max = n, .internal = TRUE)
# r-lib/rlang#1702
check_number_whole(after, min = 0, max = as.numeric(n), .internal = TRUE)

if (remove) {
lhs <- seq2(1L, after - 1L)
Expand Down
21 changes: 16 additions & 5 deletions R/compat-lazyeval.R → R/import-standalone-lazyeval.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# nocov start - compat-lazyeval (last updated: rlang 0.3.0)

# Standalone file: do not edit by hand
# Source: https://github.com/r-lib/rlang/blob/HEAD/R/standalone-lazyeval.R
# Generated by: usethis::use_standalone("r-lib/rlang", "lazyeval")
# ----------------------------------------------------------------------
#
# ---
# repo: r-lib/rlang
# file: standalone-lazyeval.R
# last-updated: 2018-09-18
# license: https://unlicense.org
# imports: rlang
# ---
#
# This file serves as a reference for compatibility functions for lazyeval.
# Please find the most recent version in rlang's repository.

#
# nocov start

warn_underscored <- function() {
return(NULL)
Expand Down Expand Up @@ -48,7 +59,7 @@ compat_lazy <- function(lazy, env = caller_env(), warn = TRUE) {
},
list =
if (inherits(lazy, "lazy")) {
lazy <- new_quosure(lazy$expr, lazy$env)
lazy = new_quosure(lazy$expr, lazy$env)
}
)

Expand Down
45 changes: 35 additions & 10 deletions R/compat-obj-type.R → R/import-standalone-obj-type.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
# nocov start --- r-lib/rlang compat-obj-type
# Standalone file: do not edit by hand
# Source: https://github.com/r-lib/rlang/blob/HEAD/R/standalone-obj-type.R
# Generated by: usethis::use_standalone("r-lib/rlang", "obj-type")
# ----------------------------------------------------------------------
#
# Changelog
# =========
# ---
# repo: r-lib/rlang
# file: standalone-obj-type.R
# last-updated: 2024-02-14
# license: https://unlicense.org
# imports: rlang (>= 1.1.0)
# ---
#
# ## Changelog
#
# 2024-02-14:
# - `obj_type_friendly()` now works for S7 objects.
#
# 2023-05-01:
# - `obj_type_friendly()` now only displays the first class of S3 objects.
#
# 2023-03-30:
# - `stop_input_type()` now handles `I()` input literally in `arg`.
#
# 2022-10-04:
# - `obj_type_friendly(value = TRUE)` now shows numeric scalars
Expand Down Expand Up @@ -36,7 +55,8 @@
# - Added support for matrices and arrays (#141).
# - Added documentation.
# - Added changelog.

#
# nocov start

#' Return English-friendly type
#' @param x Any R object.
Expand All @@ -55,7 +75,7 @@ obj_type_friendly <- function(x, value = TRUE) {
if (inherits(x, "quosure")) {
type <- "quosure"
} else {
type <- paste(class(x), collapse = "/")
type <- class(x)[[1L]]
}
return(sprintf("a <%s> object", type))
}
Expand Down Expand Up @@ -251,19 +271,19 @@ vec_type_friendly <- function(x, length = FALSE) {
#' Return OO type
#' @param x Any R object.
#' @return One of `"bare"` (for non-OO objects), `"S3"`, `"S4"`,
#' `"R6"`, or `"R7"`.
#' `"R6"`, or `"S7"`.
#' @noRd
obj_type_oo <- function(x) {
if (!is.object(x)) {
return("bare")
}

class <- inherits(x, c("R6", "R7_object"), which = TRUE)
class <- inherits(x, c("R6", "S7_object"), which = TRUE)

if (class[[1]]) {
"R6"
} else if (class[[2]]) {
"R7"
"S7"
} else if (isS4(x)) {
"S4"
} else {
Expand All @@ -288,7 +308,7 @@ stop_input_type <- function(x,
show_value = TRUE,
arg = caller_arg(x),
call = caller_env()) {
# From compat-cli.R
# From standalone-cli.R
cli <- env_get_list(
nms = c("format_arg", "format_code"),
last = topenv(),
Expand All @@ -305,10 +325,15 @@ stop_input_type <- function(x,
if (length(what)) {
what <- oxford_comma(what)
}
if (inherits(arg, "AsIs")) {
format_arg <- identity
} else {
format_arg <- cli$format_arg
}

message <- sprintf(
"%s must be %s, not %s.",
cli$format_arg(arg),
format_arg(arg),
what,
obj_type_friendly(x, value = show_value)
)
Expand Down
Loading

0 comments on commit 3a9a93c

Please sign in to comment.