Question

I am trying to make spatstat hyperframes from lists hyperframes containing of owin objects (or any spatstat objects for that matter), but face unexpected behavior when using rbind.hyperframe command in do.call to bind the lists into a larger hyperframe:

library(spatstat)
circles <- list(large = disc(10), medium = disc(5), small = disc(1))

circle.list <- lapply(names(circles), function(k) hyperframe(name = k, circle = circles[[k]]))
circle.list

# [[1]]
# Hyperframe:
#   name circle
# 1 large (owin)

At this point the list works as it should. owin objects are separately in each cell of the listed hyperframes:

circle.list[[1]]$circle

#window: polygonal boundary
#enclosing rectangle: [-10, 10] x [-10, 10] units  

Next I use do.call command to rbind the hyperframes:

circle.hyperframe <- do.call(rbind.hyperframe, circle.list)
circle.hyperframe

# Hyperframe:
#    name circle
# 1  large (list)
# 2 medium (list)
# 3  small (list)

Now the circles are lists (what they essentially are in spatstat), but it seems that all of them are bound together:

names(circle.hyperframe[1,]$circle)
# [1] "type"   "xrange" "yrange" "bdry"   "units"  "type"   "xrange" "yrange" "bdry"  
# [10] "units"  "type"   "xrange" "yrange" "bdry"   "units" 

Note triplicate names for one cell.

My code relies on lists and I would very much like to be able to bind these lists together into a larger hyperframe. Is there a way around this behavior, i.e how to rbind the hyperframes without binding the cells in 'circle' column?

Was it helpful?

Solution

I agree that this behaviour is unexpected, and I don't know the explanation at the moment. There is a simple solution for your example, but I'm not sure it is useful in a more general setting where you probably need it:

library(spatstat)
circles <- list(large = disc(10), medium = disc(5), small = disc(1))
circle.hyperframe <- hyperframe(name=names(circles), circle=circles)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top