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

Character vector can not be created with 'char' #343

Closed
fplazaonate opened this issue Aug 15, 2015 · 2 comments
Closed

Character vector can not be created with 'char' #343

fplazaonate opened this issue Aug 15, 2015 · 2 comments

Comments

@fplazaonate
Copy link
Contributor

It seems to me that CharacterVector and StringVector have the same behaviour. (correct me if I am wrong)
It is OK because as far as I know R treats single chars as strings.

However, creating a CharacterVector from char produce wrong results in Rcpp
Here is an example:

#include <Rcpp.h>
using namespace Rcpp;


// [[Rcpp::export]]
NumericMatrix test_character_vector()
{
  NumericMatrix m(3,3);
  rownames(m) = CharacterVector::create('a','b','c');
  return m;
}


/*** R
m1=matrix(nrow = 3,ncol=3)
rownames(m1)=c('a','b','c')
rownames(m1) #OK

m2=test_character_vector()
rownames(m2) # WRONG
*/

Result

> m1=matrix(nrow = 3,ncol=3)

> rownames(m1)=c('a','b','c')

> rownames(m1) #OK
[1] "a" "b" "c"

> m2=test_character_vector()

> rownames(m2) # WRONG
[1] "abc" "bc"  "c"  
@fplazaonate
Copy link
Contributor Author

This is fixed by this commit bbe2bbe

@eddelbuettel
Copy link
Member

Patch looks good per se but I am a little fearful about side effects. Then again it is inside Rcpp::internal. Any thoughts @kevinushey @jjallaire ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants