26 #include <Rcpp/internal/Exporter.h>
33 if( ::Rf_length(x) != 1 ) throw ::Rcpp::not_compatible(
"expecting a single value" ) ;
35 SEXP
y =
PROTECT( r_cast<RTYPE>(x) );
36 typedef typename ::Rcpp::traits::storage_type<RTYPE>::type STORAGE;
37 T res = caster<STORAGE,T>( *r_vector_start<RTYPE>(
y ) ) ;
43 return primitive_as<T>(
x) ;
47 if( TYPEOF(x) == CHARSXP )
return CHAR( x ) ;
48 if( ! ::Rf_isString(x) )
49 throw ::Rcpp::not_compatible(
"expecting a string" ) ;
50 if (Rf_length(x) != 1)
51 throw ::Rcpp::not_compatible(
"expecting a single value");
52 return CHAR( STRING_ELT( ::Rcpp::r_cast<STRSXP>(x) ,0 ) ) ;
58 return std::wstring( y, y+strlen(y)) ;
70 if( ! ::Rf_isString(x) ){
71 throw ::Rcpp::not_compatible(
"expecting a string" ) ;
73 if (Rf_length(x) != 1) {
74 throw ::Rcpp::not_compatible(
"expecting a single value");
76 return STRING_ELT( ::Rcpp::r_cast<STRSXP>(x) ,0 ) ;
80 RCPP_DEBUG_1(
"as(SEXP = <%p>, r_type_generic_tag )", x ) ;
81 ::Rcpp::traits::Exporter<T> exporter(x);
83 return exporter.get() ;
93 return as_module_object<typename T::object_type>(
x ) ;
98 T* obj = as_module_object<T>(
x) ;
104 return T( primitive_as<int>(x) ) ;
125 template <
typename T> T
as( SEXP m_sexp) {
129 template <
typename T>
131 return as< typename traits::remove_const_and_reference<T>::type >( m_sexp ) ;
134 template<>
inline SEXP
as(SEXP m_sexp) {
return m_sexp ; }