Description Arguments Value Declaration Definition Examples
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.
1 | SEXP Rf_ScalarLogical(int x);
|
In Rinternals.h.
1 2 3 4 5 6 7 | 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | # 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;
')
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;
')
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;
')
na_logical()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.