[Rcpp-devel] type information about elements in Rcpp::List
Chaomei Lo
chaomeilo at gmail.com
Mon Jun 9 22:56:46 CEST 2014
Hi, Romain,
Thanks a lot for the quick reply !!
Suffix with << L >> works for me for both Rf_isInteger and is<int>.
On Mon, Jun 9, 2014 at 12:43 PM, Romain François <romain at r-enthusiasts.com>
wrote:
>
> Le 9 juin 2014 à 21:40, Chaomei Lo <chaomeilo at gmail.com> a écrit :
>
> >
> > I have a R list something like this -
> >
> > op=list(a=200, b="test", c=4.5)
> > when I pass it as an argument to Rcp Export function which the code
> looks like this in below.
> >
> > ----------------------------------------
> > int n = xlist.length();
> > for (int I=0; I < n; I++) {
> > SEXP s = xlist[I];
> > if (Rf_isInteger(s)) {
> > //do something
> > }
> > else if (Rf_isNumerc(s)) {
> > //do other thing
> > }
> > else if (Rf_isString(s)) {
> > //do other thing
> > }
> > }
> >
> > However, both a and c go to the Rf_isNumeric if statement; but the first
> one is an integer,
>
> no it’s not.
>
> > str( 200 )
> num 200
> > str( 200L )
> int 200
> > str( as.integer(200) )
> int 200
>
> Suffix with « L » or use as.integer if you want an integer.
>
> Alternatively, Rcpp has is<>, so you can use
>
> if( is<int>(s) ) {
> ...
> }
>
> Romain
>
> > not sure why it did not go to into the Rf_isInteger if statement.
> >
> > Thanks.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140609/343e5986/attachment.html>
More information about the Rcpp-devel
mailing list