Rf_asReal.Rd| x |
|---|
A C double value.
double asReal(SEXP x);
In Rinternals.h.
double asReal(SEXP x)
{
int warn = 0;
double res;
if (isVectorAtomic(x) && XLENGTH(x) >= 1) {
switch (TYPEOF(x)) {
case LGLSXP:
res = RealFromLogical(LOGICAL_ELT(x, 0), &warn);
CoercionWarning(warn);
return res;
case INTSXP:
res = RealFromInteger(INTEGER_ELT(x, 0), &warn);
CoercionWarning(warn);
return res;
case REALSXP:
return REAL_ELT(x, 0);
case CPLXSXP:
res = RealFromComplex(COMPLEX_ELT(x, 0), &warn);
CoercionWarning(warn);
return res;
case STRSXP:
res = RealFromString(STRING_ELT(x, 0), &warn);
CoercionWarning(warn);
return res;
default:
UNIMPLEMENTED_TYPE("asReal", x);
}
} else if(TYPEOF(x) == CHARSXP) {
res = RealFromString(x, &warn);
CoercionWarning(warn);
return res;
}
return NA_REAL;
}
In coerce.c.
# Convert an R length one integer vector to a C double number # Please note that the double backslash in "\n" in Rprintf is only required # because of the inlining of the code here. rdouble_to_cdouble <- inline::cfunction(c(x = "double"), ' double x_; x_ = Rf_asReal(x); Rprintf("x_ is %f\\n", x_); return R_NilValue; ' double x_; x_ = Rf_asReal(x); Rprintf("x_ is %f\\n", x_); return R_NilValue; ') invisible(rdouble_to_cdouble(NA_real_))#> x_ is nan#> x_ is nan#> x_ is -1.000000#> x_ is 0.000000#> x_ is 1.000000#> x_ is inf