Title: | Virtual Arrays |
---|---|
Description: | The base class 'VirtualArray' is defined, which acts as a wrapper around lists allowing users to fold arbitrary sequential data into n-dimensional, R-style virtual arrays. The derived 'XArray' class is defined to be used for homogeneous lists that contain a single class of objects. The 'RasterArray' and 'SfArray' classes enable the use of stacked spatial data instead of lists. |
Authors: | Adam T. Kocsis [cre, aut] , Deutsche Forschungsgemeinschaft [fnd], FAU GeoZentrum Nordbayern [fnd] |
Maintainer: | Adam T. Kocsis <[email protected]> |
License: | CC BY 4.0 |
Version: | 0.2.0 |
Built: | 2024-11-06 03:27:02 UTC |
Source: | https://github.com/adamkocsis/via |
Single bracket '['
refers to indices and names within the 'VirtualArray
'-class object. Use double brackets to extract layers based on their names (in the @stack
).
## S4 method for signature 'VirtualArray,ANY,ANY' x[i, j, ..., drop = TRUE]
## S4 method for signature 'VirtualArray,ANY,ANY' x[i, j, ..., drop = TRUE]
x |
An object from a |
i |
subscript of the first dimension(rows) or vector-like subsetting. |
j |
subscript of the second dimension (columns). |
... |
subscript of additional dimensions. |
drop |
|
An object from either the same class as x
or the class of its elements.
ex <- rastex() # numeric subsetting firstThree <- ex[1:3] # character subsetting second <- ex["d"] # logical subsetting subscript <- rep(FALSE, length(ex)) subscript[2] <- TRUE second2 <- ex[subscript] data(paleocoastlines) present<- paleocoastlines["0", ] allMargin <- paleocoastlines[, "margin"]
ex <- rastex() # numeric subsetting firstThree <- ex[1:3] # character subsetting second <- ex["d"] # logical subsetting subscript <- rep(FALSE, length(ex)) subscript[2] <- TRUE second2 <- ex[subscript] data(paleocoastlines) present<- paleocoastlines["0", ] allMargin <- paleocoastlines[, "margin"]
VirtualArray
'-derived class object.Double bracket '[['
refers to elements'/layers' name in the @stack
of the 'VirtualArray
'-derived object. Use single brackets to extract elements based on their position in the 'VirtualArray
'.
## S4 method for signature 'VirtualArray,ANY,ANY' x[[i, drop = TRUE]]
## S4 method for signature 'VirtualArray,ANY,ANY' x[[i, drop = TRUE]]
x |
|
i |
subscript of the first dimension(rows) or vector-like subsetting. |
drop |
|
A VirtualArray
-derived class object, or an object of the class that makes up the VirtualArray
data(exemplar) # finds a layer exemplar[["sample1"]] # returns a stack exemplar[[c("sample1", "sample2")]] # replaces a layervalues, but not the attributes of the layer exemplar2 <- exemplar exemplar2[["sample1"]] <- exemplar2[["sample2"]] # compare every value in the they are all the same exemplar2[["sample1"]]$x == exemplar2[["sample2"]]$x
data(exemplar) # finds a layer exemplar[["sample1"]] # returns a stack exemplar[[c("sample1", "sample2")]] # replaces a layervalues, but not the attributes of the layer exemplar2 <- exemplar exemplar2[["sample1"]] <- exemplar2[["sample2"]] # compare every value in the they are all the same exemplar2[["sample1"]]$x == exemplar2[["sample2"]]$x
VirtualArray
'-class objects.Double bracket '[['
refers to layers' name in the names of the @stack
member of the 'VirtualArray
'. Use single brackets to replace elements based on their position in the 'VirtualArray
'-class object.
## S4 replacement method for signature 'VirtualArray,ANY' x[[i]] <- value
## S4 replacement method for signature 'VirtualArray,ANY' x[[i]] <- value
x |
Object from a class derived from |
i |
subscript of layers to replace. |
value |
|
The function has no return value.
VirtualArray
'.Single bracket '['
refers to indices and names within the 'VirtualArray
'-class object. Use double brackets to replace layers based on their names (in the @stack
).
Object types of the same kind class can be used to replace values in 'XArray
'-class objects. 'SpatRaster
'-class objects can be used to replace values in 'RasterArray
'-class objects. Classes inheriting from 'sf
' can be used with 'SfArray
'-class objects.
## S4 replacement method for signature 'VirtualArray,ANY,ANY,logical' x[i, j, ...] <- value ## S4 replacement method for signature 'RasterArray,ANY,ANY,SpatRaster' x[i, j, ...] <- value ## S4 replacement method for signature 'SfcArray,ANY,ANY,sfc' x[i, j, ...] <- value ## S4 replacement method for signature 'SfArray,ANY,ANY,sf' x[i, j, ...] <- value
## S4 replacement method for signature 'VirtualArray,ANY,ANY,logical' x[i, j, ...] <- value ## S4 replacement method for signature 'RasterArray,ANY,ANY,SpatRaster' x[i, j, ...] <- value ## S4 replacement method for signature 'SfcArray,ANY,ANY,sfc' x[i, j, ...] <- value ## S4 replacement method for signature 'SfArray,ANY,ANY,sf' x[i, j, ...] <- value
x |
|
i |
subscript of the first dimension(rows) or vector-like subsetting. |
j |
subscript of the second dimension (columns). |
... |
subscript of additional dimensions. |
value |
A same class object as |
The function has no return value.
ex <- rastex() # replace third element with missing value ex[3] <- NA # duplicate first element and make it the second too ex[2] <- ex[1] ex
ex <- rastex() # replace third element with missing value ex[3] <- NA # duplicate first element and make it the second too ex[2] <- ex[1] ex
RasterArray
'-class objectThe method is inherited from the 'SpatRaster
' class.
## S4 method for signature 'RasterArray' aggregate(x, ...)
## S4 method for signature 'RasterArray' aggregate(x, ...)
x |
a |
... |
arguments passed to the |
An aggregated RasterArray
-class object.
library(terra) ex <- rastex() agg <- aggregate(ex, 30)
library(terra) ex <- rastex() agg <- aggregate(ex, 30)
SfcArray
or SfArray
objectCoerce into an SfcArray
or SfArray
object
Coerce into an SfArray or SfcArray object
as.XArray(from) ## S4 method for signature 'SfcArray' as.XArray(from) ## S4 method for signature 'SfArray' as.XArray(from) as.SfcArray(from) ## S4 method for signature 'XArray' as.SfcArray(from) ## S4 method for signature 'SfArray' as.SfcArray(from) as.SfArray(from) ## S4 method for signature 'XArray' as.SfArray(from) ## S4 method for signature 'SfcArray' as.SfArray(from)
as.XArray(from) ## S4 method for signature 'SfcArray' as.XArray(from) ## S4 method for signature 'SfArray' as.XArray(from) as.SfcArray(from) ## S4 method for signature 'XArray' as.SfcArray(from) ## S4 method for signature 'SfArray' as.SfcArray(from) as.SfArray(from) ## S4 method for signature 'XArray' as.SfArray(from) ## S4 method for signature 'SfcArray' as.SfArray(from)
from |
Either a SfcArray
, SfArray
or XArray
-class object
VirtualArray
'-class object with other objectsNOTE: Sequences that start with an NA
do not yet work.
## S4 method for signature 'VirtualArray' c(x, ...)
## S4 method for signature 'VirtualArray' c(x, ...)
x |
|
... |
additional objects to combine. |
A VirtualArray
-class object.
VirtualArray
'-derived class object.Get or set the column names of two-dimensional 'VirtualArray
'-derived class objects
## S4 method for signature 'VirtualArray' colnames(x) ## S4 replacement method for signature 'VirtualArray' colnames(x) <- value
## S4 method for signature 'VirtualArray' colnames(x) ## S4 replacement method for signature 'VirtualArray' colnames(x) <- value
x |
|
value |
|
A character
vector of column names or NULL
.
data(paleocoastlines) colnames(paleocoastlines) colnames(paleocoastlines) <- c("a", "b")
data(paleocoastlines) colnames(paleocoastlines) colnames(paleocoastlines) <- c("a", "b")
RasterArray
'-class objectThe method is inherited from the 'SpatRaster
' class.
## S4 method for signature 'RasterArray' crop(x, y, ...)
## S4 method for signature 'RasterArray' crop(x, y, ...)
x |
a |
y |
an |
... |
arguments passed to the |
A cropped RasterArray
-class object.
ex <- rastex() # crop to a specific area if(requireNamespace("terra", quietly=TRUE)){ ext <- terra::ext(c( xmin = 106.58, xmax = 157.82, ymin = -45.23, ymax = 1.14 )) # cropping all au<- crop(ex, ext) }
ex <- rastex() # crop to a specific area if(requireNamespace("terra", quietly=TRUE)){ ext <- terra::ext(c( xmin = 106.58, xmax = 157.82, ymin = -45.23, ymax = 1.14 )) # cropping all au<- crop(ex, ext) }
VirtualArray
'-derived class objectsThe function returns the dimensions of the array in which elements are organized.
## S4 method for signature 'VirtualArray' dim(x)
## S4 method for signature 'VirtualArray' dim(x)
x |
A |
A numeric
vector.
data(exemplar) dim(exemplar)
data(exemplar) dim(exemplar)
VirtualArray
'-class objectThe funcion will return the dimensions 'SpatRaster
'-class layers.
dimlayer(x, ...) ## S4 method for signature 'RasterArray' dimlayer(x)
dimlayer(x, ...) ## S4 method for signature 'RasterArray' dimlayer(x)
x |
A |
... |
additional arguments passed to class-specific methods. |
A numeric
vector with the number of rows and columns in the VirtualArray
s.
VirtualArray
'-derived class object.Get or set the dimnames of multidimensional VirtualArray
-derived class object.
## S4 method for signature 'VirtualArray' dimnames(x) ## S4 replacement method for signature 'VirtualArray' dimnames(x) <- value
## S4 method for signature 'VirtualArray' dimnames(x) ## S4 replacement method for signature 'VirtualArray' dimnames(x) <- value
x |
|
value |
|
A list
of character
vectors or NULL
.
ex <- rastex() dimnames(ex) data(paleocoastlines) dimnames(paleocoastlines) dimnames(paleocoastlines)[[2]] <- c("first", "second") names(dimnames(paleocoastlines)) <- c("age", "type")
ex <- rastex() dimnames(ex) data(paleocoastlines) dimnames(paleocoastlines) dimnames(paleocoastlines)[[2]] <- c("first", "second") names(dimnames(paleocoastlines)) <- c("age", "type")
RasterArray
'-class objectThe method is inherited from the 'SpatRaster
' class.
## S4 method for signature 'RasterArray' disagg(x, ...)
## S4 method for signature 'RasterArray' disagg(x, ...)
x |
a |
... |
arguments passed to the |
A disaggregated RasterArray
class object.
ex <- rastex() disagg <- disagg(ex, 3)
ex <- rastex() disagg <- disagg(ex, 3)
XArray
'-class objectA 'XArray
'-class objects of data.frame
s, which were made from a single data.frame
with random sampling. The original object had two columns, the first (x
) an integer seqence 1:100
, the second y
a variable produced with 0.5 * x -30 + N(0,10)
.
data(exemplar)
data(exemplar)
: XArray
with 3 sample sizes (rows), and 4 different seeds (column).
RasterArray
'-class objectThe method is inherited from the 'SpatRaster
' class.
## S4 method for signature 'RasterArray' ext(x, ...)
## S4 method for signature 'RasterArray' ext(x, ...)
x |
a |
... |
arguments passed to the |
An aggregated RasterArray
-class object.
ex <- rastex() extent <- ext(ex)
ex <- rastex() extent <- ext(ex)
RasterArray
'-class objectThe function behaves similar to the regular is.na()
function applied to the proxy object of a 'RasterArray
'.
## S3 method for class 'RasterArray' is.na(x)
## S3 method for class 'RasterArray' is.na(x)
x |
A |
A logical
vector
, matrix
or array
matching the structure of the RasterArray
.
ex <- rastex() ex[2] <- NA is.na(ex)
ex <- rastex() ex[2] <- NA is.na(ex)
stack
of a 'VirtualArray
'-class objectNames of layers in the stack
of a 'VirtualArray
'-class object
layers(x, ...) ## S4 method for signature 'VirtualArray' layers(x)
layers(x, ...) ## S4 method for signature 'VirtualArray' layers(x)
x |
A |
... |
additional arguments passed to class-specific methods. |
A character
vector of names.
# names of layers in the stack data(exemplar) layers(exemplar)
# names of layers in the stack data(exemplar) layers(exemplar)
VirtualArray
'-derived class objects.Get or set the names of one-dimensional 'VirtualArray
'-derived class objects
## S4 method for signature 'VirtualArray' names(x) ## S4 replacement method for signature 'VirtualArray' names(x) <- value
## S4 method for signature 'VirtualArray' names(x) ## S4 replacement method for signature 'VirtualArray' names(x) <- value
x |
|
value |
|
A character
vector of names or NULL
.
ex <- rastex() names(ex) names(ex)[4] <- "weirdo" # NULL
ex <- rastex() names(ex) names(ex)[4] <- "weirdo" # NULL
RasterArray
'-class objectThe method is inherited from the 'SpatRaster
' class.
## S4 method for signature 'RasterArray' ncell(x)
## S4 method for signature 'RasterArray' ncell(x)
x |
a |
A numeric
value.
ex <- rastex() ncell(ex)
ex <- rastex() ncell(ex)
VirtualArray
'-derived class object.Unlike the ncol
and nrow
functions of the 'terra
' package, this function returns the number of columns and rows of the 'VirtualArray
'-derived container, rather than the dimensions of the contained 'SpatRaster
'-class object.
## S4 method for signature 'VirtualArray' ncol(x) ## S4 method for signature 'VirtualArray' nrow(x)
## S4 method for signature 'VirtualArray' ncol(x) ## S4 method for signature 'VirtualArray' nrow(x)
x |
A |
A numeric
value of the number of columns and rows.
data(paleocoastlines) ncol(paleocoastlines) nrow(paleocoastlines)
data(paleocoastlines) ncol(paleocoastlines) nrow(paleocoastlines)
The function restructures a matrix
and extends its current limits to a range defined by a names attribute
newbounds(x, cols = NULL, rows = NULL)
newbounds(x, cols = NULL, rows = NULL)
x |
The matrix to be restructured. |
cols |
Column names guiding the restructuring. |
rows |
Row names guiding the restructuring. |
This is essentially a subsetting function that allows you to subset even when the rownames or colnames vector extends beyond the bounds of a matrix and traditional subsetting methods result in the notorious 'out of bounds' error.
A matrix with extended bounds.
a<-matrix(1:9, ncol=3) rownames(a) <- c("a", "c", "d") newbounds(a, rows=letters[1:5])
a<-matrix(1:9, ncol=3) rownames(a) <- c("a", "c", "d") newbounds(a, rows=letters[1:5])
VirtualArray
'-derived class objectFunction to return the length of the array in which elements are organized.
nlayers(x) ## S4 method for signature 'list' nlayers(x) ## S4 method for signature 'SpatRaster' nlayers(x) ## S4 method for signature 'VirtualArray' length(x) ## S4 method for signature 'XArray' nlayers(x) ## S4 method for signature 'RasterArray' nlayers(x)
nlayers(x) ## S4 method for signature 'list' nlayers(x) ## S4 method for signature 'SpatRaster' nlayers(x) ## S4 method for signature 'VirtualArray' length(x) ## S4 method for signature 'XArray' nlayers(x) ## S4 method for signature 'RasterArray' nlayers(x)
x |
a |
The length()
function returns the number elements that should be present based on the array structure itself, and not the total number of values stored in the object. As the object can contain missing values, the number of actual layers can be queried with nlayers
.
A numeric
value.
ex <- rastex() # omit third element ex[3] <- NA # number of elements in the RasterArray length(ex) # remaining number values in the stack length(ex@stack) # the number of remaining layers in the RasterArray nlayers(ex)
ex <- rastex() # omit third element ex[3] <- NA # number of elements in the RasterArray length(ex) # remaining number values in the stack length(ex@stack) # the number of remaining layers in the RasterArray nlayers(ex)
The set of functions return names of objects directly cast to numeric values.
nums(x) colnums(x) rownums(x)
nums(x) colnums(x) rownums(x)
x |
Object with names, colnames or rownames attributes. |
Numeric vector.
# base R object a <- 1:10 names(a) <- seq(10, 100, 10) nums(a) # XArray data(exemplar) colnums(exemplar) rownums(exemplar)
# base R object a <- 1:10 names(a) <- seq(10, 100, 10) nums(a) # XArray data(exemplar) colnums(exemplar) rownums(exemplar)
RasterArray
'-class objectThe total number of values in a 'RasterArray
'-class object
nvalues(x, ...) ## S4 method for signature 'RasterArray' nvalues(x)
nvalues(x, ...) ## S4 method for signature 'RasterArray' nvalues(x)
x |
A |
... |
additional arguments passed to class-specific methods. |
A numeric
value.
ex <- rastex() nvalues(ex)
ex <- rastex() nvalues(ex)
A dataset containing the coastline reconstructions based on the PaleoMAP PaleoDEMS https://www.earthbyte.org/paleodem-resource-scotese-and-wright-2018/ and the Paleobiology Database https://paleobiodb.org for 0, 10 and 20Ma.
data(paleocoastlines)
data(paleocoastlines)
A SfcArray
with 3 continental margin and 3 paleocoastline layers (3 rows and 2 columns).
This is version v7. The article describing the entire set is under review. Once that is published, the entire dataset will be available.
Kocsis, A. T., & Scotese, C. R. (2020). PaleoMAP PaleoCoastlines data [Data set]. Zenodo. https://doi.org/10.5281/zenodo.3903164
RasterArray
'-class objectThe method implemets the project
function for 'RasterArray
'-class objects.
The method is inherited from the 'SpatRaster
' class. See project
for details.
project ## S4 method for signature 'RasterArray' project(x, y, ...)
project ## S4 method for signature 'RasterArray' project(x, y, ...)
x |
A |
y |
A |
... |
additional arguments as for |
An object of class standardGeneric
of length 1.
A projected RasterArray
-class object.
# project first three to mollweide ex <- rastex() mollEx <- project(ex[1:3], y="ESRI:54009")
# project first three to mollweide ex <- rastex() mollEx <- project(ex[1:3], y="ESRI:54009")
VirtualArray
'This function returns an object that symbolizes the structure of layers in the 'XArray
', 'RasterArray
' or 'SfArray
'.
proxy(x, ...) ## S4 method for signature 'VirtualArray' proxy(x)
proxy(x, ...) ## S4 method for signature 'VirtualArray' proxy(x)
x |
|
... |
additional arguments passed to class-specific methods. |
The proxy
method wraps the names of layers in the @stack
using the @index
slot of the 'VirtualArray
'.
A vector
, matrix
or array
of characters representing the VirtualArray
structure.
data(exemplar) proxy(exemplar) data(paleocoastlines) proxy(paleocoastlines)
data(exemplar) proxy(exemplar) data(paleocoastlines) proxy(paleocoastlines)
SpatRaster
'-class objectsArray class for easier navigation of multilayer rasters
stack |
A |
index |
A |
dim |
A |
The class implements structures to organize single-layer 'SpatRaster
'-class objects that have the same dimensions and coordinate reference system. Subsetting rules were defined using the proxy object in the @index
slot. See examples for implementations.
The class has two slots:
@stack
: A 'SpatRaster
'-class object with multiple layers, the actual data.
index
: A proxy object that represents the organization of the layer in the array.
A 'RasterArray
'-class object.
# example data ex <- rastex() st <-ex@stack ind <- 1:6 names(ind) <- letters[1:length(ind)] ra<- RasterArray(stack=st, index=ind)
# example data ex <- rastex() st <-ex@stack ind <- 1:6 names(ind) <- letters[1:length(ind)] ra<- RasterArray(stack=st, index=ind)
RasterArray
' classBinary versions of SpatRaster
-class objects are problematic, this function is used to instantiate a RasterArray
example.
rastex()
rastex()
A two-dimensional RasterArray
-class object, with three rows and four columns.
# create example example <- rastex() # subset - single bracket example['b'] # subset - single bracket example[c(4, 6)] # subset - double bracket example[["layer_2"]]
# create example example <- rastex() # subset - single bracket example['b'] # subset - single bracket example[c(4, 6)] # subset - double bracket example[["layer_2"]]
RasterArray
'-class objectThe method is inherited from the 'SpatRaster
' class.
## S4 method for signature 'RasterArray,ANY' resample(x, y, ...)
## S4 method for signature 'RasterArray,ANY' resample(x, y, ...)
x |
a |
y |
The y argument of the |
... |
arguments passed to the |
A resampled RasterArray
-class object.
ex <- rastex() if(requireNamespace("terra", quietly=TRUE)){ template <- terra::rast(res=5) resampled <- resample(ex, template) }
ex <- rastex() if(requireNamespace("terra", quietly=TRUE)){ template <- terra::rast(res=5) resampled <- resample(ex, template) }
RasterArray
'-class objectThe method is inherited from the 'SpatRaster
' class.
## S4 method for signature 'RasterArray' rotate(x, ...)
## S4 method for signature 'RasterArray' rotate(x, ...)
x |
( |
... |
Additional arguments passed to the |
A RasterArray
-class object.
VirtualArray
'-derived class objects.Get or set the row names of two-dimensional 'VirtualArray
'-derived class object
## S4 method for signature 'VirtualArray' rownames(x) ## S4 replacement method for signature 'VirtualArray' rownames(x) <- value
## S4 method for signature 'VirtualArray' rownames(x) ## S4 replacement method for signature 'VirtualArray' rownames(x) <- value
x |
|
value |
|
A character
vector of row names or NULL
.
data(paleocoastlines) rownames(paleocoastlines) rownames(paleocoastlines) <- paste(rownames(paleocoastlines), "Ma")
data(paleocoastlines) rownames(paleocoastlines) rownames(paleocoastlines) <- paste(rownames(paleocoastlines), "Ma")
sf
'-derived class dataArray class for easier navigation of vector spatial datasets
stack |
A |
index |
A |
dim |
A |
The class implements structures to organize entire 'sfc
' and 'sf
' objects that share coordinate reference systems. The 'SfcArray' class is derived from 'XArray
' and represents arrays of geometry sets. The 'SfArray
' class is derived from 'SfArray
', that allows the wrapping of 'sf
' objects with attributes. Subsetting rules were defined using the proxy object in the @index
slot. See examples for implementations.
The classes have two slots:
@stack
: A list
object with multiple 'sf
' class layers, the actual data.
@index
: A proxy object that represents the organization of the layers.
An 'SfcArray
' or 'SfArray
'-class object.
# example data library(sf) data(paleocoastlines) st <-paleocoastlines@stack ind <- 1:nlayers(st) dim(ind) <- c(3,2) dimnames(ind) <- list(age=c(0, 10, 20), c("margin", "coastlines")) sa<- SfcArray(stack=st, index=ind)
# example data library(sf) data(paleocoastlines) st <-paleocoastlines@stack ind <- 1:nlayers(st) dim(ind) <- c(3,2) dimnames(ind) <- list(age=c(0, 10, 20), c("margin", "coastlines")) sa<- SfcArray(stack=st, index=ind)
SfArray
'-class objectThe method is inherited from the 'sf
' class.
## S3 method for class 'SfcArray' st_bbox(obj, ...)
## S3 method for class 'SfcArray' st_bbox(obj, ...)
obj |
a |
... |
arguments passed to the |
An RasterArray
class object.
data(paleocoastlines) bb<- st_bbox(paleocoastlines)
data(paleocoastlines) bb<- st_bbox(paleocoastlines)
SfArray
'-class objectThe method is inherited from the 'sf
' class.
## S3 method for class 'SfcArray' st_crs(x, ...)
## S3 method for class 'SfcArray' st_crs(x, ...)
x |
a |
... |
arguments passed to the |
An aggregated RasterArray
class object.
data(paleocoastlines) crs <- st_crs(paleocoastlines)
data(paleocoastlines) crs <- st_crs(paleocoastlines)
SfArray
'-class objectThe method is inherited from the 'sf
' class.
## S3 method for class 'SfcArray' st_transform(x, ...)
## S3 method for class 'SfcArray' st_transform(x, ...)
x |
a |
... |
arguments passed to the |
An RasterArray
-class object.
data(paleocoastlines) moll<- st_transform(paleocoastlines, "ESRI:54009") plot(moll["20", "margin"], col="cyan") plot(moll["20", "coast"], add=TRUE, col="brown")
data(paleocoastlines) moll<- st_transform(paleocoastlines, "ESRI:54009") plot(moll["20", "margin"], col="cyan") plot(moll["20", "coast"], add=TRUE, col="brown")
VirtualArray
'-class objectExtract subsets of an object from a class derived from 'VirtualArray
' similarly to a regular array.
## S4 method for signature 'VirtualArray' subset(x, i, j, ..., oneDim = FALSE, drop = TRUE)
## S4 method for signature 'VirtualArray' subset(x, i, j, ..., oneDim = FALSE, drop = TRUE)
x |
|
i |
subscript of the first dimension(rows) or vector-like subsetting. |
j |
subscript of the second dimension (columns). |
... |
subscript of additional dimensions. |
oneDim |
|
drop |
|
Either the same class as x
, or the class that forms the element of the VirtualArray
.
ex <- rastex() # first 4 subset(ex, i=1:4) # missing at the end subset(ex, i=1:12) # character subscript subset(ex, i=c("a", "b")) # logical subscript subs <- rep(TRUE, length(ex)) subs[1] <- FALSE # remove first subset(ex, i= subs) # no drop subset(ex, i=1, drop=FALSE)
ex <- rastex() # first 4 subset(ex, i=1:4) # missing at the end subset(ex, i=1:12) # character subscript subset(ex, i=c("a", "b")) # logical subscript subs <- rep(TRUE, length(ex)) subs[1] <- FALSE # remove first subset(ex, i= subs) # no drop subset(ex, i=1, drop=FALSE)
VirtualArray
'-class objectTranspose a 'VirtualArray
'-class object
## S4 method for signature 'VirtualArray' t(x)
## S4 method for signature 'VirtualArray' t(x)
x |
A |
A VirtualArray
-class object.
data(exemplar) t(exemplar) data(paleocoastlines) t(paleocoastlines)
data(exemplar) t(exemplar) data(paleocoastlines) t(paleocoastlines)
The base class 'VirtualArray
' is defined, which acts as a wrapper around lists allowing users to fold arbitrary sequential data into n-dimensional, R-style virtual arrays. The derived 'XArray
' class is defined to be used for homogeneous lists that contain a single class of objects. The 'RasterArray
' and 'SfArray
' classes enable the use of stacked spatial data instead of lists.
#'
This is still the pre-alpha version. As is R, this is free software and comes with ABSOLUTELY NO WARRANTY. Nevertheless, notes about found bugs and suggestions are more than welcome.
Adam T. Kocsis ([email protected])
Template for construction of virtual arrays ('VirtualArray
') and a derived class ('XArray
') to instantiate it with general objects.
stack |
A |
index |
A |
dim |
A |
The 'VirtualArray
' class implements structures to organize objects of the same class in multidimensional arrays. Subsetting rules were defined using the proxy object in the index
slot. The 'VirtualArray
' is the base class for 'XArray
' and 'RasterArray
' classes.
The 'XArray
' class derived from VirtualArray
allows the instantiation of basic virtual arrays with genearl R objects, which form a single list
in the @stack slot
. The 'SfArray
' class is derived from the 'XArray
' class.
The class has two slots:
@stack
: A list containing objects of the same class (i.e. layers).
@index
: A proxy object that represents the structure of the entities.
An XArray
-class object.
# 2d XArray of vectors data(exemplar) st <-exemplar@stack ind <- 1:nlayers(st) dim(ind) <- c(3,4) dimnames(ind) <- list(n = c(10, 20, 30), seed = 1:4) xa<- XArray(stack=st, index=ind)
# 2d XArray of vectors data(exemplar) st <-exemplar@stack ind <- 1:nlayers(st) dim(ind) <- c(3,4) dimnames(ind) <- list(n = c(10, 20, 30), seed = 1:4) xa<- XArray(stack=st, index=ind)
RasterArray
'-class objectThe methods are inherited from the 'SpatRaster
' class, see res
. Replacement is not allowed.
## S4 method for signature 'RasterArray' xres(x) ## S4 method for signature 'RasterArray' yres(x) ## S4 method for signature 'RasterArray' res(x)
## S4 method for signature 'RasterArray' xres(x) ## S4 method for signature 'RasterArray' yres(x) ## S4 method for signature 'RasterArray' res(x)
x |
a |
A numeric
vector.
ex <- rastex() res(ex) yres(ex) xres(ex)
ex <- rastex() res(ex) yres(ex) xres(ex)