Learn R Programming

envirem (version 2.3)

verifyRasterNames: Verify Raster Names

Description

Given a RasterStack, this function will verify the naming scheme and check that all required rasters are present.

Usage

verifyRasterNames(
  masterstack = NULL,
  solradstack = NULL,
  returnRasters = FALSE
)

Value

Prints messages to the console if returnRasters = FALSE, If returnRasters = TRUE, then a RasterStack is returned. This RasterStack will not include rasters that were deemed unnecessary.

Arguments

masterstack

rasterStack containing all precipitation, min temperature, max temperature, and (optionally) mean temperature variables.

solradstack

rasterStack of monthly solar radiation

returnRasters

if FALSE, the function checks names and reports back. If TRUE, a RasterStack is returned with standardized names.

Author

Pascal Title

Details

This function checks that the following are present:

12 precipitation rasters

12 min temperature rasters

12 max temperature rasters

12 mean temperature rasters [optional]

12 solar radiation rasters

The naming scheme will be checked against the one defined via the custom naming environment. See link{?assignNames} for additional details.

The function can test the temp/precip rasterstack and/or the solar radiation rasterstack separately, or simultaneously.

Examples

Run this code
# Find example rasters
rasterFiles <- list.files(system.file('extdata', package='envirem'), full.names=TRUE)

# create stack of temperature and precipitation rasters
# and stack of solar radiation rasters
solradFiles <- grep('solrad', rasterFiles, value=TRUE)
worldclim <- stack(setdiff(rasterFiles, solradFiles))
solar <- stack(solradFiles)

# modify naming
names(worldclim) <- gsub('tmin_', 'minTemp', names(worldclim))
names(worldclim) <- paste0(names(worldclim), '_v1.0')
names(solar) <- gsub('et_solrad_', 'solar_', names(solar))

# but don't specify this change
varnames()

# Run check
verifyRasterNames(masterstack = worldclim, solradstack = solar, returnRasters = FALSE)

# But if we specify our naming scheme
assignNames(tmin = 'minTemp##_v1.0', tmax = 'tmax_##_v1.0', tmean = 'tmean_##_v1.0', 
	solrad = 'solar_##', precip = 'prec_##_v1.0')
varnames()

verifyRasterNames(masterstack = worldclim, solradstack = solar, returnRasters = FALSE)

# set back to defaults
assignNames(reset = TRUE)

Run the code above in your browser using DataLab