Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork219
Add assignment operator to DimNameProxy#339
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
eddelbuettel commentedAug 14, 2015
This looks pretty straightforward -- in favour. Any seconds? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
It looks like you already retrieved this above withSEXP dim = Rf_getAttrib(data_, R_DimSymbol) -- is this line superfluous?
EDIT: I see now the interface is mostly copied from the otheroperator=; I guess that's a similar oversight in the previous implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
And while you're there, now thatstop does theprintf thing, the wholestd::stringstream can be replaced.
kevinushey commentedAug 14, 2015
I agree this is a good change; it would probably be best to refactor the code into its own function (which both |
fplazaonate commentedAug 14, 2015
I made the change you asked. |
eddelbuettel commentedAug 14, 2015
Looks good to me. |
fplazaonate commentedAug 14, 2015
#include<Rcpp.h>usingnamespaceRcpp;// [[Rcpp::export]]voidtest_mat(){constint num_rows =2;constint num_cols =2; NumericMatrixm1(num_rows, num_cols); NumericMatrixm2(num_rows, num_cols);rownames(m1)=CharacterVector::create("a","b");rownames(m1)=rownames(m2);}/*** Rtest_mat()*/ Result I think this code should not produce an error as it works in R. What do you think? |
kevinushey commentedAug 14, 2015
I agree that the code shouldn't produce an error; in fact, it looks like in current Rcpp we just get the wrong result: #include<Rcpp.h>usingnamespaceRcpp;// [[Rcpp::export]]NumericMatrixtest_mat(){constint num_rows =2;constint num_cols =2; NumericMatrixm1(num_rows, num_cols); NumericMatrixm2(num_rows, num_cols);rownames(m1)=CharacterVector::create("a","b");rownames(m1)=rownames(m2);return m1;}/*** Rtest_mat()*/ gives >Rcpp::sourceCpp('~/test.cpp')> test_mat() [,1] [,2]a00b00 It looks to me like the second Thanks for working on this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This does the trick
if (Rf_length(other) !=0 && INTEGER(dims)[dim_] != Rf_length(other))
but it looks a bit dirty.
fplazaonate commentedAug 14, 2015
The last commit fixes the following cases: #include<Rcpp.h>usingnamespaceRcpp;// [[Rcpp::export]]NumericMatrixtest_mat2(){constint num_rows =2;constint num_cols =2; NumericMatrixm1(num_rows, num_cols);rownames(m1)=CharacterVector::create('a','b');rownames(m1)=CharacterVector::create();return m1;}// [[Rcpp::export]]NumericMatrixtest_mat(){constint num_rows =2;constint num_cols =2; NumericMatrixm1(num_rows, num_cols); NumericMatrixm2(num_rows, num_cols);rownames(m1)=CharacterVector::create("a","b");rownames(m1)=rownames(m2);return m1;}/*** Rtest_mat()test_mat2()*/ It is ok to do so in R |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We should check thatdims is non-null here, e.g.if (dims != R_NilValue && ...)
kevinushey commentedAug 14, 2015
Thanks! I have one more nitpick re: a null check and then I think it's ready for merge. |
fplazaonate commentedAug 14, 2015
I am not sure it can happen because a DimNameProxy object is currently created only from a Matrix. |
kevinushey commentedAug 14, 2015
Good point -- okay, then I think this is good to go.@eddelbuettel, any other comments? |
eddelbuettel commentedAug 14, 2015
Yup, let's fold this in. |
Add assignment operator to DimNameProxy
Before:
After:
After: