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

Feature/issue383 -- closes #383 #397

Merged
merged 11 commits into from Nov 12, 2015
Merged

Feature/issue383 -- closes #383 #397

merged 11 commits into from Nov 12, 2015

Conversation

@eddelbuettel
Copy link
Member

@eddelbuettel eddelbuettel commented Nov 8, 2015

this should close #383:

  • works on square and non-square integer and real matrices
  • deals with dimnames
  • will add one for strings as well, not sure I can be bothered for complex
@eddelbuettel
Copy link
Member Author

@eddelbuettel eddelbuettel commented Nov 11, 2015

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.

@jjallaire
Copy link
Member

@jjallaire jjallaire commented Nov 11, 2015

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 ...

This comment has been minimized.

@kevinushey

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?

This comment has been minimized.

@eddelbuettel

eddelbuettel Nov 11, 2015
Author Member

Nice. Anything that avoid PROTECT and UNPROTECT has my vote :)

This comment has been minimized.

@eddelbuettel

eddelbuettel Nov 12, 2015
Author Member

That's been committed.

SET_VECTOR_ELT(dimnames, 1, rnames);
// do we need dimnamesnames ?
Rf_setAttrib(r, R_DimNamesSymbol, dimnames);
UNPROTECT(1); /* dimnames */

This comment has been minimized.

@kevinushey

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)

This comment has been minimized.

@eddelbuettel

eddelbuettel Nov 11, 2015
Author Member

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)) {

This comment has been minimized.

@kevinushey

kevinushey Nov 11, 2015
Contributor

Extract this to a helper function?

This comment has been minimized.

@eddelbuettel

eddelbuettel Nov 11, 2015
Author Member

Yes, could do.

This comment has been minimized.

@eddelbuettel

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.

This comment has been minimized.

@eddelbuettel

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.

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Nov 11, 2015

This is fine as-is but made some comments that might help clean up (code duplication, Shield<SEXP>)

@eddelbuettel
Copy link
Member Author

@eddelbuettel eddelbuettel commented Nov 11, 2015

Very helpful -- thanks for he comments, Kevin. Will revise once more.

@eddelbuettel
Copy link
Member Author

@eddelbuettel eddelbuettel commented Nov 12, 2015

Bump. @kevinushey if you can take another quick look...

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Nov 12, 2015

Looks good to me!

eddelbuettel added a commit that referenced this pull request Nov 12, 2015
Feature/issue383 -- closes #383
@eddelbuettel eddelbuettel merged commit 28d099d into master Nov 12, 2015
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@eddelbuettel eddelbuettel deleted the feature/issue383 branch Nov 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.