Skip to contents

Refactor variables using metadata.

Usage

refactor(x, ...)

# S4 method for Cropmaps
refactor(x, variable, mdname, newvarname = variable)

Arguments

x

S4 object. A product of interest.

...

extra arguments.

variable

character. The variable of interest.

mdname

character. The metadata file names needed for the recoding.

newvarname

character. The name of the refactored variable.

Value

nothing. The data are saved directly in the cronus database.

Examples

if (FALSE) {
# Define required variables
region <- Region(name = "nebraska", type = "us state",
                 div = c(country = "United States", state = "Nebraska"))
date <- date_seq("2002-01-01", "2002-12-31")

## Cropmaps CDL

# Create the object
x <- new("Cropmaps", region = region, date = date)

# Get the current categories data.frame
df_cat <- terra::cats(cdl_2020)[[1]]

# Define a transformation table
tb_rcl <- cbind(a = c(121:124, 141:143), b = c(rep(82, 4), rep(63, 3)))

# Write the metadata
write(x, name = "my_metadata", df_cat = df_cat, tb_rcl = tb_rcl)

# Refactor the raster
refactor(x, variable = "cdl_projected", mdname = "my_metadata", newvarname = "cdl_refactored")
}