On Fri, Oct 8, 2010 at 4:05 PM, Eli Holmes wrote:
> I'm still trying to sort out if I can tell the function not to use
> values in the user workspace if they don't exist locally in a
> function, i.e. a "use local variables only" option when defining a
> function. Obviously, I could go to a style o
Thanks for the help. After looking over the answers, I've come up
with some revised code:
# To simply test if an argument was passed in, missing() can be used
# However, if arg defined later, missing() will return TRUE instead of false
a=1 #put a in global environment
tst <- function(a,b=1) {
if
On Oct 7, 2010, at 7:27 PM, Eli Holmes wrote:
I'm trying to test for the existence of an object within a function,
but despite searching the help files and R-list, I can't figure out
how to do it.
Here is some test code:
#-
a=1 #now I have a in the global environment
Eli -
I think you're looking for missing():
tst = function(a,b=1)
+ if(missing(a))print("You must provide a") else print(a)
tst()
[1] "You must provide a"
tst(7)
[1] 7
- Phil Spector
Statistical Co
4 matches
Mail list logo