Rf_ScalarLogical.Rd
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:
If x
is NA_LOGICAL, then return value is NA
(R_LogicalNAValue)
If x
is 0, then return value is FALSE
(R_FalseValue)
If x
is any other value, then the return value is TRUE
(R_TrueValue)
x | an int value. |
---|
A SEXP object, namely a length one logical
vector.
SEXP Rf_ScalarLogical(int x);
In Rinternals.h.
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.
# 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