Hello,

Oscar,  Thank you!

I'm relatively new on using spatial data into R, and I wasn't able to
figured out that the "evaluation used in layer is non-standard",... the
reason why the local variables were working fine until the layer method was
called.

Now (if someone else has this doubt in the future) this is the way for
using local data inside a function that calls the layer method: (the last
two lines on the previous example function):

layer(sp.points(*h1,* col='red', pch = 18)*, data = list(h1 = pDatos)*) +
layer(sp.text(coordinates*(h2*), round(h2$RS,0), adj=0, col='blue')*, data
= list(h2 = pDatos*))

Best,

--Vladimir

On Fri, Dec 14, 2012 at 6:47 PM, Oscar Perpiñan <oscar.perpinan@gmail.com>wrote:

> Hello,
>
> The layer function uses non-standard evaluation. The help page of layer
> says:
>
> "Note that the evaluation used in layer is non-standard and can be
> confusing at first: you typically refer to variables as if inside the panel
> function (x, y,etc);you can usually refer to objects which exist in the
> global environment(workspace),but it  is safer to pass them in by name in
> the data argument to layer.(And this should not to be confused with the
> data argument to the original xyplot.)"
>
> The last example of this help page will be useful for you.
>
> Best,
>
> Oscar.
> El 14/12/2012 18:33, "Vladimir Gutierrez Corea" <vladimir.gut@gmail.com>
> escribió:
>
>>  Dear All,
>>
>> I'm building a function for plotting some maps. This function get as
>> argument a variable and also create some local variables, but then when I
>> try to read these  variables through layer(sp.points(VARIABLE)), I got the
>> following error: Object 'VARIABLE' not found...
>>
>> here the code
>>
>> #-----------------------------------------------------------------------------
>> ShowInMap <- function(pDatos)
>> {
>>   coordinates(pDatos) <- c("COORDX", "COORDY")
>>   proj4string(pDatos) <- CRS("+init=epsg:4326")
>>   pDatos <- spTransform(pDatos,CRS("+init=epsg:23030"))
>>   browser()
>>   InterP.IDW <- krige(RS ~ 1, pDatos, gGrid)
>>   InterP <- InterP.IDW
>>   InterP[["IDW_pred"]] <- InterP.IDW$var1.pred
>>
>>   spplot(InterP, c("IDW_pred"), names.attr = c("IDW"), main = "(UTC)",
>> col.regions = grey(rev(seq(0,0.75,0.05)))) +
>>   layer(sp.polygons(gEsp, col='blue')) + # /* gEsp is a Global variable
>> and
>> this line works fine */
>>   layer(sp.polygons(gCyL, col='cyan')) + # /* gCyL is a Global variable
>> and
>> this line works fine */
>>   layer(sp.points(pDatos, col='red', pch = 18)) + #  / * HERE IS THE
>> PROBLEM with "pDatos", pDatos is working fine in all the other part of
>> code
>> */
>>   layer(sp.text(coordinates(pDatos), round(pDatos$RS,0), adj=0,
>> col='blue')) # / * HERE IS THE PROBLEM with "pDatos", pDatos is working
>> fine in all the other part of code */
>> }
>>
>> #-----------------------------------------------------------------------------
>>
>> It seems like if the following code: "layer(sp.points" is pointing to
>> other
>> environment than local environment of the function... If I change the code
>> for reading a global variable of course this works fine but I don't like
>> to
>> do a mess in the code by doing that!
>>
>> How can I manage that?
>> What can be the problem?
>> Is there a way to say "R" that "layer" and "sp.points" have to see this
>> local environment (like some kind of full-path)?
>>
>> Thanks in advance for your help
>>
>> Best regards,
>>
>> --
>> ************************************************************
>> Federico *Vladimir* Gutierrez Corea   www.vlado.es
>>
>> PhD Candidate at Technical University of Madrid (UPM)
>> MERCATOR Research Group
>> Campus SUR , Paseo de la Arboleda s/n.
>> E-28031 Madrid (Spain)
>> E-Mail: fv.gutierrez@upm.es
>> Ph.:  +34 91 331 1968  (University)
>> Fax.: +34 91 331 1968 (University)
>> ************************************************************
>> See *Vladimir* on Linked-In <http://es.linkedin.com/in/fvgutierrez>
>> See *Vladimir* on GeoI+D Research Center at
>> UPM<
>> http://www.upm.es/observatorio/vi/index.jsp?pageac=investigador.jsp&idInvestigador=11805
>> >
>> See *Vladimir* on Google-Scientific
>> Publications<
>> http://scholar.google.es/scholar?start=0&q=F.+Vladimir+Gutierrez-Corea&hl=en&as_sdt=1
>> >
>>
>> ************************************************************
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>


-- 
************************************************************
Federico *Vladimir* Gutierrez Corea   www.vlado.es
PhD Candidate at Technical University of Madrid (UPM)
MERCATOR Research Group
Campus SUR , Paseo de la Arboleda s/n.
E-28031 Madrid (Spain)
E-Mail: fv.gutierrez@upm.es
Ph.:  +34 91 331 1968  (University)
Fax.: +34 91 331 1968 (University)
************************************************************

	[[alternative HTML version deleted]]

