Hi, It might be a primitive question but how it is possible to determine if a variable is initialized in an environment? Suppose that we start a R session and wants to run a script which use the variable i. Which function could evaluate if i is already initialized or not and if not, then ask interactively the user to set it? This is to avoid the error message: object i is not found. Regards, Carol [[alternative HTML version deleted]]
On Sep 11, 2009, at 12:15 PM, carol white wrote:> Hi, > It might be a primitive question but how it is possible to determine > if a variable is initialized in an environment? Suppose that we > start a R session and wants to run a script which use the variable > i. Which function could evaluate if i is already initialized or not > and if not, then ask interactively the user to set it? This is to > avoid the error message: object i is not found. > > Regards, > > CarolSee ?exists Note that this will tell you if the object exists, not if it contains a specifically desired initial value. You would have to check for the latter after determining that the object does indeed exist. HTH, Marc Schwartz
On 9/11/2009 1:15 PM, carol white wrote:> Hi, > It might be a primitive question but how it is possible to determine if a variable is initialized in an environment? Suppose that we start a R session and wants to run a script which use the variable i. Which function could evaluate if i is already initialized or not and if not, then ask interactively the user to set it? This is to avoid the error message: object i is not found.See ?exists. Duncan Murdoch
On Fri, Sep 11, 2009 at 7:15 PM, carol white <wht_crl at yahoo.com> wrote:> It might be a primitive question but how it is possible to determine if a variable is initialized in an environment?What about this?> "x" %in% ls()[1] FALSE> x = 41 > "x" %in% ls()[1] TRUE Best, Michael -- Michael Knudsen micknudsen at gmail.com http://lifeofknudsen.blogspot.com/