r - Rcpp: how to set the character parameter in a function? -


i beginner of rcpp. ask basic question? following simple code:

#include <rcpp.h> using namespace rcpp;  // [[rcpp::export]] int test(char d) { char c; c=d; return 0; } 

but when try compile it, error like:

/usr/local/genomics/programs/r-3.0.0/library/rcpp/include/rcpp/as.h: in function ‘t   rcpp::internal::as_string(sexprec*, rcpp::traits::false_type) [with t = char]’: /usr/local/genomics/programs/r-3.0.0/library/rcpp/include/rcpp/as.h:66:   instantiated ‘t rcpp::internal::as(sexprec*, rcpp::traits::r_type_string_tag) [with t = char]’ /usr/local/genomics/programs/r-3.0.0/library/rcpp/include/rcpp/as.h:126:   instantiated ‘t rcpp::as(sexprec*) [with t = char]’ test1.cpp:18:   instantiated here /usr/local/genomics/programs/r-3.0.0/library/rcpp/include/rcpp/as.h:62: error: invalid conversion ‘const char*’ ‘char’ make: *** [test1.o] error 1 g++ -i/usr/local/genomics/programs/r-3.0.0/include -dndebug  -i/usr/local/include  -i"/usr/local/genomics/programs/r-3.0.0/library/rcpp/include"    -fpic  -g -o2  -c test1.cpp -o test1.o 

error in sourcecpp("test1.cpp") : error 1 occurred building shared library.

could tell me happens? thank much!

in way, bug in sense support single char objects.

in way, not matter there little useful stuff can single char. , works if either int instead

#include <rcpp.h> using namespace rcpp;  // [[rcpp::export]] int mytest(int d) {   int c;   c=d;   return 0; } 

or, better still, use string type:

#include <rcpp.h> using namespace rcpp;  // [[rcpp::export]] int mytest(std::string d) {   std::string c;   c=d;   return 0; } 

and of course work when use rcpp's own type, charactervector.

#include <rcpp.h> using namespace rcpp;  // [[rcpp::export]] int mytest(charactervector d) {   charactervector c;   c=d;   return 0; } 

single char variables bit of oddity in c , c++ (and need arrays of them, or pointers) express "words". there no real use in fixing r has vector types anyway.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -