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

Retain class inheritance #62

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Retain class inheritance #62

wants to merge 3 commits into from

Conversation

chartgerink
Copy link
Member

Updates the restore_labels function to ensure "safeframe" gets added before data.frame as the relevant subclass, but does not gets prioritized over potential other internal classes.

Fixes #56. Includes the reproducible example from #56 as a test to ensure it stays fixed 😊

@chartgerink chartgerink requested a review from Bisaloo January 23, 2025 12:25
tests/testthat/test-restore_labels.R Outdated Show resolved Hide resolved
tests/testthat/test-restore_labels.R Show resolved Hide resolved
Comment on lines +62 to +64
current_classes <- class(x)
df_index <- which(current_classes == "data.frame")
class(x) <- append(current_classes, "safeframe", after = df_index - 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As shown in the proposed new test, this will come short in complex cases where the safeframe is a subclass of a data.frame (e.g., a tibble).

I think the only solution is to restore the class in the function where it's dropped (i.e., the subsetting functions) and to restore a copy of the original 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

Successfully merging this pull request may close these issues.

safeframe should retain class inheritance order when restoring class
2 participants