[R] lapply with argument "X"

john.gavin@ubs.com john.gavin at ubs.com
Wed Oct 6 18:54:12 CEST 2004


Hi,

> From: Peter Dalgaard [mailto:p.dalgaard at biostat.ku.dk]
> <john.gavin at ubs.com> writes:
> 
> > Hi,
> > 
> > I am probably making a simple mistake but I can't see it
> > 
> > > X
> > Error: Object "X" not found
> > > exists("X")
> > [1] FALSE
> > > lapply("X", exists)
> > [[1]]
> > [1] TRUE
> > 
> > Why is lapply producing true?
> > Is it something to do with the first
> > argument of lapply also being called 'X'?
> 
> Internal variable capture. I think this is a bug.

Fyi, I wanted to show that users have to use single
character variables with caution because of the existance
of objects like 'c', 'q', 'T' and 'F'.
So I tried to say

> xx <- c(letters, LETTERS) ; xx[sapply(xx, exists)]
 [1] "c" "q" "t" "C" "D" "F" "I" "Q" "T" "X"

but the appearance of 'X' undermines my code.
In that sense, it seems like a bug to me.
(I have a local definition for 'Q' - quit without asking.)

> Also, try  lapply("FUN",get)

Agreed.

Regards,

John.

John Gavin <john.gavin at ubs.com>,
Quantitative Risk Models and Statistics,
UBS Investment Bank, 6th floor, 
100 Liverpool St., London EC2M 2RH, UK.
Phone +44 (0) 207 567 4289
Fax   +44 (0) 207 568 5352


> -----Original Message-----
> From: Peter Dalgaard [mailto:p.dalgaard at biostat.ku.dk]
> Sent: 06 October 2004 17:31
> To: Gavin, John
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] lapply with argument "X"
> 
> 
> <john.gavin at ubs.com> writes:
> 
> > Hi,
> > 
> > I am probably making a simple mistake but I can't see it
> > 
> > > X
> > Error: Object "X" not found
> > > exists("X")
> > [1] FALSE
> > > lapply("X", exists)
> > [[1]]
> > [1] TRUE
> > 
> > Why is lapply producing true?
> > Is it something to do with the first
> > argument of lapply also being called 'X'?
> 
> Internal variable capture. I think this is a bug.
> 
> Also, try  lapply("FUN",get)
> 

Visit our website at http://www.ubs.com

This message contains confidential information and is intend...{{dropped}}




More information about the R-help mailing list