[Rcpp-devel] coercion NULL to vector
Serguei Sokol
serguei.sokol at gmail.com
Wed Apr 18 15:09:23 CEST 2018
Le 18/04/2018 à 13:32, Dirk Eddelbuettel a écrit :
>
> On 18 April 2018 at 10:26, Georgi Boshnakov wrote:
> | I may be missing something here but
> | it doesn't seem right to introduce silent coercion of NULL to vectors, etc.,
> | especially if it would become imposed on everybody using Rcpp/Armadillo.
> | Even the "convenience" of this is questionable.
>
> Agreed. I am also not yet convinced by Serguei's argument. It seems a little
> invasive for an unclear (to me) use case.
I can describe my own case which made me search for a such solution.
I have an Rcpp/Armadillo function accepting in an optional argument a vector of uvec type.
It can be called from R and I can call it from other C++ functions of the same package too.
Nullable<IntegerVector> mechanism was cumbersome but sufficient (note that there is no possible Nullable<uvec>)
when only R calls were planned. But when it comes to calls from C++ I'll have to juggle with wrap() too.
Both of Nullable<T> (as well as special code for dealing with NULL case) and wrap()
become unnecessary with a neat declaration f(..., uvec v, ...). So that
an R call with 'c()' can pass as well as C++ calls with an empty uvec without
any additional hassle for treating NULL case.
Serguei.
More information about the Rcpp-devel
mailing list