Description Arguments Value Declaration Definition Examples
Converts a scalar (length one) logical vector
(SEXP) x to a C int.
x | 
 a pointer   | 
A C int value.
1  | 
In Rinternals.h.
1 2 3 4  | int asLogical(SEXP x)
{
  return asLogical2(x, /* checking = */ 0, R_NilValue, R_NilValue);
}
 | 
In coerce.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  | # Convert an R length one logical vector to a C int number
# Please note that the double backslash in "\n" in Rprintf is only required
# because of the inlining of the code here.
rlogical_to_cint <- inline::cfunction(c(x = "logical"),
 ' int x_;
   x_ = Rf_asLogical(x);
   Rprintf("x_ is %d\\n", x_);
   return R_NilValue;
 ')
# NA is mapped to INT_MIN
invisible(rlogical_to_cint(NA))
# Empty logical is also mapped to INT_MIN
invisible(rlogical_to_cint(NA))
# FALSE is internally mapped to 0
invisible(rlogical_to_cint(FALSE))
# TRUE is internally mapped to 1
invisible(rlogical_to_cint(TRUE))
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.