Function, pure C to R Needs PROTECT()

Converts an int x to a SEXP object that represents an R length one integer vector.

Arguments

x

an int value.

Value

A SEXP object, namely a length one integer vector.

Declaration

SEXP Rf_ScalarInteger(int x);

In Rinternals.h.

Definition

INLINE_FUN SEXP ScalarInteger(int x)
{
  SEXP ans = allocVector(INTSXP, 1);
  SET_SCALAR_IVAL(ans, x);
  return ans;
}

In Rinlinedfuns.h.

Examples

# Convert a C int number as an R length one integer vector forty_two <- inline::cfunction(NULL, ' int x = 42; SEXP y; y = PROTECT(Rf_ScalarInteger(x)); UNPROTECT(1); return y; ' int x = 42; SEXP y; y = PROTECT(Rf_ScalarInteger(x)); UNPROTECT(1); return y; ') forty_two()
#> [1] 42