Skip to content

[Rcpp-devel] Boolean vector from R to C++

4 messages · Cedric Ginestet, Douglas Bates, Dirk Eddelbuettel +1 more

#
Hi all,

I am trying to pass on a boolean vector from R to C++. I have naively 
tried the following:

################################
src <- '
   using namespace Rcpp ;
   using namespace std ;
   int b = as<bool>(xb);
return wrap(b);'
cxxfun <- cxxfunction(sig=signature(xb="logical"),
                       body=src,plugin="Rcpp",verbose=TRUE)
cxxfun(b);

Error in cxxfun(b) : expecting a single value
###############################

Is there an equivalent to IntegerVector or NumericVector for Boolean 
variables or can I simply use the Rcpp::Vector template for this purpose?

Thanks for your help,
#
On Thu, Apr 14, 2011 at 10:00 AM, Cedric Ginestet
<c.ginestet05 at googlemail.com> wrote:
In R a logical vector is an IntegerVector.  You could transform it to
a std::vector<bool> if you were particularly concerned about space but
you would lose the ability to represent missing values.  That is,
elements of an R logical vector can be TRUE, FALSE or <NA> whereas the
C++ bool type can only be true or false.
#
On 14 April 2011 at 16:00, Cedric Ginestet wrote:
| I am trying to pass on a boolean vector from R to C++. I have naively tried the
| following:
[...]
| Is there an equivalent to IntegerVector or NumericVector for Boolean variables
| or can I simply use the Rcpp::Vector template for this purpose?

Yes there is, and we spent time documenting all this, as well as providing
actual working examples (albeit sometime tucked away in the unit tests).  

I think at this point it would be polite of you to figure out how to best
search, index, grep, ... the documentation.

Regards, Dirk
#
Yes. LogicalVector.



Le 14 avr. 2011 ? 05:00 PM, Cedric Ginestet <c.ginestet05 at googlemail.com> a ?crit :
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110414/f202de1c/attachment.htm>