utkarshsinghal
2011-May-14 07:30 UTC
[R] calling "exists" function inside another function is not working
Hi all, I want to define a function such that one of its argument if passed do one thing and if not passed do the second thing. So basically, I have to check whether the argument is passed or not inside the function. I am trying to use 'exists' function to do this. > f = function(a,b){exists("b")} > f(a=3, b=4) [1] TRUE This is working as expected. But if I do the following: > f(a=3) [1] TRUE Can anybody explain why this function is returning TRUE here. -- Many thanks, Utkarsh
David Winsemius
2011-May-14 10:30 UTC
[R] calling "exists" function inside another function is not working
On May 14, 2011, at 3:30 AM, utkarshsinghal wrote:> > Hi all, > I want to define a function such that one of its argument if > passed do one > thing and if not passed do the second thing.?missing> So basically, I have to check > whether the argument is passed or not inside the function. I am > trying to > use 'exists' function to do this. >> f = function(a,b){exists("b")} >> f(a=3, b=4) > [1] TRUE > This is working as expected. > But if I do the following: >> f(a=3) > [1] TRUE > Can anybody explain why this function is returning TRUE here. > -- > Many thanks, > Utkarsh > ______________________________________________ > R-help at 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.David Winsemius, MD West Hartford, CT
Might it be feasible to add, "See Also: missing" to the help page for "exists"? Currently, one can spend hours studying the help page for "exists" without getting a clue to the answer to the post copied below. Thanks, Spencer On 5/14/2011 3:30 AM, David Winsemius wrote:> > On May 14, 2011, at 3:30 AM, utkarshsinghal wrote: > >> >> Hi all, >> I want to define a function such that one of its argument if passed >> do one >> thing and if not passed do the second thing. > > ?missing > >> So basically, I have to check >> whether the argument is passed or not inside the function. I am >> trying to >> use 'exists' function to do this. >>> f = function(a,b){exists("b")} >>> f(a=3, b=4) >> [1] TRUE >> This is working as expected. >> But if I do the following: >>> f(a=3) >> [1] TRUE >> Can anybody explain why this function is returning TRUE here. >> -- >> Many thanks, >> Utkarsh >> ______________________________________________ >> R-help at 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. > > David Winsemius, MD > West Hartford, CT > > ______________________________________________ > R-help at 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. >
Maybe Matching Threads
- calling "exists" function inside another function is not working
- [Fwd: adding more columns in big.matrix object of bigmemory package]
- Splitting a vector into equal groups
- intermediate iterations of stepwise regression
- bigmemory - extracting submatrix from big.matrix object