addTable: Attach or detach GVector's data table

addTable<-,GVector,data.frame-methodR Documentation

Attach or detach GVector's data table

Description

addTable() adds an entire table to a GVector. It will replace any existing table. There must be one row in the table for each geometry (see ngeom()). You can also add a table column-by-column using the $<- operator.

dropTable() removes a data table associated with a GVector.

Usage

## S4 replacement method for signature 'GVector,data.frame'
addTable(x, ...) <- value

## S4 replacement method for signature 'GVector,data.table'
addTable(x, ...) <- value

## S4 replacement method for signature 'GVector,matrix'
addTable(x, ...) <- value

## S4 method for signature 'GVector'
dropTable(x)

Arguments

x

A GVector.

...

Other arguments (ignored).

value

A data.frame, data.table, or matrix.

Value

A GVector.

See Also

$<-, colbind(), rbind(), as.data.frame(), as.data.table()

Examples

if (grassStarted()) {

# Setup
library(sf)

# Rivers vector
madRivers <- fastData("madRivers")

# Convert sf to a GVector
rivers <- fast(madRivers)

# Convert GVector to data.frame or data.table
as.data.frame(rivers)
as.data.table(rivers)

# Subset rivers vector
rivers1 <- rivers[1:2]
rivers2 <- rivers[10:11]

# Concatenate rivers
riversCombo <- rbind(rivers1, rivers2)
riversCombo

# Add columns
newCol <- data.frame(new = 1:11)
riversCol <- colbind(rivers, newCol)
riversCol

# Remove table
riversCopy <- rivers
riversCopy # has data table
riversCopy <- dropTable(riversCopy)
riversCopy # no data table

# Add a new table
newTable <- data.frame(num = 1:11, letters = letters[1:11])
addTable(riversCopy) <- newTable
riversCopy

}

adamlilith/fasterRaster documentation built on Dec. 21, 2024, 2:04 a.m.