Hi.
I'm having trouble testing for existence of an object inside a function.
Suppose I have a function:
f-function(x){
...
}
and I call it with argument y:
f(y)
I'd like to check inside the function whether argument y exists. Is this
possible, or do I have to either check outside the
Not sure which one you want, but the following should cover it:
R f - function(x) c(x=missing(x), y=exists(y))
R f(1)
x y
FALSE FALSE
R f()
x y
TRUE FALSE
R y - 1
R f()
xy
TRUE TRUE
R f(1)
x y
FALSE TRUE
Andy
From: Talbot Katz
Hi.
I'm having
a bad
programming paradigm. But even an explanation if that's the case would be
appreciated.
-- TMK --
212-460-5430home
917-656-5351cell
From: Liaw, Andy [EMAIL PROTECTED]
To: Talbot Katz [EMAIL PROTECTED],r-help@stat.math.ethz.ch
Subject: RE: [R] Testing for existence inside a function
.
-- TMK --
212-460-5430 home
917-656-5351 cell
From: Liaw, Andy [EMAIL PROTECTED]
To: Talbot Katz [EMAIL PROTECTED],r-help@stat.math.ethz.ch
Subject: RE: [R] Testing for existence inside a function [Broadcast]
Date: Tue, 15 May 2007 11:03:12 -0400
Not sure which one you want
with this. Thanks again!
-- TMK --
212-460-5430home
917-656-5351cell
From: Liaw, Andy [EMAIL PROTECTED]
To: Talbot Katz [EMAIL PROTECTED],r-help@stat.math.ethz.ch
Subject: RE: [R] Testing for existence inside a function
Date: Tue, 15 May 2007 11:41:17 -0400
Just need a bit more work
-5351cell
From: Liaw, Andy [EMAIL PROTECTED]
To: Talbot Katz [EMAIL PROTECTED],r-help@stat.math.ethz.ch
Subject: RE: [R] Testing for existence inside a function
Date: Tue, 15 May 2007 11:41:17 -0400
Just need a bit more work:
R f - function(x) exists(deparse(substitute(x)))
R f(y
!
-- TMK --
212-460-5430home
917-656-5351cell
From: Liaw, Andy [EMAIL PROTECTED]
To: Talbot Katz [EMAIL PROTECTED],r-help@stat.math.ethz.ch
Subject: RE: [R] Testing for existence inside a function
Date: Tue, 15 May 2007 11:41:17 -0400
Just need a bit more work:
R f
-5351cell
From: Liaw, Andy [EMAIL PROTECTED]
To: Talbot Katz [EMAIL PROTECTED],r-help@stat.math.ethz.ch
Subject: RE: [R] Testing for existence inside a function
Date: Tue, 15 May 2007 11:41:17 -0400
Just need a bit more work:
R f - function(x) exists(deparse
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Gabor Grothendieck
Sent: Tuesday, May 15, 2007 10:06 AM
To: Liaw, Andy
Cc: r-help@stat.math.ethz.ch; Talbot Katz
Subject: Re: [R] Testing for existence inside a function
Maybe this:
chk2 - function(x
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Gabor Grothendieck
Sent: Tuesday, May 15, 2007 10:06 AM
To: Liaw, Andy
Cc: r-help@stat.math.ethz.ch; Talbot Katz
Subject: Re: [R] Testing for existence inside a function
Maybe this:
chk2 - function(x
Talbot Katz wrote:
I'm having trouble testing for existence of an object inside a function.
No, you are having trouble testing for existence of an object
_before_ the function is called :-)
Suppose I have a function:
f-function(x){
...
}
and I call it with argument y:
f(y)
On 5/15/2007 3:06 PM, Alberto Monteiro wrote:
Talbot Katz wrote:
I'm having trouble testing for existence of an object inside a function.
No, you are having trouble testing for existence of an object
_before_ the function is called :-)
Suppose I have a function:
f-function(x){
...
Duncan Murdoch wrote:
Try this:
f - function(x) x + 1
f(y.does.not.exist)
y.does.not.exist
The error message is (almost) the same, and it happens when
parsing the line. There's no way to change f to change this.
That description is true in some languages, but not in R. R doesn't
13 matches
Mail list logo