[Rcpp-devel] convert to unsigned char* variable
Romain Francois
romain at r-enthusiasts.com
Mon Oct 20 23:09:56 CEST 2014
> Le 20 oct. 2014 à 21:54, Dirk Eddelbuettel <edd at debian.org> a écrit :
>
>
> Hi Gustaf,
>
> On 20 October 2014 at 15:17, Gustaf Granath wrote:
> | Im trying to use some C++ functions in R. However, these functions are
> | build around unsigned char* variables (1D array). I have for example a
> | large matrix in R that represents black (e.g. 1-bit image, 0 and 1s). I
> | cant find a solution to convert a character vector into unsigned char*
> | within Rcpp. Im new to Rcpp and C++ so I might have missed something
>
> Rcpp builds a bridge between R and C++, and supports (in C++) the types that
> R supports. Eg you won't find 'float' but only 'double' as that is what R
> does.
>
> Here you will get character vectors easily. If they must be unsigned char,
> you will probably have to cast them at the C++ level.
>
> | obvious here. Please direct me to resources on this topic (google did
> | not help much).
> |
> | A start:
> |
> | SEXP test(SEXP cM){
> | CharacterVector Vc(cM);
> | int n = Vr.size();
> | RawVector x(n); //is this the same as unsigned char* ?
>
> No, RawVector is for R 'raw' types -- see help("raw") in R,
Guess what raw is !!!
> demangle( "RawVector::stored_type" )
[1] "unsigned char"
> Dirk
>
> | //I tried to fill it with char*(Mr) but I
> | didnt succeed
> | }
> |
> | Thanks,
> |
> | Gustaf
> |
> | --
> | Gustaf Granath (PhD)
> | Post doc
> | McMaster University
> | School of Geography & Earth Sciences
> |
> | _______________________________________________
> | Rcpp-devel mailing list
> | Rcpp-devel at lists.r-forge.r-project.org
> | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
> --
> http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
More information about the Rcpp-devel
mailing list