basifoR provides reproducible, design-aware workflows for Spanish National Forest Inventory (SNFI) data in R.
The package helps users move from raw inventory archives to analysis-ready outputs. It supports archive retrieval and ingestion, tree-level metric computation, tree-level volume estimation, and stand-level summarization. It also exposes extensible components for custom sampling designs, schemas, and volume methods, so the same workflow can be adapted to external inventory data under explicit assumptions.
This repository contains the version used in the manuscript:
R Package basifoR: Reproducible Workflows for the Spanish National Forest Inventory
The main user-facing entry point is inventoryMetrics(). It accepts one inventory input or several inputs and returns grouped stand-level summaries.
library(basifoR)
dm <- inventoryMetrics(
list("toledo", "palencia", "madrid"),
nfi.nr = list(4, 3, 2),
mc.cores = 3,
summ.vr = c("pr", "estadillo")
)
str(dm)
attr(dm, "units")
This example processes three Spanish provinces from three SNFI stages in one call. inventoryMetrics() resolves each input, dispatches the required SNFI workflow internally, computes tree-level metrics and volume where needed, and returns stand-level summaries grouped by province (pr) and plot (estadillo). With mc.cores = 3, the inputs can be processed in parallel when your system supports it. The returned object is a data frame with standard summary variables such as basal area, mean diameter, quadratic mean diameter, mean height, trees per hectare, and volume, together with unit metadata.
.dbf, .mdb, and .accdb
n, d, dg, h, ba, and volumeinventoryMetrics()
install.packages("remotes")
# remotes::install_github("wilarhen/basifoR")
install.packages("basifoR", repos = c('https://wilarhen.r-universe.dev', 'https://cloud.r-project.org'))
library(basifoR)
Most package functionality runs directly in R once you install the package. Some workflows may require extra system components to read legacy database formats used by SNFI archives.
Workflows that import .mdb or .accdb files may require Microsoft Access connectivity.
The recommended option is the Microsoft 365 Access Runtime. Install the version that matches your local Office installation and then restart R.
Legacy Access connectivity is commonly provided through mdbtools.
On Debian-based systems, install it with:
sudo apt update
sudo apt install mdbtools
Install mdbtools with Homebrew:
brew install mdbtools
These external components affect only archive import from legacy database files. Once data are in R, the downstream workflow runs normally.
basifoR supports both a stepwise workflow and a one-call workflow.
library(basifoR)
dtol <- inventoryMetrics("toledo", nfi.nr = 4, cut.dt = "h >= 8")
head(dtol)
attr(dtol, "units")
library(basifoR)
z <- system.file("ifn3p28.zip", package = "basifoR")
x <- readNFI(z)
m <- nfiMetrics(x)
v <- metrics2Vol(m)
s <- inventoryMetrics(v)
head(s)
attr(s, "units")
This route makes each processing step explicit:
readNFI() -> nfiMetrics() -> metrics2Vol() -> inventoryMetrics()
basifoR can also process external inventory data through the same design-aware logic used for the SNFI. External workflows make the required assumptions explicit: you define the sampling design, declare how source columns map to diameter and height, and supply a volume method or parameter table when tree volume must be computed.
The external workflow can start from raw tree tables or from already standardized metric tables. In a typical workflow:
new_inventory_design() or new_concentric_design()
new_external_schema()
externalMetrics() when neededexternalMetrics2Vol() and a registry built with external_volume_method_registry() and new_volume_method()
external_dendroMetrics() or through inventoryMetrics(..., backend = "external")
These helpers let you standardize measurements, compute design-aware expansion factors, derive optional dominant height and volume outputs, and return either tree-level records or grouped stand summaries. The external backend supports repeated workflows, grouped summaries, optional provenance tracking, and custom volume definitions.
A minimal set of core helpers is:
new_inventory_design() or new_concentric_design()
new_external_schema()externalMetrics()new_volume_method()external_volume_method_registry()externalMetrics2Vol()external_dendroMetrics()inventoryMetrics(..., backend = "external")inventoryMetrics() — unified entry point that dispatches complete workflows for SNFI and external inventoriesgetNFI() — resolve a province identifier or archive input and fetch matching SNFI filesfetchNFI() — download and extract files from local or remote compressed archivesreadNFI() — import extracted SNFI tables into RdbhMetric() — compute compact tree-level metrics such as diameter, height, basal area, and trees per hectarenfiMetrics() — standardize SNFI measurements and compute tree-level dendrometric variablesmetrics2Vol() — compute tree-level SNFI volume outputs from standardized metricssnfi_volume_method_registry() — inspect the active SNFI volume-method registrydefault_snfi_volume_equations() — return the bundled SNFI equation definitionsdendroMetrics() — summarize SNFI tree data into grouped stand-level outputsnew_inventory_design() — define custom fixed-area sampling designsnew_concentric_design() — define custom concentric sampling designsnew_external_schema() — store reusable external column mappings, units, and defaultsexternalMetrics() — standardize external tree measurements into basifoR metric unitsexternalMetrics2Vol() — compute external tree-level volume outputs from standardized metrics or raw inputsexternal_volume_method_registry() — build the active registry of external volume methodsnew_volume_method() — define one custom external volume methodexternal_dendroMetrics() — process external tree tables and return tree-level or grouped stand-level outputsExample Spanish National Forest Inventory archives are distributed with the package and are also available from the official website of the Ministry for the Ecological Transition and the Demographic Challenge of Spain.
The external example used in the manuscript relies on the official IGN export resource for the French National Forest Inventory.
This GitHub repository provides the public development and review version of basifoR.
The exact version used in the manuscript is available as GitHub release v0.7.7.
GPL-3 License
If you use basifoR, please cite the package and the associated manuscript when available.
Wilson Lara
wilarhen@gmail.com