[Rcpp-devel] api/meat/is.h missing CharacterVector and CharacterMatrix
Romain Francois
romain at r-enthusiasts.com
Wed Oct 2 12:08:47 CEST 2013
Le 02/10/13 05:05, Dirk Eddelbuettel a écrit :
>
> Thomas,
>
> On 2 October 2013 at 10:12, Thomas Tse wrote:
> | hi,
> |
> | seems like api/meat/is.h missed the implementation for CharacterVector and CharacterMatrix, i.e. we should add:
> |
> | template <> inline bool is__simple<CharacterVector>( SEXP x ){
> | return TYPEOF(x) == STRSXP ;
> | }
> | template <> inline bool is__simple<CharacterMatrix>( SEXP x ){
> | return TYPEOF(x) == STRSXP && is_matrix(x) ;
> | }
>
> Looks like a good catch, and nice work. If I add this, I can in fact do
>
> R> cppFunction('bool isCharVec(SEXP x) {return(is<CharacterVector>(x));}')
> R> isCharVec(LETTERS)
> [1] TRUE
> R>
>
> whereas I get a linker error without your suggested change. Unit tests all
> pass, so no colleteral damage -- hence committed as rev4553, and added you to
> the THANKS file.
>
> Thanks -- keep the fixes coming! ;-)
>
> Dirk
Just to let you know. I've implemented is slightly differently in
Rcpp11. The template is function delegates to a Is template class with a
test method. Details on this commit:
https://github.com/romainfrancois/Rcpp11/commit/398a58cb5d7bd3098efad6b6e98c851c9c1407bb
The reason it is relevant is when we start to want to make partial
specializations, which we cannot do with function templates. So for
example, we could want to implement is for armadillo matrices. We would
just have to do :
template <typename T> struct Is< arma::Mat<T> > :
Is< Matrix<Rcpp::traits::r_sexptype_traits<T>::rtype> >{} ;
whereas with the current implementation in Rcpp, we would have to fully
specify for arma::mat, arma::cx_mat, ...
The only c++11 thing here is the use of std::conditional, but Rcpp has
traits::if_ do do the same.
Romain
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
More information about the Rcpp-devel
mailing list