Message-ID: <Pine.LNX.4.44.0410061729370.564-100000@gannet.stats>
Date: 2004-10-06T16:33:32Z
From: Brian Ripley
Subject: lapply with argument "X"
In-Reply-To: <012821F286ED1D4ABDC72F9E1DD63D0C041EA9F4@NLDNC003PEX1.ubsgs.ubsgroup.net>
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