[Rcpp-devel] Create scalar values in Rcpp

Dirk Eddelbuettel edd at debian.org
Mon Dec 10 17:33:53 CET 2018


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

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list