Dear R users,

I wrote the following toy example to explain my problem :

a=0
f=function(x,y,z) {
    if (a==0) x[1]+x[2]+y
    if (a!=0) x[1]+x[2]+y+z
}
f(1:2,3)


I have not specified z and I get an error. Although a=0, R seems to want to
know z because it's in the expression x[1]+x[2]+y+z.

So I tried to put a default value :

a=0
f=function(x,y,z=0) {
    if (a==0) x[1]+x[2]+y
    if (a!=0) x[1]+x[2]+y+z
}
f(1:2,3)

Why isn't it working ? Sometimes everything is fine even though a parameter
is not specified.

Thanks a lot.

	[[alternative HTML version deleted]]

