[Rcpp-devel] can one modify array in R memory from C++ without copying it?

Steve Lianoglou mailinglist.honeypot at gmail.com
Fri Nov 4 15:13:23 CET 2011


On Fri, Nov 4, 2011 at 9:36 AM, Dirk Eddelbuettel <edd at debian.org> wrote:
> On 4 November 2011 at 16:56, Darren Cook wrote:
> | > Not a bug, this is expected behaviour.
> |
> | Hello Romain,
> | I did not mean the behaviour is a bug; I mean it is going to cause bugs.
> | I was wondering if there is a way to stop the implicit data coercion,
> | forcing the programmer to request it explicitly.
> R does exactly that too
> R> a <- 1
> R> typeof(a)
> [1] "double"
> R> a <- 1L
> R> typeof(a)
> [1] "integer"
> R>
> and Rcpp uses Proxy Classes so this is the Right Thing (TM) to do.  We think,
> at least.
> | E.g. Are the implicit type conversions happening with some extra copy
> | constructors? If so, we could have conditional compilation to exclude
> | those. Something like:
> |
> |   #ifndef FORCE_EXPLICIT
> |   IntegerMatrix(double*){...}
> |   #endif
> |
> | Then programmers who don't like surprises would define FORCE_EXPLICIT,
> | and then their code would sometimes not compile and they would have to
> | write an explicit conversion.
> |
> | (I've not thought that through, I just wanted to demonstrate what I had
> | in mind.)
> If you feel really strongly about you could consider a patch that makes this
> non-R behaviour you suggest an option.  To most of us who use Rcpp between R
> and C++ it really is a feature.
> Don't get me wrong though: I like your input here and maybe the implicit
> nature of things needs to be stressed even more.

What if Rcpp fires a warning (I guess there's a C function that you
can use to invoke R's `warning()`) in these scenarios?

That'd alert you as to what happened and still let people who just use
the CRAN-stalled Rcpp become aware of when this happens in their code.


Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

More information about the Rcpp-devel mailing list