Dear Juan,

You have to define your function like this:

fun <- function (x,y=0, ...) {
       x+y
}

The ... means that u can use the other parameters in par!
The variables, which you want to use, these you have to define in your
function!

In this function i put y=0 on a standard value zero,

if u try now fun(2), the result will be: 2
if u try fun(2,4), then the result will be: 6

Kind Regards,
Alin Soare

2007/4/17, Juan Lewinger <lewinger@usc.edu>:
>
> Dear R list,
>
> I've read the function writing sections on both "An introduction to R" and
> "R language Definition" manuals but still don't understand why the following
> gives an error message:
>
> fun <- function(x, ...) x + y
> fun(1, y=2)
>
> I get:
>
> Error in fun(1, y = 2) : object "y" not found
>
> I'd appreciate any help in understanding this.
>
> R version 2.4.1 (2006-12-18)
> i386-pc-mingw32
> ...
>
> Juan Pablo Lewinger
> Department of Preventive Medicine
> Keck School of Medicine
> University of Southern California
> 1540 Alcazar Street, CHP-220
> Los Angeles, CA 90089-9011, USA
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>

	[[alternative HTML version deleted]]

