[R-sig-Geo] inconsistent as.data.frame(SpatialPointsDF)

dschneiderch Dominik.Schneider at colorado.edu
Fri Mar 20 18:18:54 CET 2015


I just went through my packages, iteratively unloading each one with:
detach('package:raster')
and found that if I unload the raster package then the expected behavior of
keeping the existing coordnames is achieved.

now why that differs in my script I have no idea.

> coordnames(snotellocs)
[1] "Longitude" "Latitude"
> detach('package:raster')
> head(as.data.frame(snotellocs))
  network State Station_ID Site_ID       Site_Name Latitude Longitude
1    SNTL    AZ     11R06S     308     BAKER BUTTE 34.45660 -111.4064
2    SNTL    AZ     11R07S    1140 BAKER BUTTE SMT 34.45547 -111.3827
3    SNTL    AZ     09S01S     310           BALDY 33.97883 -109.5034
4    SNTL    AZ     09S06S     902     BEAVER HEAD 33.69144 -109.2166
5    SNTL    AZ     09N05S    1143   BEAVER SPRING 36.32678 -109.0571
6    SNTL    AZ     12P01S    1139       CHALENDER 35.26247 -112.0623
  Elevation_ft Elevation_m
1         7300        2225
2         7700        2347
3         9125        2781
4         7990        2435
5         9200        2804
6         7100        2164
>

Dominik Schneider
o 303.735.6296 | c 518.956.3978


On Fri, Mar 20, 2015 at 11:02 AM, dschneiderch [via R-sig-geo] <
ml-node+s2731867n7587929h1 at n2.nabble.com> wrote:

> Edzer - Look like we posted at the same time.
> In my example my coordinates are named, no?
>
> I tried your example in my R environment and can replicate the behavior I
> mentioned.
>
> > df = data.frame(x=1:2, y=2:1, z = 3:4)
> > df1 = df
> > library(sp)
> > coordinates(df1) = ~x+y
> > as.data.frame(df1)
>   x y z
> 1 1 2 3
> 2 2 1 4
> > coordnames(df1)
> [1] "x" "y"
> > coordnames(df1)=c('long','lat')
> > str(df1)
> Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
>   ..@ data       :'data.frame': 2 obs. of  1 variable:
>   .. ..$ z: int [1:2] 3 4
>   ..@ coords.nrs : int [1:2] 1 2
>   ..@ coords     : num [1:2, 1:2] 1 2 2 1
>   .. ..- attr(*, "dimnames")=List of 2
>   .. .. ..$ : NULL
>   .. .. ..$ : chr [1:2] "long" "lat"
>   ..@ bbox       : num [1:2, 1:2] 1 1 2 2
>   .. ..- attr(*, "dimnames")=List of 2
>   .. .. ..$ : chr [1:2] "long" "lat"
>   .. .. ..$ : chr [1:2] "min" "max"
>   ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
>   .. .. ..@ projargs: chr NA
> > as.data.frame(df1)
>   x y z
> 1 1 2 3
> 2 2 1 4
>
>
> Interestingly, when I open a new R instance and without loading all the
> packages associated with my project, the names are *not* converted.  So it
> seems that one of the packages I have loaded is conflicting with sp and
> causing the names to change...  my sessionInfo() was attached in the other
> post.
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://r-sig-geo.2731867.n2.nabble.com/inconsistent-as-data-frame-SpatialPointsDF-tp7587920p7587929.html
>  To unsubscribe from inconsistent as.data.frame(SpatialPointsDF), click
> here
> <http://r-sig-geo.2731867.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=7587920&code=RG9taW5pay5TY2huZWlkZXJAY29sb3JhZG8uZWR1fDc1ODc5MjB8LTEwMzMyMTA1OQ==>
> .
> NAML
> <http://r-sig-geo.2731867.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/inconsistent-as-data-frame-SpatialPointsDF-tp7587920p7587931.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list