[Rd] Error once having applied (PR#8718)

maechler at stat.math.ethz.ch maechler at stat.math.ethz.ch
Tue Mar 28 12:05:17 CEST 2006


Merci, François!

>>>>> "FrPi" == François Pinard <pinard at progiciels-bpi.ca>
>>>>>     on Tue, 28 Mar 2006 03:00:19 +0200 (CEST) writes:

    FrPi> Hi, people.  Here is a transcript of a "R --vanilla" session:
    FrPi> ======================================================================>

    FrPi> R : Copyright 2005, The R Foundation for Statistical Computing
    FrPi> Version 2.2.1  (2005-12-20 r36812)

    ....................

    >> z = data.frame(a=0:9, b=10:19)
    >> apply(z, 1, sum)
    FrPi> 1  2  3  4  5  6  7  8  9 10
    FrPi> 10 12 14 16 18 20 22 24 26 28
    >> apply(z, 1, '$', 'a')
    FrPi> NULL
    >> apply(z, 1, sum)
    FrPi> Erreur dans sum(..., na.rm = na.rm) : 'mode' de l'argument incorrect
    FrPi> ======================================================================<

    FrPi> There are three explicit calls to "apply", one would expect the first
    FrPi> and the third to yield similar results.  They do indeed, if the second
    FrPi> "apply" is not executed, or if '$' gets replaced by '[[' within it.  So
    FrPi> the second "apply", as written, may be hurting the R interpreter.

Indeed! 'z' itself is not changed; it's something else that's corrupted,
since one can reproduce the bug by

apply(data.frame(a=0:9, b=10:19), 1, sum)
apply(data.frame(a=0:9, b=10:19), 1, "$", "a")
apply(data.frame(a=0:9, b=10:19), 1, sum)
##-> error ... invalid 'mode'

This also happens in "R-devel", since yesterday aka 
"2.3.0 alpha".

Martin



More information about the R-devel mailing list