Function, pure C to R Needs PROTECT()

Converts an Rbyte (unsigned char) to a SEXP object that represents an R length one raw vector.

Arguments

x

an Rbyte value.

Value

A SEXP object, namely a length one (one byte) raw vector.

Declaration

SEXP Rf_ScalarRaw(Rbyte x);

In Rinternals.h.

Definition

INLINE_FUN SEXP ScalarRaw(Rbyte x)
{
  SEXP ans = allocVector(RAWSXP, 1);
  SET_SCALAR_BVAL(ans, x);
  return ans;
}

In Rinlinedfuns.h.

Examples

# Convert a C unsigned char to an R length one raw vector asterisk_byte <- inline::cfunction(NULL, " Rbyte x = '*'; // '*' is 42 in decimal, 2a in hexadecimal. SEXP y; y = PROTECT(Rf_ScalarRaw(x)); UNPROTECT(1); return y; " Rbyte x = '*'; // '*' is 42 in decimal, 2a in hexadecimal. SEXP y; y = PROTECT(Rf_ScalarRaw(x)); UNPROTECT(1); return y; ") asterisk_byte()
#> [1] 2a