library(spacetime)

# generate test data
testsp <- SpatialPoints(expand.grid(1:5, 1:5))
testtime <- xts(1:25, seq(as.POSIXct("2011-01-01"),
                          as.POSIXct("2011-01-25"), by=3600*24))
testdata <- data.frame(test=rnorm(length(testsp)*nrow(testtime)))

# full space-time grid as STSDF
testSTSDF <- STSDF(testsp, testtime, testdata,
                   as.matrix(expand.grid(1:length(testsp),
                                         1:nrow(testtime))))

# subsetting
testSTSDF[1,] # works
testSTSDF[,1] # works
testSTSDF[1,1] # error in checkSlotAssignment(object, name, value),
               # fixed in line 70 of STSDF-methods.R
testSTSDF[1:10,5]
testSTSDF[1,1:10]
testSTSDF[1:10,1:5]

# sparse space-time grid as STSDF
samp <- sample(1:nrow(testdata), nrow(testdata)-10)
testSTSDF <- STSDF(testsp, testtime, testdata[samp,, drop=FALSE],
                   as.matrix(expand.grid(1:length(testsp),
                                         1:nrow(testtime))[samp,]))

# subsetting
testSTSDF[1,] # error in xts(x@data, index(x@time)) : NROW(x) must match length(order.by)
              # fixed in line 77 of STSDF-methods.R
testSTSDF[,1] # error in validityMethod(object) : 
  #number of rows in data.frame and SpatialPoints don't match
              # fixed in line 80 of STSDF-methods.R
testSTSDF[1,1] # 
testSTSDF[1:10,5]
testSTSDF[1,1:10]
testSTSDF[1:10,1:5]
