s-news
[Top] [All Lists]

Re: [S] Feature or bug?

To: "Paul Y. Peng" <ypeng@math.mun.ca>
Subject: Re: [S] Feature or bug?
From: Prof Brian D Ripley <ripley@stats.ox.ac.uk>
Date: Fri, 23 Jul 1999 08:37:29 +0100 (BST)
Cc: s-news <s-news@wubios.wustl.edu>
In-reply-to: <3797C919.E826A81E@math.mun.ca>
Sender: owner-s-news@wubios.wustl.edu
On Thu, 22 Jul 1999, Paul Y. Peng wrote:

> 
> In S-PLUS 3.3 (DEC Alpha) and S-PLUS 2000,
> 
> > z <- c("a"=1, "b"=2)
> > lapply(z, function(x)names(x))
> $a:
> [1] "a"
> 
> $b:
> [1] "b"
> 
> But in S-PLUS 5.1 (Linux),
> 
> > z <- c("a"=1, "b"=2)
> > lapply(z, function(x)names(x))
> $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.

No, you missed something in S-PLUS 3.3. The argument of lapply is
supposed to be a list:

Apply a Function to Components of a List


DESCRIPTION:
       Returns a list which is the result of a function  that  is
       applied to each element of a list.

USAGE:
       lapply(X, FUN, ...)

REQUIRED ARGUMENTS:
X:     a list.


> z <- c("a"=1, "b"=2)
> is.list(z)
[1] F

In S-PLUS 5.1

> as.list(z)
$a:
[1] 1

$b:
[1] 2

Those components have no names.

In S-PLUS 3.4

> as.list(z)
[[1]]:
[1] 1

[[2]]:
[1] 2
> lapply(as.list(z), names)
[[1]]:
NULL

[[2]]:
NULL
> lapply(z, names)
$a:
[1] "a"

$b:
[1] "b"

which seems rather inconsistent.

Now if you had complained about
> sapply(z, names) # 3.4
   a   b 
 "a" "b"
> sapply(z, names) # 5.1
$a:
NULL

$b:
NULL

I would agree, as

   X
          any S-PLUS object; usually a list. Missing values ( NAs) are
 ...

However, just names(z) or as.list(names(z)) would do in your problem.


-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>