Skip to content
Prev 10245 / 10988 Next

[Rcpp-devel] Create scalar values in Rcpp

On 10 December 2018 at 11:24, Avraham Adler wrote:
| There are no scalars in R; there are vectors of length 1.

Yep. An R feature, and gotcha if you come from somwhere else. See

  R> a <- 1
  R> is.vector(a)
  [1] TRUE
  R>

And while we can do this

  R> Rcpp::cppFunction("double wolf(double x) { return x+x; }")
  R> wolf(21.0)
  [1] 42
  R> 

it involves a combination of casts and our template magic so make it SEXPs
which, as representations of R types, are always vectors.

Dirk