Skip to content

Problems ahead from misuse of DUP=FALSE in .C and .Fortran calls

1 message · Brian Ripley

#
I have been looking into making as.double() and friends do less copying 
(and they now do in R-devel).  The problem is that people have been 
writing code which assumes copying is guaranteed, so we decided not to put 
any changes into 2.5.0.

All but one of the cases I have detected (RandomFields, cluster::diana and 
stats::smooth, but there may be others that I have not) are due to the use 
of DUP=FALSE.  Now, there is a pretty strong warning against this on the 
help page, but people still do it and some of you are relying on as.xxxx 
making a new object which the compiled code then alters.

I think the message is clear: do not use DUP=FALSE unless you can prove 
that alteration of arguments in your C/Fortran code never has a 
side-effect.  Watch out for what that side-effect might be: in one case it 
is to change the parsed code in the loaded namespace which affects 
subsequent uses of the function but the first example works correctly (and 
few test suites try functions repeatedly).