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

Dims in str for data.frame-inheriting object #494

Open
jonthegeek opened this issue Nov 12, 2024 · 0 comments
Open

Dims in str for data.frame-inheriting object #494

jonthegeek opened this issue Nov 12, 2024 · 0 comments

Comments

@jonthegeek
Copy link
Contributor

This line is causing me issues:

S7/R/class.R

Line 305 in f5b23ab

attributes(object) <- list(names = names(object), dim = dim(object))

I have a subclass of data.frame, "paths". This is the hackiest part of my package and likely to change, but the tests work before and now throw an error, so I want to report this while I see it.

When my test tries to print an object that contains a "rapid::paths" object (and thus calls str()), I get an error. You can reproduce it like this:

library(S7)
df <- data.frame(a = 1:2, b = 1:2)
# Imagine that df belongs to an S7 subclass of data.frame.
class(df) <- c("myclass", "data.frame", "S7_object")
str(df)
#> Classes 'myclass', 'S7_object' and 'data.frame': 2 obs. of  2 variables:
#> <myclass>
#> Error in attributes(object) <- list(names = names(object), dim = dim(object)): dims [product 4] do not match the length of object [2]

Created on 2024-11-12 with reprex v2.1.1

Or more directly like this:

x <- data.frame(a = 1:2, b = 1:2)
attributes(x) <- list(dim = dim(x))

I suspect I can avoid this by implementing a str method like I've been meaning to do anyway (not to mention that this object likely won't inherit from data.frame much longer), but it also seems like this is probably a bug.

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