Hi,

You need to specify that a is an argument to the function:

On Thu, Sep 12, 2013 at 3:56 PM, Gang Peng <michael.gang.p...@gmail.com> wrote:
> For example:
>
> a <- 1
>
> f <- function(b){
>     return(a+b)
> }
>

f <- function(b, a) {
    return(a+b)
}

> when we call function f(2), r will search the local environment first, if
> it cannot find a, it will search global environment, and return 3. How to
> avoid r searching the global environment and return an error when we call
> this function?

The function will now give an error if a is not specified.

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org

______________________________________________
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.

Reply via email to