[R-sig-Geo] spdep and server

jon.skoien at jrc.ec.europa.eu jon.skoien at jrc.ec.europa.eu
Thu Dec 1 17:23:57 CET 2011


Hi Matilde,
see inline comments below.

On 01-Dec-11 15:45, Matilde Karakachoff wrote:
> Ok, I’m sorry. I think that there was a little problem with my 
> previous message.
>
> I’m trying to execute some R commands on a linux server (where I 
> installed R and packages previously) to create a SpatialGridDataFrame. 
> It has to be a grid 10*10 to which I will associate data resulting 
> from simulations of the spatial distribution of genotypic data (Fregene).
>
>
> Some lines and columns of my data frame:
> coord    x    y    f.all1s1    f.all2s1
> 4040    40    40    0,665    0,335    0,05346675
> 4041    40    41    0,72    0,28    0,049152
> 4042    40    42    0,825    0,175    0,04141875
> 4043    40    43    0,81    0,19    0,042483
> 4044    40    44    0,82    0,18    0,041772
> 4045    40    45    0,59    0,41    0,059643
> 4046    40    46    0,585    0,415    0,06006675
> 4047    40    47    0,405    0,595    0,07632075
>
> My script:
>> library(spdep)
>> Locus1 <- read.csv2(file='data.csv', head=T)
>> coordinates(Locus1) <- c('x', 'y')
>> Locus1.sp <- as(Locus1, 'SpatialPixels')
>> Locus1.gr <- as(Locus1.sp, 'SpatialGridDataFrame')

What has happened here is that you first create a spatial object with 
coordinates(). Then you strip off the data with as(Locus1, 
'SpatialPixels'). The last line throws an error because you try to 
coerce a SpatialPixels-object without data into a SpatialGridDataFrame 
which needs a data slot.

The lines above would probably work if you changed SpatialPixels with 
SpatialPixelsDataFrame in line 4. But you can also try:
Locus1 <- read.csv2(file='data.csv', head=T)
gridded(Locus1) = ~x+y # Set coordinates and create 
SpatialPixelsDataFrame immediately
fullgrid(Locus1) = TRUE # change to SpatialGridDataFrame

>
> The first four lines are ok, but the last one gives the following error:
>
> Error in asMethod(object, Class, value) : replace-coercion not allowed
>
> But if I run it on my computer it works. So, why it doesn’t work on a 
> server? May be the ‘spdep’ package doesn't work in the same way on linux?

This shouldnt be different between different installations of R, but 
maybe there was something in your workspace that made it work on your 
computer?

Cheers,
Jon


-- 
Jon Olav Skøien
Joint Research Centre - European Commission
Institute for Environment and Sustainability (IES)
Global Environment Monitoring Unit

Via Fermi 2749, TP 440,  I-21027 Ispra (VA), ITALY

jon.skoien at jrc.ec.europa.eu
Tel:  +39 0332 789206

Disclaimer: Views expressed in this email are those of the individual and do not necessarily represent official views of the European Commission.



More information about the R-sig-Geo mailing list