Function, pure C to R Needs PROTECT()

Converts an Rcomplex x to a SEXP object that represents an R length one complex vector.

Arguments

x

an Rcomplex object.

Value

A SEXP object, namely a length one complex vector.

Declaration

SEXP Rf_ScalarComplex(Rcomplex x);

In Rinternals.h.

Definition

INLINE_FUN SEXP ScalarComplex(Rcomplex x)
{
  SEXP ans = allocVector(CPLXSXP, 1);
  SET_SCALAR_CVAL(ans, x);
  return ans;
}

In Rinlinedfuns.h.

Examples

# Convert a C complex number to an R length one complex vector scalar_complex <- inline::cfunction(NULL, 'double real = 1.; double imaginary = 2.; Rcomplex x; x.r = real; x.i = imaginary; SEXP y; y = PROTECT(Rf_ScalarComplex(x)); UNPROTECT(1); return y; 'double real = 1.; double imaginary = 2.; Rcomplex x; x.r = real; x.i = imaginary; SEXP y; y = PROTECT(Rf_ScalarComplex(x)); UNPROTECT(1); return y; ') scalar_complex()
#> [1] 1+2i