Try this: if (!exists("i")) tryCatch(stop(""), error = function(e)invisible(), finally=print("Please set the i variable"))
On Mon, Sep 14, 2009 at 3:38 PM, carol white <wht_...@yahoo.com> wrote: > Thanks to your replies. > > In fact, the problem doesn't come from "exists" but from "stop" that > displays Error even if call. = FALSE. To answer to Dan, I quoted the > pramater of exists. So when the variable is not defined, stop displays the > expression message preceded by "Error". So the question was how not to > display "Error" or if there is another function that does stop's job without > displaying "Error"? > > Cheers, > > --- On Sun, 9/13/09, Michael Knudsen <micknud...@gmail.com> wrote: > > From: Michael Knudsen <micknud...@gmail.com> > Subject: Re: [R] how to determine if a variable is already set? > To: "carol white" <wht_...@yahoo.com> > Cc: r-h...@stat.math.ethz.ch > Date: Sunday, September 13, 2009, 7:06 AM > > On Fri, Sep 11, 2009 at 7:15 PM, carol white <wht_...@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 > micknud...@gmail.com > http://lifeofknudsen.blogspot.com/ > > > > > [[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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[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.