Rf_asLogical: Convert an R scalar logical vector to a C int

Description Arguments Value Declaration Definition Examples

Description

\Sexpr[results=rd, stage=render]{c3po:::badge('fnp')} \Sexpr[results=rd, stage=render]{c3po:::badge('r2c')}

Converts a scalar (length one) logical vector (SEXP) x to a C int.

Arguments

x

a pointer SEXP, referring to an object of type LGLSXP.

Value

A C int value.

Declaration

1
int asLogical(SEXP x);

In Rinternals.h.

Definition

1
2
3
4
int asLogical(SEXP x)
{
  return asLogical2(x, /* checking = */ 0, R_NilValue, R_NilValue);
}

In coerce.c.

Examples

 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))

ramiromagno/c3po documentation built on Jan. 5, 2021, 8:01 p.m.