Re: [R] exists() and functions

From: Jonathan Greenberg <>
Date: Fri, 25 Jun 2010 13:12:01 -0700

Always nice to answer my own question 3 minutes later. The missing() function does what I want. Still, why DOES this exists() statement fail? Do functions "auto create" the variables once they are called, regardless of whether or not they are assigned?


On Fri, Jun 25, 2010 at 1:05 PM, Jonathan Greenberg <> wrote:
> I'm a bit confused about how exists() work within a function -- I want
> to test for unassigned variables, but I'm doing tests in the main
> environment to figure out the function, so the variables DO exist in
> the parent environment of a function call.
> Why does:
> myfunction <- function(variable_outside_function)
> {
>        print(exists("variable_outside_function",inherit=FALSE))
>        print(exists("another_variable_outside_function",inherit=FALSE))
> }
> myfunction()
> Return:
> [1] TRUE
> [1] FALSE
> I didn't assign anything to variable_outside_function, so I'm unclear
> why it thinks it exists...
> --j
> mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri 25 Jun 2010 - 20:41:22 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 25 Jun 2010 - 20:50:36 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive