Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bare type predicates: explicitly call out matrices&arrays in docs (as well as names & other attributes?) #1775

Open
brookslogan opened this issue Feb 4, 2025 · 0 comments

Comments

@brookslogan
Copy link

brookslogan commented Feb 4, 2025

The current documentation for the bare type predicates includes:

#' These predicates check for a given type but only return `TRUE` for
#' bare R objects. Bare objects have no class attributes. For example,
#' a data frame is a list, but not a bare list.

Aside from what appears to be a minor typo ("attributes"), this appears to be technically accurate, but likely surprising to many in the case of matrices and arrays:

mat <- matrix(1:6, 2, 3)
ray <- array(1:12, c(2, 2, 3))
rlang::is_bare_numeric(mat)
#> [1] TRUE
rlang::is_bare_numeric(ray)
#> [1] TRUE
names(attributes(mat))
#> [1] "dim"
names(attributes(ray))
#> [1] "dim"
class(mat)
#> [1] "matrix" "array"
class(ray)
#> [1] "array"

Created on 2025-02-04 with reprex v2.1.1

It would be helpful to mention this case in the documentation. It may also help to explicitly mention that other attributes may still be present. E.g., maybe something like:

#' These predicates check for a given type but only return `TRUE` for
#' bare R objects. Bare objects have no class attribute. For example,
#' a data frame is a list, but not a bare list. Bare objects include matrices
#' and arrays unless they have been assigned a non-`"matrix"`, non-`"array"`
#' class. They can also have non-class attributes such as names.

though it's a bit wordy. Or maybe something like

#' Bare objects include many matrices and arrays; see [`class`]."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant