Conversation
There was a problem hiding this comment.
Pull request overview
This PR replaces the use of the deprecated ATTRIB() macro with the new R_mapAttrib() API introduced in R 4.6.0. The ATTRIB() macro is being removed in R 4.6.0 as announced on the r-devel mailing list, requiring this update for forward compatibility.
Key Changes:
- Introduced two new helper callback functions (
get_attr_namesandget_row_count) that work withR_mapAttrib()to iterate over attributes - Updated attribute-related methods to use version-conditional compilation, maintaining backward compatibility with R < 4.6.0
- Replaced direct attribute list traversal with the new opaque attribute handling approach
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utilities.cpp | New file containing helper callback functions get_attr_names and get_row_count for use with R_mapAttrib() |
| src/rcpp_init.cpp | Registers the two new helper functions to make them callable via the R API |
| inst/include/Rcpp/routines.h | Adds function declarations and inline wrappers for the new helper functions |
| inst/include/Rcpp/proxy/AttributeProxy.h | Updates attributeNames() and hasAttribute() methods to use R_mapAttrib() for R >= 4.6.0 while preserving old implementation for earlier versions |
| inst/include/Rcpp/DataFrame.h | Rewrites nrow() method to use R_mapAttrib() instead of direct ATTRIB access, with version-conditional compilation |
| DESCRIPTION | Updates version number and date |
| ChangeLog | Documents all changes made in this PR |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Enchufa2
left a comment
There was a problem hiding this comment.
I would simplify nrow and hasAttribute as suggested above. attributeNames is the only one that requires R_mapAttrib, but it may be further simplified if Luke adds R_getAttribNames, so I would just inline an anonymous visitor there for now, instead of creating another routine, another compilation unit...
|
On the |
This would be very convenient for us.
Since |
|
Oh, you meant that, from now on, pairlists and language objects would return a new attribute |
|
All good. I mostly wanted to see if I could get away from ATTRIB now as we have the next upload coming up. We can likely simplify further. Too bad I didn't 'click' on the already possible simpler |
|
The thought of going the column length for a simpler Shield<SEXP> rn = Rf_getAttrib(Parent::get__(), R_RowNamesSymbol);
return Rf_length(rn);which stays closer to R itself at the cost of the one allocation in On the other hand rewriting what @ltierney suggested as follows (with a second SEXP x = Parent::get__();
// We can simplify: zero row DFs have no names, else length of all vector same
// by design constraint so can use vector length for desired row count
return (XLENGTH(x) == 0) ? 0 : XLENGTH(VECTOR_ELT(x, 0))All those variants pass our 1600+ tests (of which several dozen hit data.frame objects). |
Unfortunately my comment is wrong: you can have a data frame with zero columns and non-zero rows: So for now going with |
|
Thanks so much for checking. The other two-liner relying on I am about to commit the re-done attribute proxy using two lambda visitors too. I still think copilot is wrong and that |
|
Those were really helpful by all -- big thanks to you all: @ltierney @Enchufa2 @JanMarvin ! |
Closes #1429
As detailed by @ltierney in a post to the r-devel list two days ago, and as tracked in issue #1429,
ATTRIB()may go away for the R 4.6.0 cycle. We use it in three spots, and this PR replaces the use by employing the (brand-new, had to re-build the 'r-devel' container we use here in CI as its last build on Monday did not reflect it yet)R_mapAttrib()which treats attributes as an opaque object and 'walks' a user-supplied function over it.Checklist
R CMD checkstill passes all tests