Function, pure C to R Needs PROTECT()

Converts an int x to a SEXP object that represents an R length one logical vector. The mapping from C integers to R's logical is:

Arguments

x

an int value.

Value

A SEXP object, namely a length one logical vector.

Declaration

SEXP Rf_ScalarLogical(int x);

In Rinternals.h.

Definition

INLINE_FUN SEXP ScalarLogical(int x)
{
  extern SEXP R_LogicalNAValue, R_TrueValue, R_FalseValue;
  if (x == NA_LOGICAL) return R_LogicalNAValue;
  else if (x != 0) return R_TrueValue;
  else return R_FalseValue;
}

In Rinlinedfuns.h.

Examples

# Convert a C int number as an R length one logical vector with TRUE true <- inline::cfunction(NULL, ' int x = 2; SEXP y; y = PROTECT(Rf_ScalarLogical(x)); UNPROTECT(1); return y; ' int x = 2; SEXP y; y = PROTECT(Rf_ScalarLogical(x)); UNPROTECT(1); return y; ') true()
#> [1] TRUE
# Convert a C int number as an R length one logical vector with FALSE false <- inline::cfunction(NULL, ' int x = 0; SEXP y; y = PROTECT(Rf_ScalarLogical(x)); UNPROTECT(1); return y; ' int x = 0; SEXP y; y = PROTECT(Rf_ScalarLogical(x)); UNPROTECT(1); return y; ') false()
#> [1] FALSE
# Convert a C int number as an R length one logical vector with NA na_logical <- inline::cfunction(NULL, ' int x = NA_LOGICAL; SEXP y; y = PROTECT(Rf_ScalarLogical(x)); UNPROTECT(1); return y; ' int x = NA_LOGICAL; SEXP y; y = PROTECT(Rf_ScalarLogical(x)); UNPROTECT(1); return y; ') na_logical()
#> [1] NA