Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upFeature/issue383 -- closes #383 #397
Conversation
|
Bump to @jjallaire @kevinushey -- please take a look when time permits. This is an addition of three free functions (along with tests), and changes no interface. |
|
LGTM however I don't know enough about the internals to fully provide the green light. @kevinushey ? |
| s[i] = x[j]; | ||
| } | ||
|
|
||
| // there must be a simpler, more C++-ish way for this ... |
kevinushey
Nov 11, 2015
Contributor
You could do something like this:
SEXP oldDimNames = Rf_getAttrib(x, R_DimNamesSymbol);
if (!Rf_isNull(oldDimNames)) {
Shield<SEXP> newDimNames(Rf_allocVector(VECSXP, 2));
SET_VECTOR_ELT(newDimNames, 0, VECTOR_ELT(oldDimNames, 1));
SET_VECTOR_ELT(newDimNames, 1, VECTOR_ELT(oldDimNames, 0));
Rf_setAttrib(r, R_DimNamesSymbol, newDimNames);
}
Marginally cleaner?
You could do something like this:
SEXP oldDimNames = Rf_getAttrib(x, R_DimNamesSymbol);
if (!Rf_isNull(oldDimNames)) {
Shield<SEXP> newDimNames(Rf_allocVector(VECSXP, 2));
SET_VECTOR_ELT(newDimNames, 0, VECTOR_ELT(oldDimNames, 1));
SET_VECTOR_ELT(newDimNames, 1, VECTOR_ELT(oldDimNames, 0));
Rf_setAttrib(r, R_DimNamesSymbol, newDimNames);
}
Marginally cleaner?
eddelbuettel
Nov 11, 2015
Author
Member
Nice. Anything that avoid PROTECT and UNPROTECT has my vote :)
Nice. Anything that avoid PROTECT and UNPROTECT has my vote :)
eddelbuettel
Nov 12, 2015
Author
Member
That's been committed.
That's been committed.
| SET_VECTOR_ELT(dimnames, 1, rnames); | ||
| // do we need dimnamesnames ? | ||
| Rf_setAttrib(r, R_DimNamesSymbol, dimnames); | ||
| UNPROTECT(1); /* dimnames */ |
kevinushey
Nov 11, 2015
Contributor
Should use Shield<SEXP>(Rf_allocVector(VECSXP, 2)) to ensure that destructors automatically take care of reference counting (don't need to worry about UNPROTECT)
Should use Shield<SEXP>(Rf_allocVector(VECSXP, 2)) to ensure that destructors automatically take care of reference counting (don't need to worry about UNPROTECT)
eddelbuettel
Nov 11, 2015
Author
Member
Yes, as just noted above -- very nice.
Yes, as just noted above -- very nice.
| // there must be a simpler, more C++-ish way for this ... | ||
| SEXP rnames = internal::DimNameProxy(x, 0); | ||
| SEXP cnames = internal::DimNameProxy(x, 1); | ||
| if (!Rf_isNull(rnames) || !Rf_isNull(cnames)) { |
kevinushey
Nov 11, 2015
Contributor
Extract this to a helper function?
Extract this to a helper function?
eddelbuettel
Nov 11, 2015
Author
Member
Yes, could do.
Yes, could do.
eddelbuettel
Nov 12, 2015
Author
Member
On second look, maybe not so obvious. The typedef are local; could do old-school via a macros but then with just three deployments... it seems fine as is.
On second look, maybe not so obvious. The typedef are local; could do old-school via a macros but then with just three deployments... it seems fine as is.
eddelbuettel
Nov 12, 2015
Author
Member
On third look, I think I have it worked out -- see ea52d60 and give it another look.
Should be merge-ready now.
On third look, I think I have it worked out -- see ea52d60 and give it another look.
Should be merge-ready now.
|
This is fine as-is but made some comments that might help clean up (code duplication, |
|
Very helpful -- thanks for he comments, Kevin. Will revise once more. |
|
Bump. @kevinushey if you can take another quick look... |
|
Looks good to me! |
Feature/issue383 -- closes #383
this should close #383:
dimnames