For data frames you can also use with()

in your example:

with(d, exists("z"))
--------------------------------------
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
"Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it."
     - Jubal Early, Firefly



From:
ivo welch <ivo.we...@gmail.com>
To:
Erik Iverson <er...@ccbr.umn.edu>
Cc:
r-help <r-h...@stat.math.ethz.ch>
Date:
11/03/2010 02:20 PM
Subject:
Re: [R] programming questions
Sent by:
r-help-boun...@r-project.org



yikes.  this is all my fault.  it was the first thing that I ever
defined when I started using R.

   is.defined <- function(name) exists(as.character(substitute(name)))

I presume there is something much better...

/iaw


On Wed, Nov 3, 2010 at 2:12 PM, Erik Iverson <er...@ccbr.umn.edu> wrote:
>
>
> ivo welch wrote:
>>
>> quick programming questions.  I want to "turn on" more errors.  there
>> are two traps I occasionally fall into.
>>
>> * I wonder why R thinks that a variable is always defined in a data 
frame.
>>
>>     > is.defined(d)
>>     [1] FALSE
>>     > d= data.frame( x=1:5, y=1:5 )
>>     > is.defined(d$z)
>>     [1] TRUE
>>     > is.defined(nonexisting$garbage)
>>     [1] TRUE
>
> Which package/version of R is the 'is.defined' function in?
>
> I don't seem to have it here on 2.11.1, which I know is not
> the latest version of R.
>
> What does 'defined' mean?
>
>>
>> this is a bit unfortunate for me, because subsequent errors become
>> less clear.   right now, I need to do '(is.defined(d) and
>> !is.null(d$z))' to check that my function inputs are valid.  It would
>> be nicer if one could just write "if (is.defined(d$z)".
>
> "z" %in% names(d) ?
>
>>
>> * is there a way to turn off automatic recycling?  I would rather get
>> an error than unexpected recycling.  I can force recycling with rep()
>> when I need to.
>>
>> regards,
>>
>> /iaw
>>
>> ----
>> Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)
>>
>> ______________________________________________
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to