[R-sig-Geo] change in sp::Lines() breaks example in my package
Michael Friendly
friendly at yorku.ca
Wed Jul 28 23:22:16 CEST 2010
Thanks, Edzer
What was not clear from either the documentation or the error message
was what you just
said: "each Lines *colllection* only has a single ID" . The .Rd just says
|ID| a unique character identifier
but 'unique' in what context? help(Lines) gives no examples, so there
was no way for me to figure this out.
It might help to revise the documentation, and you are welcome to use
any part of this example if
it helps. At a minimum, if I understand correctly, I suggest something like
|ID| a single character identifier, unique among other SpatialLines objects,
applying to the collection of lines in \code{slinelist}
Your 'short way out' works for me, and I have no need to index
particular streets.
best,
-Michael
Edzer Pebesma wrote:
> Michael, indeed a check was added recently to make sure that each Lines
> colllection only has a single ID; I don't believe the array of IDs you
> passed it had the effect you desired.
>
> The short way out would be to have a simple
>
> Lsl1 <- Lines(Ll1,"Streets")
>
> but the nicer way assigns street IDs to individual streets:
>
> i = 0
> Lsl1 <- lapply(slist, function(x) {
> i <<- i+1
> Lines(Line(x), as.character(i))
> })
> rm(i)
> Snow.streets.sp <- SpatialLines(Lsl1)
>
> which now lets you index Snow.streets.sp, as in
>
> Snow.streets.sp[100] # or
> Snow.streets.sp["100"]
>
> BTW it's the first time I advice someone to use <<- and I'd be happy for
> a suggestion to get rid of it!
>
> On 07/27/2010 04:22 PM, Michael Friendly wrote:
>
>> [Running R.2.11.1, Win XP]
>>
>> I just updated sp from sp_0.9-65 to sp_0.9-66 after receiving a report
>> from the CRAN team that my HistData
>> package now generates errors in at least one documentation example. It
>> occurs in example(Snow), which
>> worked successfully under the previous versions of sp. I don't
>> understand the nature of the error, or how to
>> correct it. Can someone point me in a useful direction?
>>
>> Here is the complete portion of the example (to draw Snow's cholera map
>> of London), suitable for cut/paste to R:
>>
>> #install.packages("HistData") # if necessary
>> library(HistData)
>> library(sp)
>>
>> # streets
>> slist <-
>> split(Snow.streets[,c("x","y")],as.factor(Snow.streets[,"street"]))
>> Ll1 <- lapply(slist,Line)
>> Lsl1 <- Lines(Ll1,paste("Street",1:length(Ll1)))
>> Snow.streets.sp <- SpatialLines(list(Lsl1))
>> plot(Snow.streets.sp, col="gray")
>> title(main="Snow's Cholera Map of London")
>>
>> # deaths
>> Snow.deaths.sp = SpatialPoints(Snow.deaths[,c("x","y")])
>> plot(Snow.deaths.sp, add=TRUE, col ='red', pch=15, cex=0.6)
>>
>> # pumps
>> spp <- SpatialPoints(Snow.pumps[,c("x","y")])
>> Snow.pumps.sp <- SpatialPointsDataFrame(spp,Snow.pumps[,c("x","y")])
>> plot(Snow.pumps.sp, add=TRUE, col='blue', pch=17, cex=1.5)
>> text(Snow.pumps[,c("x","y")], labels=Snow.pumps$label, pos=1, cex=0.8)
>>
>> Here is the transcript showing the error with Lines:
>>
>>
>>> # streets
>>> slist <-
>>>
>> split(Snow.streets[,c("x","y")],as.factor(Snow.streets[,"street"]))
>>
>>> Ll1 <- lapply(slist,Line)
>>> Lsl1 <- Lines(Ll1,paste("Street",1:length(Ll1)))
>>>
>> Error in Lines(Ll1, paste("Street", 1:length(Ll1))) : Single ID required
>>
>>> Snow.streets.sp <- SpatialLines(list(Lsl1))
>>>
>> Error in is.vector(X) : object 'Lsl1' not found
>>
>> Some tests:
>>
>>> length(Ll1)
>>>
>> [1] 528
>>
>>> length(unique(paste("Street",1:length(Ll1))))
>>>
>> [1] 528
>>
>> Below is my sessionInfo():
>>
>>
>>> sessionInfo()
>>>
>> R version 2.11.1 (2010-05-31)
>> i386-pc-mingw32
>>
>> locale:
>> [1] LC_COLLATE=English_United States.1252
>> [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United
>> States.1252
>> [4] LC_NUMERIC=C [5] LC_TIME=English_United
>> States.1252
>> attached base packages:
>> [1] stats graphics grDevices utils datasets methods base
>> other attached packages:
>> [1] sp_0.9-66 KernSmooth_2.23-3 HistData_0.6-8
>> loaded via a namespace (and not attached):
>> [1] grid_2.11.1 lattice_0.18-8 tools_2.11.1 >
>>
>>
>
>
--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street Web: http://www.datavis.ca
Toronto, ONT M3J 1P3 CANADA
More information about the R-sig-Geo
mailing list