| readNFI | R Documentation |
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,
...)
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 [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>)
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.