https://github.com/cran/fields
Tip revision: 6c8b30169bba182a68765ee3cb9b4e2ef7d38332 authored by Doug Nychka on 16 November 2011, 00:00:00 UTC
version 6.6.3
version 6.6.3
Tip revision: 6c8b301
parse.grid.list.R
# fields, Tools for spatial data
# Copyright 2004-2011, Institute for Mathematics Applied Geosciences
# University Corporation for Atmospheric Research
# Licensed under the GPL -- www.gpl.org/licenses/gpl.html
"parse.grid.list" <- function(grid.list, order.variables = "xy") {
#
# utility to find the x and y sequences in grid.list
# this is used in predict.surface and as.surface
#
M <- length(grid.list)
gcounts <- unlist(lapply(grid.list, FUN = length))
xy <- (1:M)[gcounts > 1]
if (length(xy) > 2) {
stop("only two components of the grid list\ncan have more than one element")
}
#
# swap the roles of x and y
if (order.variables == "yx") {
xy <- xy[2:1]
}
#
#
# here is the good stuff
#
nx <- gcounts[xy[1]]
ny <- gcounts[xy[2]]
x <- grid.list[[xy[1]]]
y <- grid.list[[xy[2]]]
#
# extract the names of the x and y components of the
# list
#
xlab <- names(grid.list)[xy[1]]
ylab <- names(grid.list)[xy[2]]
xlab <- ifelse(is.null(xlab), "X", xlab)
ylab <- ifelse(is.null(ylab), "Y", ylab)
list(x = x, y = y, nx = nx, ny = ny, xlab = xlab, ylab = ylab,
xy = xy)
}