Skip to content

check_data() fails with long expressions because check_dim() does not accept character vectors for x_name #300

Description

@StefanoMezzini
check_data(data.frame(fac = factor(c("a", "b", "z"), levels = c("a", "z", "b"))),
                      list(fac = factor(c("a", "b", "z"), levels = c("a", "z", "b"))))

gives the error

Error in `check_dim()` at chk/R/check-data.R:41:3:
! `x_name` must be a string (non-missing character scalar).
Run `rlang::last_trace()` to see where the error occurred.

because backtick_chk(deparse(substitute(x)))  returns the character vector of length 2

[1] "`data.frame(fac = factor(c(\"a\", \"b\", \"z\"), levels = c(\"a\", \"z\", `"
[2] "`    \"b\")))`"`

Despite this bug being a likely uncommon edge case, I think the bug is worth fixing because the error is quite uninterpretable without debugging.

We could:

  • only use first string (and append "..." to the end of it?)
  • collapse the elements with p0(..., collapse = "")
  • indenting of the second element can probably be dropped, since the first line ends with a space, but this may not always be the case

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions