R/read.epmGrid.R

Defines functions read.epmGrid

Documented in read.epmGrid

##' @title Read a epmGrid object
##'
##' @description Load a saved epmGrid object. 
##'
##' @param filename filename, with extension \code{rds}
##'
##' @details This function will read in epmGrid objects that
##' were saved with \code{\link{write.epmGrid}}. 
##'
##' @return object of class epmGrid
##'
##' @author Pascal Title
##'
##' @examples
##' #save
##' write.epmGrid(tamiasEPM, paste0(tempdir(), '/tamiasEPM'))
##' 
##' # read back in
##' tamiasEPM <- read.epmGrid(paste0(tempdir(), '/tamiasEPM.rds'))
##'
##' # delete the file
##' unlink(paste0(tempdir(), '/tamiasEPM.rds'))
##'
##' @export

read.epmGrid <- function(filename) {
	
	if (!grepl('\\.rds$', filename)) {
		filename <- paste0(filename, '.rds')
	}
	
	x <- readRDS(filename)
	
	if (inherits(x[[1]], 'PackedSpatRaster')) {
		x[[1]] <- terra::rast(x[[1]])
	}

	return(x)	
}

Try the epm package in your browser

Any scripts or data that you put into this service are public.

epm documentation built on April 4, 2025, 1:42 a.m.