This vignette provides a brief introduction to ZonationR. Users will:
- Set up example biodiversity data.
- Prepare Zonation input files.
- Run a single prioritization analysis.
If you are new to spatial conservation prioritization or want a gentle overview to understand the basics, see the vignette Why spatial conservation prioritization?.
Setup
# Install the Zonation5RData package from GitHub:
pak::pak("thiago-cav/Zonation5RData")
# Load necessary libraries
library(ZonationR)
library(Zonation5RData)Before you begin
ZonationR is an interface to Zonation, which means that Zonation must be able to read and write files on disk. To ensure this works smoothly, it is recommended that you run the analysis inside an RStudio project whose directory is writable. Before running the example below, please make sure that:
-
Zonation 5 is installed on your system
- You know the path to the Zonation 5 installation
directory
- Your current R project directory is writable
To install the Zonation 5 software on your computer.
Visit the official Zonation 5 website.
Download the appropriate installer or executable for your operating system (e.g., Windows, Linux).
Install or unpack the software, and note the installation path. You’ll need it later.
Prepare input data
For this example, we use the Zonation5RData package, which provides GeoTIFF layers for workflows with Zonation and ZonationR. To use the biodiversity layers in the RStudio project, we first create a folder and then copy the raster files from the package.
# Create a folder for biodiversity input data
dir.create("biodiversity", showWarnings = FALSE)
# Get the paths to biodiversity rasters included in the package
files <- zonation5rdata_list("biodiversity", full.names = TRUE)
# Copy the raster files to the local biodiversity folder
file.copy(files, "biodiversity", overwrite = TRUE)Preflight checks
Now let’s check our setup! You can use the preflight functions in ZonationR to check that key requirements are met before creating input files or running Zonation. For example, you can quickly see if R can find the Zonation 5 executable on your computer. The installation path will be used later when creating the Zonation command file.
# Run one preflight check
z_check <- check_zonation_executable()
# Print the message
cat(z_check$message)Zonation analyses require that input feature layers (e.g., species
distribution rasters) share the same extent, resolution, and projection.
The ZonationR package provides the function
check_raster_uniformity() to verify that your layers are
harmonized. You can also use check_dir_writable() to ensure
that your working directory is writable.
# Run the other preflight checks
check_raster_uniformity("biodiversity")
check_dir_writable(".")Zonation input files
Next, we create the three compulsory input files required by Zonation
5. The zonation_path argument must point to the directory
where Zonation 5 is installed on your system.
# Create feature list file
feature_list(spp_file_dir = "biodiversity")
# Create settings file
settings_file(feature_list_file = "feature_list.txt")
# Create the Zonation command file
command_file(zonation_path = "C:/Program Files (x86)/Zonation5")Run the prioritization
Finally, we run the Zonation 5 analysis.
# Run the Zonation 5 analysis
run_command_file(".")Awesome! You just ran your first Zonation prioritization analysis 🎉
All outputs (priority map, performance curves, and other files) are in
the output folder.
Keep exploring
Want to take it further? Run multiple scenarios, tweak feature
weightings, or explore other settings in the vignette Working with variants in
ZonationR.
