[R] lapply with argument "X"
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Oct 6 18:33:32 CEST 2004
On Wed, 6 Oct 2004 john.gavin at ubs.com wrote:
> 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'?
Yes. Note that the first argument of lapply is supposed to be a list,
so what you are really using is
lapply(as.list("X"), exists)
and indeed an object named "X" exists in the environment within which
exists() is run.
--
Brian D. Ripley, ripley at 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 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list