Determine the filename, given various combinations of inputs.

determineFilename(filename2 = TRUE, filename1 = NULL,
  destinationPath = NULL, prefix = "Small", ...)

Arguments

filename2

filename2 is optional, and is either NULL (no writing of outputs to disk), or several options for writing the object to disk. If TRUE (the default), it will give it a file name determined by .prefix(basename(filename1), prefix). If a character string, it will use this as its file name. See determineFilename.

filename1

Character strings giving the file paths of the input object (filename1) filename1 is only used for messaging (i.e., the object itself is passed in as x) and possibly naming of output (see details and filename2).

destinationPath

Optional. If filename2 is a relative file path, then this will be the directory of the resulting absolute file path.

prefix

The character string to prepend to filename1, if filename2 not provided.

...

Additional arguments passed to methods. For spatialObjects, these are: cropInputs, fixErrors, projectInputs, maskInputs, determineFilename, and writeOutputs. Each of these may also pass ... into other functions, like writeRaster, or sf::st_write. This might include potentially important arguments like datatype, format. Also passed to projectRaster, with likely important arguments such as method = "bilinear". See details.

... passed to:

FunctionArgumentscropInputscrop
projectInputsprojectRastermaskInputsfastMask or intersect
fixErrorsbufferwriteOutputswriteRaster or shapefile
determineFilenameFunction
* Can be overridden with useSAcrs ** Will mask with NAs from rasterToMatch if maskWithRTM

Details

The post processing workflow, which includes this function, addresses several scenarios, and depending on which scenario, there are several file names at play. For example, Raster objects may have file-backed data, and so possess a file name, whereas Spatial objects do not. Also, if post processing is part of a prepInputs workflow, there will always be a file downloaded. From the perspective of postProcess, these are the "inputs" or filename1. Similarly, there may or may not be a desire to write an object to disk after all post processing, filename2.

This subtlety means that there are two file names that may be at play: the "input" file name (filename1), and the "output" filename (filename2). When this is used within postProcess, it is straight forward.

However, when postProcess is used within a prepInputs call, the filename1 file is the file name of the downloaded file (usually automatically known following the downloading, and refered to as targetFile) and the filename2 is the file name of the of post-processed file.

If filename2 is TRUE, i.e., not an actual file name, then the cropped/masked raster will be written to disk with the original filenam1/targetFile name, with prefix prefixed to the basename(targetFile).

If filename2 is a character string, it will be the path of the saved/written object e.g., passed to writeOutput. It will be tested whether it is an absolute or relative path and used as is if absolute or prepended with destinationPath if relative.

If filename2 is logical, then the output filename will be prefix prefixed to the basename(filename1). If a character string, it will be the path returned. It will be tested whether it is an absolute or relative path and used as is if absolute or prepended with destinationPath if provided, and if filename2 is relative.

Examples

# Add a study area to Crop and Mask to # Create a "study area" library(sp) library(raster) ow <- setwd(tempdir()) # make a SpatialPolygon coords1 <- structure(c(-123.98, -117.1, -80.2, -100, -123.98, 60.9, 67.73, 65.58, 51.79, 60.9), .Dim = c(5L, 2L)) Sr1 <- Polygon(coords1) Srs1 <- Polygons(list(Sr1), "s1") shpEcozone <- SpatialPolygons(list(Srs1), 1L) crs(shpEcozone) <- "+init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" # make a "study area" that is subset of larger dataset coords <- structure(c(-118.98, -116.1, -99.2, -106, -118.98, 59.9, 65.73, 63.58, 54.79, 59.9), .Dim = c(5L, 2L)) Sr1 <- Polygon(coords) Srs1 <- Polygons(list(Sr1), "s1") StudyArea <- SpatialPolygons(list(Srs1), 1L) crs(StudyArea) <- "+init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" #' #' ########## shpEcozonePostProcessed <- postProcess(shpEcozone, studyArea = StudyArea)
#> No cacheRepo supplied. Using value in getOption('reproducible.cachePath')
#> loading memoised result from previous cropInputs call.
#> Checking for errors in SpatialPolygon
#> Found no errors.
#> No cacheRepo supplied. Using value in getOption('reproducible.cachePath')
#> loading memoised result from previous projectInputs call.
#> No cacheRepo supplied. Using value in getOption('reproducible.cachePath')
#> loading memoised result from previous maskInputs call.
#> Saving output to ./Smallfile12bcb3d5f38. Specify filename1 or filename2 for more control
#' # Try manually, individual pieces shpEcozoneReprojected <- projectInputs(shpEcozone, StudyArea) shpEcozoneCropped <- cropInputs(shpEcozone, StudyArea)
#> cropping ...
shpEcozoneClean <- fixErrors(shpEcozone)
#> Checking for errors in SpatialPolygon
#> Found no errors.
shpEcozoneMasked <- maskInputs(shpEcozone, StudyArea)
#> intersecting ...
#> Checking for errors in studyArea
#> Found no errors.
setwd(ow)