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
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
I don't believe the solution proposed below works and anyway misses the
whole point of tryCatch(), which is **not** to test manually:
f - function(i){
val - tryCatch(get(i), error = function(e)input error)
val ## can test val and carry on if not an error
}
## testit
f()
[1] input error
f(2)
Not the most beautiful solution: start your message with carriage return, e.g.
stop(\rA long enough message);
A long enough message
stop(\rfoo);
fooor:
/H
On Mon, Sep 14, 2009 at 5:06 PM, Bert Gunter gunter.ber...@gene.com wrote:
I don't believe the solution proposed below works and anyway
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
Thanks for your replies.
I use the following script:
if(!exists(i)) stop (set the variable i, call. = FALSE)
but before the stop expression, Error gets displayed:
Error: set the variable i
Is there another function that stops the execution, prints an expression
without printing Error or any
Do watch out, however, for *where* i exits.
That is, if you type search() you will see a list of environments in
which i might be found. You're probably assuming that i, if
exists(i) is true, is in .GlobalEnv, but it might be in one of the
other environments, in which case exists('i') will be
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
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
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
10 matches
Mail list logo