| listNFI_tables | R Documentation |
Discover the raw tables or
files available in Spanish National Forest
Inventory (SNFI) downloads, local archives,
or already decompressed files. The function
helps users inspect available table names
before reading data with readNFI().
listNFI_tables(nfi, nfi.nr = 4,
dir = tempdir(),
file_ext = NULL,
file_name = NULL,
...)
nfi |
|
nfi.nr |
|
dir |
|
file_ext |
|
file_name |
|
... |
Additional arguments passed to |
The input nfi can be a
province name or province code, a local or
remote .zip archive, or one or more
already decompressed .dbf, .mdb,
.accdb, or .csv files.
When nfi is a province identifier, the
function resolves it with the internal URL
resolver selected by nfi.nr: nfi2(),
nfi3(), or nfi4(). It then calls
fetchNFI() to download or reuse the
corresponding local files.
For second-stage SNFI data and other DBF-based
sources, the function lists one row per DBF file
and uses the DBF file stem as dt.nm. For
CSV sources, it lists one row per CSV file and
also uses the file stem as dt.nm. For
Access sources, it lists one row per table found
inside each .mdb or .accdb file.
The function does not read full data tables. It
only discovers table or file names. However, it
must inspect local files. Therefore, when nfi
is remote or province-based, at least one download
or extraction step can be necessary unless the
files already exist in the same dir cache.
The arguments file_ext and file_name
are forwarded to fetchNFI() only when they
are not NULL. This keeps fetchNFI()
as the single authority for default downloadable
extensions and matches the forwarding style used
by readNFI().
Access table listing is platform dependent. On
Windows it requires RODBC and a Microsoft
Access ODBC driver. Package odbc is optional
and is used only to check whether such a driver is
visible. On Unix-like systems, table listing
requires the external mdbtools command
mdb-tables.
A data.frame with one row per discovered raw table
or file. The columns are source, which identifies the
backend as "DBF", "CSV", or "Access";
dt.nm, the table or file stem that users can pass to
readNFI() when appropriate; file, the local file
basename; and path, the normalized local file path. The
function returns an empty data frame with these columns when no
matching files or tables are found.
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>)
## Self-contained example using a temporary DBF file.
tmp <- tempfile(fileext = ".dbf")
foreign::write.dbf(
data.frame(
plot = 1:2,
tree = 1:2,
dbh = c(15.2, 31.8)
),
file = tmp
)
tabs <- listNFI_tables(tmp)
tabs[, c("source", "dt.nm", "file")]
unlink(tmp)
## Typical SNFI use with a persistent cache directory.
## This can download data and may require mdbtools or an Access driver,
## so it is intentionally left as commented example code.
## cache <- tools::R_user_dir("basifoR", "cache")
## tabs4 <- listNFI_tables(28, nfi.nr = 4, dir = cache)
## head(tabs4)
## x4 <- readNFI(28, nfi.nr = 4, dt.nm = "PCMayores", dir = cache)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.