[Rd] extending the derivs table/fools rushing in

Gabor Grothendieck ggrothendieck at gmail.com
Thu Aug 14 19:21:27 CEST 2008


Its a valid R function.   ?"{"

On Thu, Aug 14, 2008 at 1:07 PM, Ben Bolker <bolker at zoology.ufl.edu> wrote:
>  http://www.zoology.ufl.edu/bolker/deriv_patch2.txt
>
>  has this change added as well.
>  However, I'm not as confident that this is the right thing
> to do?  Should curly brackets even be appearing in mathematical
> expressions?
>
>  Ben
>
> Gabor Grothendieck wrote:
>> While you are at it could you add { to the
>> table so that this works:
>>
>>> # this is ok
>>> f <- function(x) x*x
>>> D(body(f), "x")
>> x + x
>>
>>> # but not g which is same as f
>>> # except it has { ... } surrounding its body
>>> g <- function(x) { x*x }
>>> D(body(g), "x")
>> Error in D(body(g), "x") : Function '`{`' is not in the derivatives table
>>
>>
>> 2008/8/14 Ben Bolker <bolker at zoology.ufl.edu>:
>>>  I added "plogis" to the derivative table in the
>>> development version of R; the patch against yesterday's
>>> R-devel src/deriv/main.c is available at
>>> http://www.zoology.ufl.edu/bolker/deriv_patch.txt .
>>>
>>>  I pretty much followed the framework of the other symbols;
>>> here was my incantation
>>>
>>> -       } else if (CAR(expr) == PlogisSymbol) {
>>> -           ans = simplify(TimesSymbol,
>>> -                          PP_S(TimesSymbol,
>>> -                               PP_S2(ExpSymbol,
>>> -                                  PP_S2(MinusSymbol,CADR(expr))),
>>> -                               PP_S(PowerSymbol,
>>> -                                    PP_S(PlusSymbol,
>>> -                                         Constant(1.),
>>> -                                         PP_S2(ExpSymbol,
>>> -                                            PP_S2(MinusSymbol,CADR(expr)))),
>>> -                                    Constant(-2.))),
>>> -                          PP(D(CADR(expr),var)));
>>> -           UNPROTECT(8);
>>>
>>> It seems to work:
>>>
>>>> D(quote(plogis(a)),"a")
>>> exp(-a) * (1 + exp(-a))^-2
>>>> D(quote(plogis(a+b*x)),"x")
>>> exp(-(a + b * x)) * (1 + exp(-(a + b * x)))^-2 * b
>>>
>>>  Any thoughts?  I'm sure there's a cleverer way to do this ...
>>>
>>>  Ben Bolker
>>>
>>>  PS I get a minor build error at the end of the compilation
>>> (on Ubuntu 8.10):
>>>
>>> make[2]: *** No rule to make target `VR.ts', needed by
>>> `stamp-recommended'.  Stop.
>>> make[2]: Leaving directory
>>> `/usr/local/src/R/R-devel/src/library/Recommended'
>>> make[1]: *** [recommended-packages] Error 2
>>> make[1]: Leaving directory
>>> `/usr/local/src/R/R-devel/src/library/Recommended'
>>> make: *** [stamp-recommended] Error 2
>>>
>>>  ... don't know if that is important or not.
>>>
>>>
>>>
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>>
>
>
>



More information about the R-devel mailing list