[Rcpp-devel] Extract a function from a list and create a call
Romain Francois
romain.francois at dbmail.com
Mon Mar 22 16:21:57 CET 2010
Le 22/03/10 14:14, Douglas Bates a écrit :
> I think the problem under Linux is extracting fam[0]. The error
> message to me indicates that even though fam is declared as a
> CharacterVector the SEXP it contains isn't a STRSXP.
This is not supposed to happen. The constructor of CharacterVector makes
sure the SEXP is a STRSXP.
Vector( SEXP x ) : Base() {
Base::setSEXP( r_cast<RTYPE>( x ) ) ;
}
and r_cast attempts to convert x to a STRSXP and throws otherwise.
When we do :
List ll(l) ;
CharacterVector fam = ll["family"] ;
ll["family"] makes a generic_name_proxy, we then ask to convert it to a
CharacterVector, so the templated conversion operator is called :
template <typename T>
operator T(){
return ::Rcpp::as<T>( get() ) ;
}
with T = CharacterVector, so then as<CharacterVector> is called, which
eventually calls CharacterVector( SEXP) constructor, so fam should refer
to a STRSXP.
You can do things like this to debug further.
Function str("str") ;
Rf_PrintValue( str( fam ) ) ;
to check.
or maybe even use the internal inspect:
inspect <- function(...) .Internal(inspect(...))
Function inspect("inspect") ;
Rf_PrintValue( inspect( fam ) ) ;
Romain
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/OIXN : raster images and RImageJ
|- http://tr.im/OcQe : Rcpp 0.7.7
`- http://tr.im/O1wO : highlight 0.1-5
More information about the Rcpp-devel
mailing list