Sylvain Antoniazza
2011-Nov-27 15:32 UTC
[R] conflict when passing an argument to a function within an other function
Dear all, I have a problem with this piece of code which I don't really see how to overcome and I think it might also be of more general interest: map(xlim=c(-10,40),ylim=c(30,60) ,mar=rep(0,4)+.1 ,fill=T ,col="darkseagreen" ,bg="skyblue" ) The idea is to use the map function from the maps package to draw a map of Europe. By default with the argument fill=T there is border to the polygones and I want them without border. Here is the start of the problems. The polygone function used in map function has a border argument that can deal with that issue, the problem is that this argument cannot be passed to map directly because map also has a border argument for another purpose (I tried with the density argument for polygone passed to map and here it is working (because map don't have a density argument itself)). Is there any way to pass a border argument to the polygone function within map??? Thanks in advance for your help. Cheers, Sylvain. PS: for the moment I used a trick with the fg argument passed to par which allows to pass a colour for the border of the polygons. -- *Sylvain Antoniazza* PhD student & assistant University of Lausanne, Switzerland http://www.unil.ch/dee/page55408_fr.html [[alternative HTML version deleted]]
Duncan Murdoch
2011-Nov-27 17:35 UTC
[R] conflict when passing an argument to a function within an other function
On 11-11-27 10:32 AM, Sylvain Antoniazza wrote:> Dear all, > > I have a problem with this piece of code which I don't really see how to > overcome and I think it might also be of more general interest: > > map(xlim=c(-10,40),ylim=c(30,60) > ,mar=rep(0,4)+.1 > ,fill=T > ,col="darkseagreen" > ,bg="skyblue" > ) > > The idea is to use the map function from the maps package to draw a map of > Europe. By default with the argument fill=T there is border to the > polygones and I want them without border. Here is the start of the problems. > > The polygone function used in map function has a border argument that can > deal with that issue, the problem is that this argument cannot be passed to > map directly because map also has a border argument for another purpose (I > tried with the density argument for polygone passed to map and here it is > working (because map don't have a density argument itself)).For problems like this you need to look at the source code. map() calls polygon(), passing ... to it. So you want border in the ..., but since border is an argument to map, it is already taken. So make use of partial argument matching. Pass border to map, and bord or borde to polygon: map(xlim=c(-10,40),ylim=c(30,60) ,mar=rep(0,4)+.1 ,fill=T ,col="darkseagreen" ,bg="skyblue" ,border=0.01, borde=FALSE) The first one matches border, the second gets passed to polygon. Duncan Murdoch> > Is there any way to pass a border argument to the polygone function within > map??? > > Thanks in advance for your help. > > Cheers, Sylvain. > > PS: for the moment I used a trick with the fg argument passed to par which > allows to pass a colour for the border of the polygons. >