On Wed, Nov 3, 2010 at 6:17 PM, ivo welch <[email protected]> wrote:
> 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...
You didn't do a good job testing your is.defined :)
Let's see what happens when you feed it 'nonexisting$garbage'. What
gets passed into 'exists'?
acs=function(name){as.character(substitute(name))}
> acs(nonexisting$garbage)
[1] "$" "nonexisting" "garbage"
- and then your exists test is doing effectively exists("$") which
exists. Hence TRUE.
What you are getting here is the expression parsed up as a function
call ($) and its args. You'll see this if you do:
> acs(fix(me))
[1] "fix" "me"
Perhaps you meant to deparse it:
> acs=function(name){as.character(deparse(substitute(name)))}
> acs(nonexisting$garbage)
[1] "nonexisting$garbage"
> exists(acs(nonexisting$garbage))
[1] FALSE
But you'd be better off testing list elements with is.null
Barry
______________________________________________
[email protected] 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.