| Title: | Retrieval and Processing of the Spanish National Forest Inventory |
|---|---|
| Description: | Fetches, harmonizes, and analyses data from the Spanish National Forest Inventory for reproducible, design-aware forest inventory workflows. Computes tree- and stand-level metrics, applies sampling-based expansion factors, estimates volume, and supports extensible processing for external inventory designs with custom sampling schemes and volume equations. |
| Authors: | Wilson Lara [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>) |
| Maintainer: | Wilson Lara <[email protected]> |
| License: | GPL-3 |
| Version: | 0.7.7 |
| Built: | 2026-06-01 10:29:02 UTC |
| Source: | https://github.com/wilarhen/basifor |
Convert raw tree diameter or height inputs into the compact metric formats used across basifoR workflows.
dbhMetric(dbh, met = "d", design = snfi_design())dbhMetric(dbh, met = "d", design = snfi_design())
dbh |
|
met |
|
design |
Object inheriting from |
The sampling design affects only met = "n". For "d", "ba", and "h", the returned value does not depend on design.
A single numeric value. Returns mean diameter in mm for met = "d", basal area in m^2 per tree for met = "ba", trees per hectare for met = "n", and height in dm for met = "h". Returns NA_real_ when all supplied values are missing or become missing after zero replacement.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
dbhMetric(300, "d") dbhMetric(300, "ba") dbhMetric(18, "h") dsg <- new_concentric_design( radii_m = c(4, 8, 12), min_dbh_cm = c(5, 15, 30), name = "3-subplot design" ) dbhMetric(130, "n", design = dsg)dbhMetric(300, "d") dbhMetric(300, "ba") dbhMetric(18, "h") dsg <- new_concentric_design( radii_m = c(4, 8, 12), min_dbh_cm = c(5, 15, 30), name = "3-subplot design" ) dbhMetric(130, "n", design = dsg)
Return the built-in external volume-method specifications used as the starting registry for externalMetrics2Vol and external_volume_method_registry.
default_external_volume_methods()default_external_volume_methods()
"V" passes through an already available total-volume
field. "VCC" computes merchantable volume over bark
from diameter and height, and "VSC" computes
merchantable volume under bark from the resolved
vcc value.
A named list of default external volume-method specifications.
The list currently contains entries named "V",
"VCC", and "VSC", each stored as the named
list returned by new_volume_method.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
methods <- default_external_volume_methods() names(methods) methods$V$output methods$VCC$required_inputsmethods <- default_external_volume_methods() names(methods) methods$V$output methods$VCC$required_inputs
Return the default SNFI volume-equation registry. Creates the default set of method definitions used by 'metrics2Vol()' to compute tree-level volume variables. Each registry entry describes how one output is computed, including the target column name, equation function, unit conversion, argument builder, and fallback rule.
default_snfi_volume_equations()default_snfi_volume_equations()
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
This function summarizes dendrometric data from the Spanish
National Forest Inventory (SNF). It primarily accepts a province
name or number, a local compressed SNF file, or a URL to a
compressed SNF file hosted by www.miteco.gob.es. It can
also process data frames previously returned by
readNFI, nfiMetrics, or
metrics2Vol. Dendrometric variables in the output
are transformed into stand units, see Details section.
dendroMetrics(nfi, summ.vr = "Estadillo", metric_levels = NULL, cut.dt = "d == d", report = FALSE, mc.cores = getOption("mc.cores", 1L), ...)dendroMetrics(nfi, summ.vr = "Estadillo", metric_levels = NULL, cut.dt = "d == d", report = FALSE, mc.cores = getOption("mc.cores", 1L), ...)
nfi |
|
summ.vr |
|
metric_levels |
|
cut.dt |
|
report |
|
mc.cores |
|
... |
Additional arguments passed to |
Dendrometric variables are
summarized according to the levels of
argument summ.vr. Summary outputs
include the categorical columns defined
by summ.vr together with the
quantitative variables available after
processing with nfiMetrics
and metrics2Vol.
These variables may include tree basal
area ba ('m2 ha-1'), mean
diameter at breast height d
('cm'), quadratic mean diameter
dg ('cm'), mean tree
height h ('m'), number of
trees per hectare n
('dimensionless'), and over-bark
volume v ('m3 ha-1').
When summ.vr = NULL, the function
returns tree-level outputs from
metrics2Vol after applying
the filter defined in cut.dt.
When summ.vr is not NULL,
the function converts supported
variables to stand units, splits the data
by the requested grouping variable, and
computes summaries by group. Extensive
variables are multiplied by n
before summation. Variables d,
h, and Hd, when present,
are returned as averages weighted by
n.
If both ba and n are
available, the function also derives the
quadratic mean diameter dg.
Output subsets are extracted using the
logical expression supplied in
cut.dt, see syntax in
Logic.
The function accepts one input object or
several inputs. When several inputs are
supplied, each one is processed
independently and the results are merged
into a single output data frame.
Parallel processing is controlled by
mc.cores. Values greater than 1
process several inputs in parallel.
data.frame. Depending on summ.vr = NULL, an output from
metrics2Vol, or a summary of the variables, see
Details section.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
## Process SNF data for Toledo stored locally # Path to Toledo data file in 'basifoR' package ifn4p45 <- system.file("Ifn4_Toledo.zip", package="basifoR") # Decompress SNF data from the specified file path or URL fetch_ifn4p45 <- fetchNFI(ifn4p45) # Read and process the data (first 100 rows) get_ifn4p45 <- getNFI(fetch_ifn4p45)[1:100,] # Compute some metrics metrics_ifn4p45 <- nfiMetrics(get_ifn4p45) # Calculate volume metrics vol_ifn4p45 <- metrics2Vol(metrics_ifn4p45) # Compute all metrics (dendrometrics) for trees with height > 8 dendromet_ifn4p45 <- dendroMetrics(vol_ifn4p45, cut.dt='h > 8') # Display structure of dendrometric data str(dendromet_ifn4p45) # Check units of metrics attr(dendromet_ifn4p45,'units') ## Alternatively, download data from 'www.miteco.gob.es' ## Specify province name/number to compute dendrometrics: # Compute dendrometrics for Toledo (code 45) for NFI 4, height >= 8 dendromet_ifn4p45 <- dendroMetrics('toledo',nfi.nr=4,cut.dt='h >= 8') # Display first few rows head(dendromet_ifn4p45) # Check units of metrics attr(dendromet_ifn4p45,'units')## Process SNF data for Toledo stored locally # Path to Toledo data file in 'basifoR' package ifn4p45 <- system.file("Ifn4_Toledo.zip", package="basifoR") # Decompress SNF data from the specified file path or URL fetch_ifn4p45 <- fetchNFI(ifn4p45) # Read and process the data (first 100 rows) get_ifn4p45 <- getNFI(fetch_ifn4p45)[1:100,] # Compute some metrics metrics_ifn4p45 <- nfiMetrics(get_ifn4p45) # Calculate volume metrics vol_ifn4p45 <- metrics2Vol(metrics_ifn4p45) # Compute all metrics (dendrometrics) for trees with height > 8 dendromet_ifn4p45 <- dendroMetrics(vol_ifn4p45, cut.dt='h > 8') # Display structure of dendrometric data str(dendromet_ifn4p45) # Check units of metrics attr(dendromet_ifn4p45,'units') ## Alternatively, download data from 'www.miteco.gob.es' ## Specify province name/number to compute dendrometrics: # Compute dendrometrics for Toledo (code 45) for NFI 4, height >= 8 dendromet_ifn4p45 <- dendroMetrics('toledo',nfi.nr=4,cut.dt='h >= 8') # Display first few rows head(dendromet_ifn4p45) # Check units of metrics attr(dendromet_ifn4p45,'units')
Process external tree data through a unified workflow that standardizes measurements, computes missing dendrometric variables, optionally derives volume outputs, and returns either tree-level records or grouped stand-level summaries. The function can work from already standardized inputs or from raw external tables, and it supports repeated processing of several tables with optional parallel execution.
external_dendroMetrics(x, summ.vr = NULL, cut.dt = "d == d", report = FALSE, mc.cores = getOption("mc.cores", 1L), var = c("d", "h", "ba", "n", "Hd"), parametro = NULL, design = NULL, parameter_table = NULL, method_registry = external_volume_method_registry(), levels = NULL, metric_levels = NULL, keep_cols = NULL, metric_keep_cols = NULL, colmap = NULL, metric_colmap = list(d = c("d", "dbh", "diameter", "diameter_mm"), h = c("h", "height", "height_m")), d_unit = NULL, metric_d_unit = c("mm", "cm")[1], h_unit = NULL, metric_h_unit = c("m", "dm", "cm")[1], tree_d_unit_out = NULL, tree_h_unit_out = NULL, volume_colmap = list(d = c("d"), h = c("h"), dnm = c("dnm", "d_nm", "D.n.m."), v = c("v"), species = c("species", "spec", "especie"), region = c("region", "pr"), equation_set = c("equation_set", "eqset", "tariff", "model_set")), selector = c("first", "priority")[1], track_provenance = FALSE, compute_metrics_if_needed = TRUE, schema = NULL, domheight_fun = null_or(get0("domheight_strict", mode = "function", inherits = TRUE), get0("domheight", mode = "function", inherits = TRUE)), ...)external_dendroMetrics(x, summ.vr = NULL, cut.dt = "d == d", report = FALSE, mc.cores = getOption("mc.cores", 1L), var = c("d", "h", "ba", "n", "Hd"), parametro = NULL, design = NULL, parameter_table = NULL, method_registry = external_volume_method_registry(), levels = NULL, metric_levels = NULL, keep_cols = NULL, metric_keep_cols = NULL, colmap = NULL, metric_colmap = list(d = c("d", "dbh", "diameter", "diameter_mm"), h = c("h", "height", "height_m")), d_unit = NULL, metric_d_unit = c("mm", "cm")[1], h_unit = NULL, metric_h_unit = c("m", "dm", "cm")[1], tree_d_unit_out = NULL, tree_h_unit_out = NULL, volume_colmap = list(d = c("d"), h = c("h"), dnm = c("dnm", "d_nm", "D.n.m."), v = c("v"), species = c("species", "spec", "especie"), region = c("region", "pr"), equation_set = c("equation_set", "eqset", "tariff", "model_set")), selector = c("first", "priority")[1], track_provenance = FALSE, compute_metrics_if_needed = TRUE, schema = NULL, domheight_fun = null_or(get0("domheight_strict", mode = "function", inherits = TRUE), get0("domheight", mode = "function", inherits = TRUE)), ...)
x |
External input table, processed table, or list of such objects. Raw inputs must contain enough columns to resolve the requested metrics and, if needed, the volume selectors. |
summ.vr |
Grouping variable or character vector of grouping variables.
Leave |
cut.dt |
Character filter evaluated on the final table.
The expression is evaluated with |
report |
Whether to write the returned table to ‘report.csv’.
The file is written in the working directory only when |
mc.cores |
Number of worker processes used when |
var |
Requested variables.
Typical metric requests are |
parametro |
Optional volume-method codes, for example |
design |
Inventory |
parameter_table |
Optional parameter table for the volume stage.
Passed to |
method_registry |
Volume method registry.
Usually created by |
levels |
Grouping variables forwarded to |
metric_levels |
Grouping variables used during internal metric computation.
These are forwarded specifically to |
keep_cols |
Source columns to preserve in the output or |
metric_keep_cols |
Columns to preserve during internal metric computation.
These are passed to |
colmap |
Optional aliases that update the default mappings. Use this when source names differ from the expected volume or metric names. |
metric_colmap |
metric_colmap |
d_unit |
Optional diameter unit override shared with |
metric_d_unit |
Diameter unit expected by |
h_unit |
Optional height unit override shared with |
metric_h_unit |
Height unit expected by |
tree_d_unit_out |
Optional output unit for tree-level diameter values.
Only used when |
tree_h_unit_out |
Optional output unit for tree-level height values.
Only used when |
volume_colmap |
volume_colmap |
selector |
Rule used by |
track_provenance |
Whether to keep provenance columns from the volume workflow.
When |
compute_metrics_if_needed |
Whether to compute missing metrics from raw inputs.
If |
schema |
Optional |
domheight_fun |
domheight_fun |
... |
Additional arguments passed to downstream helpers. These are mainly useful for custom options in the internal metric or volume-processing steps. |
This wrapper mirrors the arguments and behaviour of dendroMetrics().
When summ.vr = NULL, the function returns tree-level records after applying cut.dt. When summ.vr contains one or more grouping variables, the function aggregates by those groups, reporting weighted means for d, h, and Hd, arithmetic sums for ba, n, and volume variables, and quadratic mean diameter dg when diameter and trees-per-hectare are available.
The function can work from already standardized inputs or from raw external tables. If requested metrics are missing and compute_metrics_if_needed = TRUE, it calls externalMetrics() internally, so raw inputs usually need a valid design plus diameter and, when relevant, height mappings. When schema is supplied, it provides reusable defaults for column aliases, units, grouping variables, and retained columns, while explicit arguments supplied in the call override those defaults.
Volume outputs are optional. They are computed only when parametro is supplied explicitly or can be inferred from var and method_registry. This lets the same entry point handle metric-only workflows, mixed metric-plus-volume workflows, and repeated processing of several input tables with optional parallel execution through mc.cores.
A data.frame with class c("external_dendroMetrics", "dendroMetrics", \code{...}).
With summ.vr = NULL, the returned rows represent tree-level records, optionally converted to tree_d_unit_out and tree_h_unit_out. With summ.vr supplied, the returned rows represent grouped summaries and include standardized summary units such as "cm", "m", "m2 ha-1", "ha-1", and "m3 ha-1" when those variables are present.
The returned object stores the matched call in attr(out, "call"). When available, it also preserves "units", "design_meta", and "volume_meta" attributes from upstream processing, which makes the result suitable for downstream inspection and update methods.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
sq_0.1ha <- new_inventory_design( sample_area_m2 = 1000, min_dbh_cm = 7.5, name = "Square 0.1-ha plot", metadata = list(shape = "square", side_m = sqrt(1000)) ) x <- data.frame( plot = c("P1", "P1", "P2"), species = c("sp1", "sp1", "sp2"), diameter_mm = c(120, 185, 260), height_m = c(7.1, 9.4, 13.2), stringsAsFactors = FALSE ) external_dendroMetrics( x = x, summ.vr = "plot", var = c("d", "h", "ba", "n"), design = sq_0.1ha, metric_colmap = list(d = "diameter_mm", h = "height_m"), metric_d_unit = "mm", metric_h_unit = "m" )sq_0.1ha <- new_inventory_design( sample_area_m2 = 1000, min_dbh_cm = 7.5, name = "Square 0.1-ha plot", metadata = list(shape = "square", side_m = sqrt(1000)) ) x <- data.frame( plot = c("P1", "P1", "P2"), species = c("sp1", "sp1", "sp2"), diameter_mm = c(120, 185, 260), height_m = c(7.1, 9.4, 13.2), stringsAsFactors = FALSE ) external_dendroMetrics( x = x, summ.vr = "plot", var = c("d", "h", "ba", "n"), design = sq_0.1ha, metric_colmap = list(d = "diameter_mm", h = "height_m"), metric_d_unit = "mm", metric_h_unit = "m" )
Return the registry of external volume methods used by
externalMetrics2Vol() and related external-inventory workflows.
The function starts from the package defaults, optionally uses a
user-supplied registry, then applies named overrides stored in
option "basifoR.external_volume_methods".
external_volume_method_registry(methods = get0("external_volume_methods", inherits = TRUE, ifnotfound = NULL))external_volume_method_registry(methods = get0("external_volume_methods", inherits = TRUE, ifnotfound = NULL))
methods |
methods |
The function only assembles and validates the registry. It does not
evaluate volume equations by itself.
A named list of external volume-method definitions. The list
always includes the package defaults, updated by any entries supplied
in methods and then by any entries found in option
"basifoR.external_volume_methods". Each element is expected
to be compatible with new_volume_method().
examples<< reg <- external_volume_method_registry()
examples<< names(reg)
examples<<
examples<< custom <- list(
examples<< V = new_volume_method(
examples<< output = "v",
examples<< unit = "m3",
examples<< raw_unit = "m3",
examples<< scale_to_m3 = 1,
examples<< build_args = function(ctx, pars, resolved) list(),
examples<< fallback = function(ctx, pars, resolved) 0,
examples<< match_by = character(0),
examples<< required_inputs = "v"
examples<< )
examples<< )
examples<< reg2 <- external_volume_method_registry(custom)
examples<< reg2$V$output
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
Standardize external tree measurements for external inventory workflows and return requested tree-level metrics in basifoR units.
externalMetrics(x, var = c("d", "h", "ba", "n", "Hd"), levels = NULL, design, colmap = NULL, d_unit = c("mm", "cm")[1], h_unit = c("m", "dm", "cm")[1], keep_cols = NULL, domheight_fun = NULL)externalMetrics(x, var = c("d", "h", "ba", "n", "Hd"), levels = NULL, design, colmap = NULL, d_unit = c("mm", "cm")[1], h_unit = c("m", "dm", "cm")[1], keep_cols = NULL, domheight_fun = NULL)
x |
Input data.frame with one row per tree or stem. |
var |
Supported values are |
levels |
Grouping columns to keep in the output. |
design |
Inventory |
colmap |
Named list of candidate raw column names for diameter and height.
Matching is case-insensitive and also accepts numeric suffixes such
as |
d_unit |
Unit of raw diameter columns in |
h_unit |
Unit of raw height columns in |
keep_cols |
Additional source columns to carry into the result. |
domheight_fun |
Function used when |
The function first resolves measurement columns from colmap. Exact matches are preferred, then case-insensitive matches with optional numeric suffixes are considered. When several repeated measurement columns are found for the same variable, row-wise non-missing means are used.
Zero values in resolved diameter or height columns are treated as missing before aggregation. Returned units are standardized to millimetres for d, decimetres for h and Hd, square metres per tree for ba, and trees per hectare for n.
When var includes "n", the function uses design to obtain expansion factors. Fixed-area designs call trees_per_ha(), while concentric designs choose the proper factor from the design thresholds. When var includes "Hd", dominant height is computed within each resolved group defined by levels and keep_cols.
A data.frame containing the requested tree-level metrics, optionally preceded by resolved grouping columns.
The returned object inherits from classes "externalMetrics" and "nfiMetrics". Unit metadata are stored in attr(out, "units"). When var includes "n" or "Hd", the result also stores sampling design metadata in attr(out, "design_meta").
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
sq_0.1ha <- new_inventory_design( sample_area_m2 = 1000, min_dbh_cm = 7.5, name = "Square 0.1-ha plot", metadata = list(shape = "square", side_m = sqrt(1000)) ) x <- data.frame( plot = c("P1", "P1", "P2"), species = c("sp1", "sp1", "sp2"), diameter_mm = c(120, 185, 260), height_m = c(7.1, 9.4, 13.2), stringsAsFactors = FALSE ) externalMetrics( x = x, var = c("d", "h", "ba", "n"), levels = c("plot", "species"), design = sq_0.1ha, colmap = list(d = "diameter_mm", h = "height_m"), d_unit = "mm", h_unit = "m" )sq_0.1ha <- new_inventory_design( sample_area_m2 = 1000, min_dbh_cm = 7.5, name = "Square 0.1-ha plot", metadata = list(shape = "square", side_m = sqrt(1000)) ) x <- data.frame( plot = c("P1", "P1", "P2"), species = c("sp1", "sp1", "sp2"), diameter_mm = c(120, 185, 260), height_m = c(7.1, 9.4, 13.2), stringsAsFactors = FALSE ) externalMetrics( x = x, var = c("d", "h", "ba", "n"), levels = c("plot", "species"), design = sq_0.1ha, colmap = list(d = "diameter_mm", h = "height_m"), d_unit = "mm", h_unit = "m" )
Compute one or more tree-level volume outputs from external inventory data or from a precomputed external metrics table.
externalMetrics2Vol(x, parametro = c("V"), parameter_table = NULL, method_registry = external_volume_method_registry(), colmap = NULL, selector = c("first", "priority")[1], track_provenance = FALSE, compute_metrics_if_needed = TRUE, design = NULL, var = NULL, metric_var = NULL, levels = NULL, metric_levels = NULL, keep_cols = NULL, metric_keep_cols = NULL, metric_colmap = list(d = c("d", "dbh", "diameter", "diameter_mm"), h = c("h", "height", "height_m")), d_unit = NULL, metric_d_unit = c("mm", "cm")[1], h_unit = NULL, metric_h_unit = c("m", "dm", "cm")[1], volume_colmap = list(d = c("d"), h = c("h"), dnm = c("dnm", "d_nm", "D.n.m."), v = c("v"), species = c("species", "spec", "especie"), region = c("region", "pr"), equation_set = c("equation_set", "eqset", "tariff", "model_set")), ...)externalMetrics2Vol(x, parametro = c("V"), parameter_table = NULL, method_registry = external_volume_method_registry(), colmap = NULL, selector = c("first", "priority")[1], track_provenance = FALSE, compute_metrics_if_needed = TRUE, design = NULL, var = NULL, metric_var = NULL, levels = NULL, metric_levels = NULL, keep_cols = NULL, metric_keep_cols = NULL, metric_colmap = list(d = c("d", "dbh", "diameter", "diameter_mm"), h = c("h", "height", "height_m")), d_unit = NULL, metric_d_unit = c("mm", "cm")[1], h_unit = NULL, metric_h_unit = c("m", "dm", "cm")[1], volume_colmap = list(d = c("d"), h = c("h"), dnm = c("dnm", "d_nm", "D.n.m."), v = c("v"), species = c("species", "spec", "especie"), region = c("region", "pr"), equation_set = c("equation_set", "eqset", "tariff", "model_set")), ...)
x |
Standardized columns such as |
parametro |
Requested volume outputs or method names. |
parameter_table |
Optional data.frame of coefficients or parameter rows used by the
selected methods. Rows may be filtered by columns such as
|
method_registry |
Named list of method definitions, usually created with
|
colmap |
Optional alias list used to resolve contextual inputs for the volume
methods. If |
selector |
Rule used when several parameter rows remain after filtering. |
track_provenance |
If |
compute_metrics_if_needed |
If |
design |
Inventory |
var |
Legacy alias for |
metric_var |
Metric variables requested during automatic derivation. |
levels |
Legacy alias for |
metric_levels |
Grouping or identifier columns kept during metric derivation. |
keep_cols |
Legacy alias for |
metric_keep_cols |
Extra columns kept during metric derivation. |
metric_colmap |
metric_colmap |
d_unit |
Legacy alias for |
metric_d_unit |
Unit of raw diameter columns used during metric derivation. |
h_unit |
Legacy alias for |
metric_h_unit |
Unit of raw height columns used during metric derivation. |
volume_colmap |
volume_colmap |
... |
Additional arguments passed only to |
Required inputs are inferred from the selected methods in method_registry. When one or more standardized inputs are missing and compute_metrics_if_needed = TRUE, the function calls externalMetrics() to derive them, using design, metric_colmap, units, grouping columns, and retained columns from the corresponding arguments.
Each requested output is evaluated with its method definition. A method can resolve its own parameter rows with get_pars, use embedded parameters in pars, or fall back to parameter_table. Raw outputs are converted to cubic metres with scale_to_m3.
When track_provenance = TRUE, the result stores per-output provenance columns together with a volume_meta attribute describing input units, returned units, required inputs, and method settings.
A data.frame containing the original columns in x plus the requested volume outputs.
The returned object inherits from classes "externalMetrics2Vol" and "metrics2vol". Named unit metadata are stored in attr(out, "units"), and the result may also preserve design_meta and volume_meta.
Use exact alias matching only here. This avoids false positives such as
matching the requested standardized metric "n" to source columns like
"CAMPAGNE" during the preflight check that decides whether metrics need
to be computed.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
x <- data.frame( species = c("sp1", "sp2"), d = c(120, 260), h = c(7.1, 13.2) ) attr(x, "units") <- c(d = "mm", h = "m") pars <- data.frame( parameter = "V", species = c("sp1", "sp2"), a = c(0.00002, 0.00003), b = c(2.30, 2.10), model = c("demo_sp1", "demo_sp2") ) ext_methods <- external_volume_method_registry(list( V = new_volume_method( output = "v", fun = function(dbh_mm, h_m, pars) { dbh_cm <- dbh_mm / 10 pars$a + pars$b * (dbh_cm^2) * h_m }, raw_unit = "cm3", unit = "m3", scale_to_m3 = 1 / 1e6, build_args = function(ctx, pars, resolved) { list(dbh_mm = ctx$d_mm, h_m = ctx$h_m, pars = pars) }, fallback = function(ctx, pars, resolved) NA_real_, match_by = "species", required_inputs = c("d", "h") ) )) out <- externalMetrics2Vol( x, parametro = "V", parameter_table = pars, method_registry = ext_methods, track_provenance = TRUE ) out[, c("species", "v", "v_source", "v_status")]x <- data.frame( species = c("sp1", "sp2"), d = c(120, 260), h = c(7.1, 13.2) ) attr(x, "units") <- c(d = "mm", h = "m") pars <- data.frame( parameter = "V", species = c("sp1", "sp2"), a = c(0.00002, 0.00003), b = c(2.30, 2.10), model = c("demo_sp1", "demo_sp2") ) ext_methods <- external_volume_method_registry(list( V = new_volume_method( output = "v", fun = function(dbh_mm, h_m, pars) { dbh_cm <- dbh_mm / 10 pars$a + pars$b * (dbh_cm^2) * h_m }, raw_unit = "cm3", unit = "m3", scale_to_m3 = 1 / 1e6, build_args = function(ctx, pars, resolved) { list(dbh_mm = ctx$d_mm, h_m = ctx$h_m, pars = pars) }, fallback = function(ctx, pars, resolved) NA_real_, match_by = "species", required_inputs = c("d", "h") ) )) out <- externalMetrics2Vol( x, parametro = "V", parameter_table = pars, method_registry = ext_methods, track_provenance = TRUE ) out[, c("species", "v", "v_source", "v_status")]
This function can download and decompress data sets from the Spanish
National Forest Inventory (SNF) stored in .zip files,
whether they are local or remote (URL-based).
fetchNFI(url., dir = tempdir(), file_ext = c("mdb", "DBF", "accdb"), file_name = NULL, timeOut = timeout(60))fetchNFI(url., dir = tempdir(), file_ext = c("mdb", "DBF", "accdb"), file_name = NULL, timeOut = timeout(60))
url. |
|
dir |
|
file_ext |
|
file_name |
|
timeOut |
|
The data should be in files with
extensions specified in the file_ext
argument. Use file_name to restrict the
returned files to specific names inside the
decompressed content. It accepts either full
file names or bare stems without extensions.
character. Returns the path to the fetched and decompressed
NFI data (.mdb, .DBF, .accdb, or other extensions requested in
file_ext) stored in a temporary file.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
## Process SNF data for Toledo stored locally # Path to Toledo data file in 'basifoR' package ifn4p45 <- system.file("Ifn4_Toledo.zip", package="basifoR") # Decompress SNF data from the specified file path or URL fetch_ifn4p45 <- fetchNFI(ifn4p45) print(fetch_ifn4p45) ## French NFI tree table read from the official web resource ## f <- "https://inventaire-forestier.ign.fr/dataifn/data/export_dataifn_2024_en.zip" ## fnfi <- fetchNFI(f, file_ext = "csv", file_name = "ARBRE") ## print(fnfi)## Process SNF data for Toledo stored locally # Path to Toledo data file in 'basifoR' package ifn4p45 <- system.file("Ifn4_Toledo.zip", package="basifoR") # Decompress SNF data from the specified file path or URL fetch_ifn4p45 <- fetchNFI(ifn4p45) print(fetch_ifn4p45) ## French NFI tree table read from the official web resource ## f <- "https://inventaire-forestier.ign.fr/dataifn/data/export_dataifn_2024_en.zip" ## fnfi <- fetchNFI(f, file_ext = "csv", file_name = "ARBRE") ## print(fnfi)
Compute SNFI IAVC using the variables required by the selected model.
get_snfi_iavc(dbh_mm = NULL, dnm_mm = NULL, h_t = NULL, vcc = NULL, pars)get_snfi_iavc(dbh_mm = NULL, dnm_mm = NULL, h_t = NULL, vcc = NULL, pars)
dbh_mm |
Tree diameter at breast height in millimetres, when required by the model. |
dnm_mm |
Mean plot diameter in millimetres, when required by the model. |
h_t |
Tree height in metres, when required by the model. |
vcc |
Merchantable volume over bark in dm3, when required by the model. |
pars |
One-row |
This function evaluates the SNFI equation for annual increment
of volume over bark (IAVC) and returns the result in dm3.
It supports models 8, 13, 14, 16, 17, 18, 19, 20, 21, and 25.
The required inputs depend on the selected model.
Numeric IAVC in dm3. Returns NA_real_ when pars
is empty, when required inputs are missing, or when the model
is not recognised. Missing required inputs also trigger a
printed message. print("Model not recognized for IAVC.")
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
Compute SNFI VCC from tree diameter, height, and one coefficient row.
get_snfi_vcc(dbh_mm, h_t, pars)get_snfi_vcc(dbh_mm, h_t, pars)
dbh_mm |
Tree diameter at breast height in millimetres. |
h_t |
Tree height in metres. |
pars |
One-row |
This function evaluates the SNFI equation for merchantable
volume over bark (VCC) and returns the result in dm3.
It currently supports models 1 and 11 from the SNFI
coefficient table.
Numeric VCC in dm3. Returns NA_real_ when pars
is empty or when the model is not recognised. print("Model not recognized for VCC.")
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
Compute SNFI VLE from tree diameter or VCC and one coefficient row.
get_snfi_vle(dbh_mm = NULL, vcc = NULL, pars)get_snfi_vle(dbh_mm = NULL, vcc = NULL, pars)
dbh_mm |
Tree diameter at breast height in millimetres, when required by the model. |
vcc |
Merchantable volume over bark in dm3, when required by the model. |
pars |
One-row |
This function evaluates the SNFI equation for coarse woody
volume (VLE) and returns the result in dm3.
It supports models 10 and 12.
Numeric VLE in dm3. Returns NA_real_ when pars
is empty, when required inputs are missing, or when the model
is not recognised. Missing required inputs also trigger a
printed message. print("Model not recognized for VLE.")
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
Compute SNFI VSC from VCC and one coefficient row.
get_snfi_vsc(vcc, pars)get_snfi_vsc(vcc, pars)
vcc |
Merchantable volume over bark in dm3. |
pars |
One-row |
This function evaluates the SNFI equation for merchantable
volume under bark (VSC) and returns the result in dm3.
It currently supports model 7.
Numeric VSC in dm3. Returns NA_real_ when pars
is empty or when the model is not recognised. print("Model not recognized for VSC.")
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
Resolve a Spanish province identifier to the corresponding archive URL for the requested Spanish National Forest Inventory (SNFI) stage and download/extract the matching files with fetchNFI. When provincia is already a local .zip path or a remote archive URL, the function skips province resolution and fetches that archive directly.
getNFI(provincia, nfi.nr = 4, ...)getNFI(provincia, nfi.nr = 4, ...)
provincia |
|
nfi.nr |
|
... |
Additional arguments passed to |
getNFI() is a light wrapper around the internal stage-specific resolvers nfi2(), nfi3(), and nfi4() plus fetchNFI. For province inputs, it first translates provincia to the archive URL that corresponds to nfi.nr. It then downloads the archive when needed, extracts the requested files, and returns the extracted paths.
Use nfi.nr = 2, 3, or 4 to target the corresponding SNFI stage. Use ... to restrict the extracted files, for example with file_ext or file_name as supported by fetchNFI. This function fetches files; use readNFI to import the extracted tables into R.
character. Paths to extracted inventory files returned by fetchNFI. The result is typically a vector of .mdb, .accdb, .dbf, or other requested files inside the retrieved archive.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
## Fetch bundled Toledo data from the example archive shipped with basifoR toledo_zip <- system.file("Ifn4_Toledo.zip", package = "basifoR") files <- getNFI(toledo_zip) ## Show the extracted filenames basename(files)## Fetch bundled Toledo data from the example archive shipped with basifoR toledo_zip <- system.file("Ifn4_Toledo.zip", package = "basifoR") files <- getNFI(toledo_zip) ## Show the extracted filenames basename(files)
Run a complete inventory workflow by dispatching to either
dendroMetrics for Spanish National Forest Inventory
inputs or to external_dendroMetrics() for external
inventories. The function is intentionally thin: it decides which
backend to use, forwards the relevant arguments, and stores the
original call so the result can be updated later with
update.
inventoryMetrics(nfi, backend = c("auto", "snfi", "external"), summ.vr = "Estadillo", cut.dt = "d == d", report = FALSE, mc.cores = getOption("mc.cores", 1L), design = NULL, schema = NULL, method_registry = NULL, parameter_table = NULL, ...)inventoryMetrics(nfi, backend = c("auto", "snfi", "external"), summ.vr = "Estadillo", cut.dt = "d == d", report = FALSE, mc.cores = getOption("mc.cores", 1L), design = NULL, schema = NULL, method_registry = NULL, parameter_table = NULL, ...)
nfi |
|
backend |
|
summ.vr |
|
cut.dt |
|
report |
|
mc.cores |
|
design |
Optional sampling |
schema |
Optional external |
method_registry |
Optional method registry passed to the
<< selected |
parameter_table |
Optional table of parameters required
<< by the external |
... |
Additional named arguments forwarded to the selected
<< |
The dispatcher keeps computation inside the backend
functions. It only validates the backend choice,
forwards arguments, stores the reconstructed call in
attr(x, "call"), and records the chosen backend in
attr(x, "backend"). That makes the wrapper easier
to maintain while preserving a single public entry point.
A backend result augmented with class
"inventoryMetrics", a stored call in
attr(x, "call"), and the selected backend in
attr(x, "backend"). The returned object otherwise
preserves the class and attributes produced by the backend.
Keep backend-specific computation in the backend functions,
not in this dispatcher.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
dendroMetrics, nfiMetrics, metrics2Vol, update.inventoryMetrics
## Example with bundled Toledo data routed to the SNFI backend ifn4p45 <- system.file("Ifn4_Toledo.zip", package = "basifoR") x <- inventoryMetrics(ifn4p45, backend = "snfi") attr(x, "backend") ## External workflows require an external backend function and the ## corresponding schema, design, and parameter objects.## Example with bundled Toledo data routed to the SNFI backend ifn4p45 <- system.file("Ifn4_Toledo.zip", package = "basifoR") x <- inventoryMetrics(ifn4p45, backend = "snfi") attr(x, "backend") ## External workflows require an external backend function and the ## corresponding schema, design, and parameter objects.
Computes one or more tree-level volume variables from Spanish National Forest Inventory data. The function standardizes the input, selects the appropriate volume model for each tree, applies equation-based methods defined in a method registry, converts results to cubic metres, and optionally keeps legacy outputs (from previous versions of the package) and provenance information.
metrics2Vol(nfi, cub.met = "freq", parametro = c("VCC"), keep.var = TRUE, keep.legacy = FALSE, method_registry = snfi_volume_method_registry(), track_provenance = FALSE, ...)metrics2Vol(nfi, cub.met = "freq", parametro = c("VCC"), keep.var = TRUE, keep.legacy = FALSE, method_registry = snfi_volume_method_registry(), track_provenance = FALSE, ...)
nfi |
Input accepted by 'nfiMetrics()', or a precomputed '"nfiMetrics"' object with tree-level metrics. |
cub.met |
Cubication selector used when several coefficient rows match. |
parametro |
One or more volume outputs to compute. |
keep.var |
Keep auxiliary coefficient columns when available. |
keep.legacy |
Also return the legacy volume estimate for backward compatibility. |
method_registry |
Registry that maps each requested output to its equation function, output column name, units, and fallback rule. |
track_provenance |
Add per-row provenance columns and audit metadata. |
... |
Passed to 'nfiMetrics()' when 'nfi' is not already an '"nfiMetrics"' object. |
Computes requested volume outputs from standardized NFI
tree metrics using registry-based methods and optional
fallback to legacy estimates.
A data.frame with the requested volume outputs added.
Registry-based dispatcher for volume equations. Return early for 'NULL' input. Build dendrometric metrics when the input is not already standardized. Resolve the inventory edition from the object attribute first and from a column only as a fallback. Match the first available column name among accepted aliases. Identify the core columns needed by the volume equations. Validate and standardize measurement-unit metadata before dispatching any equation. Validate requested outputs against the method registry. Preallocate all requested output columns. Compute the legacy volume once so modern methods can fall back to it when needed. Decide whether legacy estimates can be computed from the input. need_legacy <- keep.legacy || any(parametro %in% c("V", "VCC")) Load and normalize the coefficient table used by registry-based methods. Convert relevant inputs and coefficient keys to numeric values. Cache row matches to avoid repeated filtering of the same coefficient subset. Resolve the parameter row for one method and one tree. Resolve the equation function for one registry entry. Evaluate one registry method and return both value and provenance. Evaluate methods row by row. 'VCC' is computed first because later outputs may reuse it. Drop auxiliary coefficient columns when requested. Keep only the requested computed outputs. Reorder identifying columns to the front of the output. Rebuild units from surviving input columns plus returned volume outputs. 'nfiMetrics' stores units as a named vector: names = variable names, values = unit strings. Add units for the computed outputs that are returned. Computed outputs override any original units with the same name. Keep units only for columns present in the final output.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
nfiMetrics, snfi_volume_method_registry
if (FALSE) { x <- nfiMetrics('toledo') y <- metrics2Vol(x, parametro = c('VCC', 'VSC')) head(y[c('nfi.nr', 'pr', 'especie', 'vcc', 'vsc')]) }if (FALSE) { x <- nfiMetrics('toledo') y <- metrics2Vol(x, parametro = c('VCC', 'VSC')) head(y[c('nfi.nr', 'pr', 'especie', 'vcc', 'vsc')]) }
Define a concentric inventory design from subplot radii and minimum diameter thresholds.
The constructor orders subplot tiers by minimum DBH, converts radii
to sampled area in square metres, computes trees-per-hectare
expansion factors, and returns an object of class
"concentric_design" inheriting from
"inventory_design".
new_concentric_design(radii_m, min_dbh_cm, name = "custom", metadata = NULL)new_concentric_design(radii_m, min_dbh_cm, name = "custom", metadata = NULL)
radii_m |
|
min_dbh_cm |
|
name |
|
metadata |
Optional |
The function delegates to new_inventory_design
and then appends the ordered radii_m vector plus the
class "concentric_design". The metadata
argument is merged with default entries for circular plot
shape and ordered radii using
utils::modifyList().
An object of class
c("concentric_design", "inventory_design"), returned
as a named list with components name,
min_dbh_cm, sample_area_m2, sf,
metadata, and radii_m. The
sample_area_m2 component stores subplot areas in
square metres, sf stores the corresponding
trees-per-hectare expansion factors, and
metadata contains the merged design metadata.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
dsg <- new_concentric_design( radii_m = c(5, 10, 15, 25), min_dbh_cm = c(7.5, 12.5, 22.5, 42.5), name = "SNFI" ) dsgdsg <- new_concentric_design( radii_m = c(5, 10, 15, 25), min_dbh_cm = c(7.5, 12.5, 22.5, 42.5), name = "SNFI" ) dsg
Create a reusable "external_schema" object that records how
Create a reusable schema with column aliases, units, default grouping settings, retained columns, and optional defaults for the external basifoR workflow.
source columns in an external inventory correspond to the standardized
Create a reusable schema with column aliases, units, default grouping settings, retained columns, and optional defaults for the external basifoR workflow.
field names used by the basifoR external workflow. The schema can also
Create a reusable schema with column aliases, units, default grouping settings, retained columns, and optional defaults for the external basifoR workflow.
store declared measurement units, default grouping levels, columns to
Create a reusable schema with column aliases, units, default grouping settings, retained columns, and optional defaults for the external basifoR workflow.
preserve during processing, and auxiliary defaults that wrapper
Create a reusable schema with column aliases, units, default grouping settings, retained columns, and optional defaults for the external basifoR workflow.
functions may reuse across repeated calls.
Create a reusable schema with column aliases, units, default grouping settings, retained columns, and optional defaults for the external basifoR workflow.
new_external_schema(colmap, units = list(), levels = NULL, keep_cols = NULL, defaults = list())new_external_schema(colmap, units = list(), levels = NULL, keep_cols = NULL, defaults = list())
colmap |
Named |
units |
Named |
levels |
Optional |
keep_cols |
Optional |
defaults |
Optional named |
The returned object is lightweight. It validates the basic
structure of the inputs, assigns class
c("external_schema", "list"), and leaves semantic
interpretation to downstream helpers such as
externalMetrics(), externalMetrics2Vol(), or
external_dendroMetrics().
An object of class "external_schema" containing normalized colmap, units, levels, keep_cols, and defaults components, ready to pass to external workflow wrappers.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
sch <- new_external_schema( colmap = list( plot = c("plot_id", "plot"), species = c("species_code", "sp"), d = c("dbh_mm", "diameter_mm"), h = c("height_m", "h") ), units = list(d = "mm", h = "m"), levels = "plot", keep_cols = c("plot_id", "species_code"), defaults = list(selector = "priority") ) class(sch) sch$colmap$d sch$units sch$levelssch <- new_external_schema( colmap = list( plot = c("plot_id", "plot"), species = c("species_code", "sp"), d = c("dbh_mm", "diameter_mm"), h = c("height_m", "h") ), units = list(d = "mm", h = "m"), levels = "plot", keep_cols = c("plot_id", "species_code"), defaults = list(selector = "priority") ) class(sch) sch$colmap$d sch$units sch$levels
Build a generic inventory design from tally areas and minimum DBH
Construct a generic "inventory_design" object from sampled areas and minimum DBH thresholds.
The function computes trees-per-hectare expansion factors for each tally tier and can represent circular,
square, strip, ring, or custom layouts through metadata.
thresholds. The function stores each tally tier, computes its
Construct a generic "inventory_design" object from sampled areas and minimum DBH thresholds.
The function computes trees-per-hectare expansion factors for each tally tier and can represent circular,
square, strip, ring, or custom layouts through metadata.
trees-per-hectare expansion factor, and returns an object of class
Construct a generic "inventory_design" object from sampled areas and minimum DBH thresholds.
The function computes trees-per-hectare expansion factors for each tally tier and can represent circular,
square, strip, ring, or custom layouts through metadata.
"inventory_design" for use in inventory workflows.
Construct a generic "inventory_design" object from sampled areas and minimum DBH thresholds.
The function computes trees-per-hectare expansion factors for each tally tier and can represent circular,
square, strip, ring, or custom layouts through metadata.
new_inventory_design(sample_area_m2, min_dbh_cm = 0, name = "custom", metadata = NULL)new_inventory_design(sample_area_m2, min_dbh_cm = 0, name = "custom", metadata = NULL)
sample_area_m2 |
|
min_dbh_cm |
|
name |
|
metadata |
Optional |
The object is shape-agnostic. Use metadata to record
how the sampled area was obtained, for example from
circular radii, square side lengths, strip dimensions, or
protocol notes. The constructor stores metadata as
supplied and does not validate or reorder its contents.
An object of class "inventory_design", returned as a
named list with components name,
min_dbh_cm, sample_area_m2, sf, and
metadata. sf gives the trees-per-hectare
expansion factor for each tally tier.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
dsg <- new_inventory_design( sample_area_m2 = c(400, 100), min_dbh_cm = c(20, 0), name = "Nested square design", metadata = list(shape = "square", side_m = c(20, 10)) ) dsg$min_dbh_cm dsg$sfdsg <- new_inventory_design( sample_area_m2 = c(400, 100), min_dbh_cm = c(20, 0), name = "Nested square design", metadata = list(shape = "square", side_m = c(20, 10)) ) dsg$min_dbh_cm dsg$sf
Creates a compact method specification for the external volume registry. A method definition tells
Create a method specification for registry-based volume calculations in external inventory workflows.
externalMetrics2Vol which output to compute, where to find or resolve parameters, how to
Create a method specification for registry-based volume calculations in external inventory workflows.
build the argument list for the equation, how to scale the raw result to cubic metres, and which
Create a method specification for registry-based volume calculations in external inventory workflows.
fallback to return when a direct computation is not possible.
Create a method specification for registry-based volume calculations in external inventory workflows.
new_volume_method(output, fun = NULL, fun_name = NULL, unit = "m3", raw_unit = unit, scale_to_m3 = 1, build_args = function(ctx, pars, resolved) list(), fallback = function(ctx, pars, resolved) null_or(resolved$preexisting_v_m3, NA_real_), match_by = character(0), get_pars = NULL, pars = NULL, filter_pars = NULL, required_inputs = NULL)new_volume_method(output, fun = NULL, fun_name = NULL, unit = "m3", raw_unit = unit, scale_to_m3 = 1, build_args = function(ctx, pars, resolved) list(), fallback = function(ctx, pars, resolved) null_or(resolved$preexisting_v_m3, NA_real_), match_by = character(0), get_pars = NULL, pars = NULL, filter_pars = NULL, required_inputs = NULL)
output |
|
fun |
Optional |
fun_name |
Optional |
unit |
|
raw_unit |
|
scale_to_m3 |
|
build_args |
|
fallback |
fallback |
match_by |
|
get_pars |
Optional |
pars |
Optional embedded parameter table stored inside the method definition. |
filter_pars |
Optional |
required_inputs |
Optional |
The fallback function should return a scalar numeric value, typically NA_real_ or a pre-existing volume estimate already present in the data. Define required_inputs with the standardized variable names expected by the method so the workflow can resolve prerequisites before evaluation.
A named list describing one external volume method.
The list contains the components output, fun,
fun_name, unit, raw_unit,
scale_to_m3, build_args, fallback,
match_by, get_pars, pars,
filter_pars, and required_inputs.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
## Minimal standalone example vm <- new_volume_method( output = "vcc", fun = function(dbh_cm, h_m, pars) dbh_cm * h_m * pars$k[1], unit = "m3", raw_unit = "cm3", scale_to_m3 = 1 / 1e6, build_args = function(ctx, pars, resolved) { list(dbh_cm = ctx$d_cm, h_m = ctx$h_m, pars = pars) }, fallback = function(ctx, pars, resolved) NA_real_, match_by = "species", pars = data.frame(species = "sp1", k = 2500), required_inputs = c("d", "h") ) names(vm) vm$output vm$build_args( ctx = list(d_cm = 20, h_m = 12), pars = vm$pars, resolved = list() )## Minimal standalone example vm <- new_volume_method( output = "vcc", fun = function(dbh_cm, h_m, pars) dbh_cm * h_m * pars$k[1], unit = "m3", raw_unit = "cm3", scale_to_m3 = 1 / 1e6, build_args = function(ctx, pars, resolved) { list(dbh_cm = ctx$d_cm, h_m = ctx$h_m, pars = pars) }, fallback = function(ctx, pars, resolved) NA_real_, match_by = "species", pars = data.frame(species = "sp1", k = 2500), required_inputs = c("d", "h") ) names(vm) vm$output vm$build_args( ctx = list(d_cm = 20, h_m = 12), pars = vm$pars, resolved = list() )
Compute tree-level diameter, height, basal area, trees per
hectare, and optional dominant height from Spanish National Forest
Inventory inputs. Supply either an object returned by
readNFI or a path/URL that readNFI
can import. The function returns the requested metrics together
with the matched grouping columns and attaches unit metadata to the
result.
nfiMetrics(nfi, var = c("d", "h", "ba", "n", "Hd"), levels = c("esta", "espe"), design = snfi_design(), ...)nfiMetrics(nfi, var = c("d", "h", "ba", "n", "Hd"), levels = c("esta", "espe"), design = snfi_design(), ...)
nfi |
|
var |
|
levels |
|
design |
Sampling |
... |
Additional arguments passed to |
If you request 'Hd', the function computes
dominant height within the groups selected by
levels by using 'h', 'd', and
'n'.
data.frame with the matched identifier and grouping
columns plus the metrics requested in var. The output
inherits from 'nfiMetrics' and 'data.frame' and
stores attr(x, 'nfi.nr') when available. Inspect
attr(x, 'units') for the returned metric units and
attr(x, 'design_meta') for the sampling design summary
attached when 'n' or 'Hd' is requested.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
dendroMetrics, dbhMetric, readNFI, snfi_design, trees_per_ha
## Minimal reproducible example with a small object that mimics ## readNFI() output toy_ifn <- structure( data.frame( esta = c("plot1", "plot1", "plot2"), espe = c("sp1", "sp2", "sp1"), Dn = c(120, 185, 260), altura = c(7.1, 9.4, 13.2), stringsAsFactors = FALSE ), class = c("readNFI", "data.frame"), nfi.nr = 4 ) x <- nfiMetrics( toy_ifn, var = c("d", "h", "ba", "n"), levels = c("esta", "espe") ) x attr(x, "units")## Minimal reproducible example with a small object that mimics ## readNFI() output toy_ifn <- structure( data.frame( esta = c("plot1", "plot1", "plot2"), espe = c("sp1", "sp2", "sp1"), Dn = c(120, 185, 260), altura = c(7.1, 9.4, 13.2), stringsAsFactors = FALSE ), class = c("readNFI", "data.frame"), nfi.nr = 4 ) x <- nfiMetrics( toy_ifn, var = c("d", "h", "ba", "n"), levels = c("esta", "espe") ) x attr(x, "units")
Display the main components of a "concentric_design" object:
Display the main components of a "concentric_design" object.
The printed summary reports the design name together with subplot radii, minimum DBH thresholds, and expansion factors for each tally tier.
design name, subplot radii, minimum diameters, and expansion factors.
Display the main components of a "concentric_design" object.
The printed summary reports the design name together with subplot radii, minimum DBH thresholds, and expansion factors for each tally tier.
## S3 method for class 'concentric_design' print(x, ...)## S3 method for class 'concentric_design' print(x, ...)
x |
Object of class |
... |
Further arguments passed to methods. Currently unused. |
The function does not modify the design and does not currently use additional arguments passed through ....
The input "concentric_design" object, returned invisibly.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
dsg <- new_concentric_design( radii_m = c(5, 10, 15), min_dbh_cm = c(7.5, 22.5, 42.5), name = "Example concentric design" ) print.concentric_design(dsg) invisible(NULL)dsg <- new_concentric_design( radii_m = c(5, 10, 15), min_dbh_cm = c(7.5, 22.5, 42.5), name = "Example concentric design" ) print.concentric_design(dsg) invisible(NULL)
Display the column mappings, declared units, and default grouping levels stored in an "external_schema" object.
## S3 method for class 'external_schema' print(x, ...)## S3 method for class 'external_schema' print(x, ...)
x |
An |
... |
Additional arguments accepted for S3 compatibility and ignored by this method. |
The input "external_schema" object, returned invisibly.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
Display the main stored components of an "inventory_design"
Print a compact summary of an "inventory_design" object.
The method reports the stored design name, minimum DBH thresholds,
sampled areas, and trees-per-hectare expansion factors.
object in a compact human-readable summary.
Print a compact summary of an "inventory_design" object.
The method reports the stored design name, minimum DBH thresholds,
sampled areas, and trees-per-hectare expansion factors.
## S3 method for class 'inventory_design' print(x, ...)## S3 method for class 'inventory_design' print(x, ...)
x |
Object of class |
... |
Further arguments passed to methods. Currently unused. |
The method does not modify the object.
The input "inventory_design" object, returned invisibly.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
dsg <- new_inventory_design( sample_area_m2 = c(400, 100), min_dbh_cm = c(20, 0), name = "Nested square design" ) print(dsg)dsg <- new_inventory_design( sample_area_m2 = c(400, 100), min_dbh_cm = c(20, 0), name = "Nested square design" ) print(dsg)
Read raw tables from the Spanish National Forest Inventory (SNFI)
Import raw inventory tables from
the Spanish National Forest Inventory (SNFI)
or compatible tabular exports. Use
readNFI() when you need the original
table structure before computing metrics with
higher-level workflows.
and compatible inventory exports. The function accepts province
Import raw inventory tables from
the Spanish National Forest Inventory (SNFI)
or compatible tabular exports. Use
readNFI() when you need the original
table structure before computing metrics with
higher-level workflows.
identifiers that are resolved to official SNFI download URLs, local
Import raw inventory tables from
the Spanish National Forest Inventory (SNFI)
or compatible tabular exports. Use
readNFI() when you need the original
table structure before computing metrics with
higher-level workflows.
or remote .zip archives, and direct paths to decompressed
Import raw inventory tables from
the Spanish National Forest Inventory (SNFI)
or compatible tabular exports. Use
readNFI() when you need the original
table structure before computing metrics with
higher-level workflows.
.csv, .dbf, .mdb, or .accdb files.
Import raw inventory tables from
the Spanish National Forest Inventory (SNFI)
or compatible tabular exports. Use
readNFI() when you need the original
table structure before computing metrics with
higher-level workflows.
readNFI(nfi, nfi.nr = 4, dt.nm = "PCMayores", file_ext = NULL, file_name = NULL, ...)readNFI(nfi, nfi.nr = 4, dt.nm = "PCMayores", file_ext = NULL, file_name = NULL, ...)
nfi |
|
nfi.nr |
|
dt.nm |
|
file_ext |
|
file_name |
|
... |
Additional arguments passed to |
The input nfi can be supplied
in three main forms. First, it can be a
province name or code; in that case,
readNFI() resolves the identifier to
an official SNFI download URL according to
nfi.nr. Second, it can be a local or
remote .zip archive; the function then
delegates extraction to fetchNFI.
Third, it can be one or more already
decompressed file paths.
When the selected files are .csv, the
function detects the field separator
automatically and returns either one data
frame or a named list of data frames. When the
selected files are Access or DBF tables from
the SNFI, the function reads the requested
table, converts numeric-looking factors back to
numeric values, preserves character columns,
and adds province and inventory-stage metadata.
Access backends are platform dependent. On
Windows, reading .mdb or .accdb
files requires package RODBC and an
installed Microsoft Access driver. On
Unix-like systems, it requires package
Hmisc together with the external
mdbtools utilities. Use
file_ext = "csv" to bypass those
dependencies when you work with zipped CSV
exports.
Returns one of three object types, depending on the input.
First, when nfi resolves to .csv file paths, the
function returns a single data.frame for one file or a named
list of data.frames for several files. Second, when
it reads Access or DBF tables from the SNFI, it returns a
data.frame of class c("readNFI", "data.frame").
This object includes leading columns nfi.nr and pr,
stores the province vector in attr(x, "pr."), and stores the
inferred inventory stage in attr(x, "nfi.nr"). Third, the
function returns NULL when fetching, extraction, or import
fails, or when no requested file can be read.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
## Minimal example using a local CSV file created on the fly tmp <- tempfile(fileext = ".csv") utils::write.table( data.frame( plot = 1:2, species = c("sp1", "sp2"), dbh_cm = c(12.5, 18.0) ), file = tmp, sep = ";", row.names = FALSE, quote = FALSE ) x <- readNFI(tmp) str(x) unlink(tmp)## Minimal example using a local CSV file created on the fly tmp <- tempfile(fileext = ".csv") utils::write.table( data.frame( plot = 1:2, species = c("sp1", "sp2"), dbh_cm = c(12.5, 18.0) ), file = tmp, sep = ";", row.names = FALSE, quote = FALSE ) x <- readNFI(tmp) str(x) unlink(tmp)
Return the predefined concentric sampling design used by basifoR for Spanish National Forest Inventory workflows.
snfi_design()snfi_design()
Use this function when you want the default SNFI design object explicitly, for example before calling trees_per_ha or when inspecting the design used by SNFI-oriented workflows.
An object of class "concentric_design" that also inherits from "inventory_design". It stores the default SNFI subplot radii, minimum DBH thresholds, sampled areas, expansion factors, design name, and metadata.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
snfi_design()snfi_design()
Return the final registry of SNFI volume methods after merging package defaults, optional user definitions, and session-level option overrides.
snfi_volume_method_registry(equations = get0("snfi_volume_equations", inherits = TRUE, ifnotfound = NULL))snfi_volume_method_registry(equations = get0("snfi_volume_equations", inherits = TRUE, ifnotfound = NULL))
equations |
equations |
Each registry entry is a named list that typically contains fields such
as output, fun_name, unit, raw_unit,
scale_to_m3, build_args, and fallback. The
function checks only that the supplied registry is a named list;
downstream functions validate and use the individual fields.
A named list of SNFI volume-method definitions.
Names usually correspond to requested parameters such as "V",
"VCC", and "VSC".
Each element describes one computation pathway and commonly includes:
outputName of the output column returned by the method.
fun_nameName of the equation helper called at run time, or NULL for direct passthrough methods.
unitReturned unit after scaling, usually "m3 tree-1".
raw_unitUnit returned by the underlying equation before scaling.
scale_to_m3Multiplier applied to raw outputs to express them in cubic metres.
build_argsFunction that builds the argument list for the equation helper.
fallbackFunction used when coefficients are missing or a method cannot compute the requested output.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
c( "reg <- snfi_volume_method_registry()", "names(reg)", "reg$VCC$output", "custom <- list(VCC = list(output = 'vcc_m3'))", "reg2 <- snfi_volume_method_registry(custom)", "reg2$VCC$output" )c( "reg <- snfi_volume_method_registry()", "names(reg)", "reg$VCC$output", "custom <- list(VCC = list(output = 'vcc_m3'))", "reg2 <- snfi_volume_method_registry(custom)", "reg2$VCC$output" )
Dispatch on the sampling-design class to return the expansion factor,
Return the expansion factor, expressed as trees per hectare, associated with a tree of a given diameter at breast height under a supported inventory design.
expressed as trees per hectare, associated with a tree of a given
Return the expansion factor, expressed as trees per hectare, associated with a tree of a given diameter at breast height under a supported inventory design.
diameter at breast height.
Return the expansion factor, expressed as trees per hectare, associated with a tree of a given diameter at breast height under a supported inventory design.
trees_per_ha(design, dbh_cm)trees_per_ha(design, dbh_cm)
design |
Sampling |
dbh_cm |
|
Current methods return NA_real_ when diameter is
missing after preprocessing or falls below the smallest
supported threshold in the supplied design.
A single numeric value giving the trees-per-hectare
expansion factor for the supplied diameter and design, or
NA_real_ when no valid factor can be assigned.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
dsg <- new_inventory_design(sample_area_m2 = c(100, 400), min_dbh_cm = c(0, 20)) trees_per_ha(dsg, 13)dsg <- new_inventory_design(sample_area_m2 = c(100, 400), min_dbh_cm = c(0, 20)) trees_per_ha(dsg, 13)
Match a tree diameter to the appropriate subplot of a
Return the trees-per-hectare expansion factor for a tree measured under a concentric subplot design.
"concentric_design" object and return the corresponding
Return the trees-per-hectare expansion factor for a tree measured under a concentric subplot design.
trees-per-hectare expansion factor.
Return the trees-per-hectare expansion factor for a tree measured under a concentric subplot design.
## S3 method for class 'concentric_design' trees_per_ha(design, dbh_cm)## S3 method for class 'concentric_design' trees_per_ha(design, dbh_cm)
design |
Object of class |
dbh_cm |
|
It returns NA_real_ when all supplied diameters are
missing or when the resulting diameter is smaller than the
smallest subplot threshold.
A single numeric expansion factor in trees per hectare
taken from design$sf, or NA_real_ when the tree
does not belong to any subplot tier.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
trees_per_ha(snfi_design(), 13)trees_per_ha(snfi_design(), 13)
Match a tree diameter to the tally tier of a generic
Return the trees-per-hectare expansion factor for a tree measured under a generic inventory design.
"inventory_design" object and return the corresponding
Return the trees-per-hectare expansion factor for a tree measured under a generic inventory design.
trees-per-hectare expansion factor.
Return the trees-per-hectare expansion factor for a tree measured under a generic inventory design.
## S3 method for class 'inventory_design' trees_per_ha(design, dbh_cm)## S3 method for class 'inventory_design' trees_per_ha(design, dbh_cm)
design |
Object of class |
dbh_cm |
|
It returns NA_real_ when all supplied diameters are
missing or when the resulting diameter is smaller than the
minimum threshold supported by the design.
A single numeric expansion factor in trees per hectare
taken from design$sf, or NA_real_ when the tree
does not belong to any tally tier.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
dsg <- new_inventory_design(sample_area_m2 = c(100, 400), min_dbh_cm = c(0, 20), name = "Example design") trees_per_ha(dsg, 13)dsg <- new_inventory_design(sample_area_m2 = c(100, 400), min_dbh_cm = c(0, 20), name = "Example design") trees_per_ha(dsg, 13)
Re-run dendroMetrics from the call stored
in a previous "dendroMetrics" result while replacing one or
more named arguments in .... This method supports reproducible
re-evaluation of the original workflow and can either return the
updated result or the reconstructed call.
## S3 method for class 'dendroMetrics' update(object, ..., evaluate = TRUE)## S3 method for class 'dendroMetrics' update(object, ..., evaluate = TRUE)
object |
A |
... |
Named arguments used to replace entries in the stored call before evaluation. |
evaluate |
|
A new "dendroMetrics" object when
evaluate = TRUE; otherwise the updated call.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
Rebuild the call stored in a previous "external_dendroMetrics" result, optionally replace named arguments, and either evaluate the updated call or return it unevaluated.
## S3 method for class 'external_dendroMetrics' update(object, ..., evaluate = TRUE)## S3 method for class 'external_dendroMetrics' update(object, ..., evaluate = TRUE)
object |
Object returned by |
... |
Named arguments used to replace entries in the stored call. |
evaluate |
If |
The method checks that object inherits from "external_dendroMetrics" and that the original matched call is stored in attr(\code{object}, "call"). It then replaces any named arguments supplied in ... inside that stored call.
Use evaluate = FALSE to inspect the reconstructed call before execution. This is useful when debugging filters, grouping variables, schemas, or volume-method options.
The method checks that object inherits from
"external_dendroMetrics" and that it stores the original
matched call in attr(\code{object}, "call"). It then replaces any
named arguments supplied in ... inside that stored call.
Use evaluate = FALSE to inspect the reconstructed call
before execution, which is useful when debugging filters,
grouping variables, schemas, or volume-method options.
The method only changes arguments supplied explicitly in
...; all other arguments remain as stored in the original
call.
A new "external_dendroMetrics" object when evaluate = TRUE; otherwise the updated call.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
x <- structure( data.frame(plot = "P1", d = 12, h = 8), class = c("external_dendroMetrics", "dendroMetrics", "data.frame") ) attr(x, "call") <- quote( external_dendroMetrics( x = data.frame(plot = "P1", d = 12, h = 8), var = c("d", "h"), summ.vr = NULL ) ) update(x, var = c("d", "h", "ba"), evaluate = FALSE)x <- structure( data.frame(plot = "P1", d = 12, h = 8), class = c("external_dendroMetrics", "dendroMetrics", "data.frame") ) attr(x, "call") <- quote( external_dendroMetrics( x = data.frame(plot = "P1", d = 12, h = 8), var = c("d", "h"), summ.vr = NULL ) ) update(x, var = c("d", "h", "ba"), evaluate = FALSE)
Re-run inventoryMetrics from the call
stored in a previous "inventoryMetrics" result while
replacing one or more named arguments in .... This method
supports reproducible re-evaluation of the selected backend and can
either return the updated result or the reconstructed call.
## S3 method for class 'inventoryMetrics' update(object, ..., evaluate = TRUE)## S3 method for class 'inventoryMetrics' update(object, ..., evaluate = TRUE)
object |
A |
... |
Named arguments used to replace entries in the stored << call before evaluation. |
evaluate |
|
A new "inventoryMetrics" object when
evaluate = TRUE; otherwise the updated call.
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)
update
Guard against raw dendroMetrics inputsCatch attempts to call update
on raw input lists intended for dendroMetrics and
return a workflow-specific error message. When the input does not
look like a dendroMetrics workflow, this method falls back to
update.default.
## S3 method for class 'list' update(object, ..., evaluate = TRUE)## S3 method for class 'list' update(object, ..., evaluate = TRUE)
object |
A |
... |
Additional arguments passed to |
evaluate |
|
Either an error with a dendroMetrics-specific
message or the result of update.default().
Wilson Lara <[email protected]> [aut, cre] (ORCID: <https://orcid.org/0000-0003-3527-1380>), Cristobal Ordonez <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-5354-3760>), Aitor Vázquez-Veloso <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0003-0227-506X>), Felipe Bravo <[email protected]> [aut] (ORCID: <https://orcid.org/0000-0001-7348-6695>)