GeezerVison is showing github.com — Allow user to see when coercion happens · Issue #142 · Rcpp11/Rcpp11
Allow user to see when coercion happens #142
Description
E.g. defining RCPP_WARN_ON_COERCE would warn whenever r_cast is called. Maybe r_coerce as well?
Activity
romainfrancois commented on Apr 11, 2014
Perhaps in Vector(SEXP) it makes sense, although perhaps the default should be to error when e.g. someone wants to make a NumericVector out of a INTSXP which is the common source of coercion.
We could have some explicit way of saying that coercion is fine.
kevinushey commented on Apr 11, 2014
ContributorAuthor
More actions
Having coercion off by default makes sense to me as well. It makes more sense in R where the distinction between double and int shouldn't matter for most use cases; this is less true with C++.
romainfrancois commented on Apr 12, 2014
The bonus is that it also takes care of this problem:
void alter( NumericVector x){
x[0] = 1 ;
}
if you pass a numeric vector to alter its data is altered, that's fine our classes are proxies to the underlying SEXP. But if you pass an integer vector, then what is altered is the coerced data. This is usually hard to explain. So this free coercion has a price.
kevinushey commented on Apr 15, 2014
ContributorAuthor
More actions
In the coerce branch, the ctor from SEXP now has a coerce argument, defaulting to false. It throws an error if one tries to construct a vector from a SEXP of different type.
Metadata
Metadata
Development
No branches or pull requestsIssue actions