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

setDT() works on S4 slots (again), and := works in under-allocated S4 slots #6703

Merged
merged 4 commits into from
Jan 6, 2025

Conversation

MichaelChirico
Copy link
Member

@MichaelChirico MichaelChirico commented Jan 2, 2025

Closes #6701 (and possibly #6575). Closes #6704.

Lumped together because of #6702 -- really this should be one small change fixing both places. After #6702 it will only be possible for a bug to affect both call sites of .is_simple_extraction().

I'm not totally clear what broke exactly -- something about the change to .shallow() broke assignment back to an S4 slot.

On a side note, I'm not totally clear this should be allowed in the first place -- it really bends S4 semantics IMO.

For example, if we try and pass a data.table to a class's slot which is declared as data.frame, S4 will coerce it to data.frame:

setClass("DataFrame", slots=c(x="data.frame"))
DF = new("DataFrame", x=data.table(a=1))
class(DF@x)
# [1] "data.frame"

Glancing at the one downstream I debugged, personally I think they should change the code:

https://github.com/HimesGroup/snpsettest/blob/38d5b86217fcd9061e3714bf911eb4ffb36ea1b3/R/harmonize_sumstats.R#L83-L88

setDT() there is having global effects perhaps unintentionally. Something like snps = as.data.table(x@snps) seems more appropriate.

Anyway, that's a thought for another day.

@MichaelChirico MichaelChirico requested a review from tdhock January 2, 2025 08:55
@MichaelChirico MichaelChirico changed the title setDT() works on S4 slots setDT() works on S4 slots (again) Jan 2, 2025
Copy link

codecov bot commented Jan 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.61%. Comparing base (70c64ac) to head (eeeb61c).
Report is 5 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6703   +/-   ##
=======================================
  Coverage   98.61%   98.61%           
=======================================
  Files          79       79           
  Lines       14553    14561    +8     
=======================================
+ Hits        14352    14360    +8     
  Misses        201      201           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MichaelChirico MichaelChirico added the non-atomic column e.g. list columns, S4 vector columns label Jan 2, 2025
Copy link

github-actions bot commented Jan 2, 2025

Comparison Plot

Generated via commit eeeb61c

Download link for the artifact containing the test results: ↓ atime-results.zip

Task Duration
R setup and installing dependencies 4 minutes and 39 seconds
Installing different package versions 7 minutes and 37 seconds
Running and plotting the test cases 2 minutes and 14 seconds

@MichaelChirico MichaelChirico changed the title setDT() works on S4 slots (again) setDT() works on S4 slots (again), and := works in under-allocated S4 slots Jan 2, 2025
@@ -3048,6 +3052,9 @@ rleidv = function(x, cols=seq_along(x), prefix=NULL) {
is.name(e[[1L]]) && is.name(e[[2L]]) # e.g. V1:V2, but not min(V1):max(V2) or 1:max(V2)
}

# for assignments like x[[1]][, a := 2] or setDT(x@DT)
.is_simple_extraction = function(e) e %iscall% c('$', '@', '[[') && is.name(e[[2L]])
Copy link
Member

Choose a reason for hiding this comment

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

great thanks for adding this helper fun

@tdhock
Copy link
Member

tdhock commented Jan 6, 2025

lgtm

but I don't really use S4 very often...

@MichaelChirico
Copy link
Member Author

but I don't really use S4 very often...

nor do i... basically relying on sandboxing, existing tests, and revdeps here.

@MichaelChirico MichaelChirico merged commit b48649a into master Jan 6, 2025
11 checks passed
@MichaelChirico MichaelChirico deleted the setdt-s4 branch January 6, 2025 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
non-atomic column e.g. list columns, S4 vector columns
Projects
None yet
Development

Successfully merging this pull request may close these issues.

:= assignment to under-allocated S4 slot fails setDT fails on S4 slots
2 participants