Skip to content

lapply( *, names) -- bug ?!

3 messages · Martin Maechler, Brian Ripley

#
This came on S-news

The more direct test being

sapply(c(a=1,b=2), names)

Problem:  
	  R ("all" versions) 
	  behaves the same as S+5.1, which is wrong IMO.

{since some might disagree,  I didn't yet post to R-bugs ..}

------- Start of forwarded message -------
Date: Thu, 22 Jul 1999 23:14:57 -0230
From: "Paul Y. Peng" <ypeng@math.mun.ca>
To: s-news <s-news@wubios.wustl.edu>
Subject: [S] Feature or bug?

In S-PLUS 3.3 (DEC Alpha) and S-PLUS 2000,
$a:
[1] "a"

$b:
[1] "b"

But in S-PLUS 5.1 (Linux),
$a:
NULL

$b:
NULL

Is this a new feature of S-PLUS 5? Do I miss anything in
S-PLUS 5? Thank you for your help.
------- End of forwarded message -------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Fri, 23 Jul 1999, Martin Maechler wrote:

            
I do.  the argument is not a list, and lapply applies to lists. So
$a
[1] 1

$b
[1] 2

Fine. Note the names of the components are NULL.

  
    
#

        
BDR> On Fri, 23 Jul 1999, Martin Maechler wrote:
>> This came on S-news
    >> 
    >> The more direct test being
    >> 
    >> sapply(c(a=1,b=2), names)
    >> 
    >> Problem:  
    >> R ("all" versions) 
    >> behaves the same as S+5.1, which is wrong IMO.
    >> 
    >> {since some might disagree,  I didn't yet post to R-bugs ..}

    BDR> I do.  the argument is not a list, and lapply applies to lists.
that was not the point;
lapply() and sapply() are supposed to coerce to list()
    BDR> So
    >> as.list(c(a=1,b=2))
    BDR> $a
    BDR> [1] 1

    BDR> $b
    BDR> [1] 2

    BDR> Fine. Note the names of the components are NULL.

Yes, exactly.  

And therefore lapply(*, names) {or sapply(..)} should return NULLs
as it does [in R and S+5.x].
I was wrong all along.
It seems I need a longer warm-up time for my brain today...

Martin
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._