Skip to content
Back to formatted view

Raw Message

Message-ID: <BANLkTinM0g0ksph6bi-cAY+yEx9q0axU7A@mail.gmail.com>
Date: 2011-04-14T15:14:59Z
From: Douglas Bates
Subject: [Rcpp-devel] Boolean vector from R to C++
In-Reply-To: <4DA70C24.5070305@googlemail.com>

On Thu, Apr 14, 2011 at 10:00 AM, Cedric Ginestet
<c.ginestet05 at googlemail.com> wrote:
> 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?

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.