# [Rd] deriv (PR#953)

**Peter Dalgaard BSA
**
p.dalgaard@biostat.ku.dk

*30 May 2001 00:35:00 +0200*

tlumley@u.washington.edu writes:
>* The first bug is very strange and I suspect there's something going on in
*>* the memory management. Supplying a function as the third argument should
*>* cause the body of the function to be replaced by the derivative. This
*>* sometimes works, but doesn't depend on the function in any simple way.
*>*
*>* It seems to depend on how new the function is. With a new anonymous
*>* function it never works, but with a base function like lm or log it always
*>* works:
*>*
*>* ## works
*>* deriv(expression(sin(cos(x) * y)), c("x","y"), log)
*>* ## identical function
*>* LOG<-function (x, base = exp(1))
*>* if (missing(base)) .Internal(log(x)) else .Internal(log(x, base))
*>* ## doesn't work
*>* deriv(expression(sin(cos(x) * y)), c("x","y"), LOG)
*>*
*>* Creating a new function somewhere else in the search path doesn't help
*>* assign("a",function(x,y){},pos=3)
*>* # doesn't work
*>* deriv(expression(sin(cos(x) * y)), c("x","y"), a)
*>*
*>* but copying a loaded function does
*>*
*>* library(tcltk)
*>* a<-tkbind
*>* #works
*>* deriv(expression(sin(cos(x) * y)), c("x","y"), a)
*
<grin>
You had me going there too.
Try stripping the "source" attribute from the template functions....
(or from the output of deriv() for that matter). I'll give it a think
how to do that inside the deriv function so as to preserve user
sanity.
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._