listNFI_tables: List available raw SNFI tables

listNFI_tablesR Documentation

List available raw SNFI tables

Description

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().

Usage

listNFI_tables(nfi, nfi.nr = 4, 
    dir = tempdir(), 
    file_ext = NULL, 
    file_name = NULL, 
    ...)

Arguments

nfi

character or numeric. Inventory source to inspect. Accepted values are: (i) a province name or province code to be resolved to an official SNFI download URL; (ii) a local or remote .zip archive; or (iii) one or more direct paths to decompressed .dbf, .mdb, .accdb, or .csv files.

nfi.nr

integer. SNFI stage used when nfi is given as a province identifier. Use 2, 3, or 4. The value selects the internal URL resolver nfi2(), nfi3(), or nfi4().

dir

character. Directory used by fetchNFI() to store downloaded archives and extracted files. Use the same dir in later calls to readNFI() to reuse cached files and avoid unnecessary downloads.

file_ext

character or NULL. Optional file extension or extensions forwarded to fetchNFI. Leave NULL to use the default extensions defined by fetchNFI().

file_name

character or NULL. Optional file name or bare stem forwarded to fetchNFI to keep only specific files inside a compressed archive.

...

Additional arguments passed to fetchNFI, such as timeOut = httr::timeout(120).

Details

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.

Value

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.

Author(s)

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>)

Examples

## 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)

basifoR documentation built on Aug. 26, 2026, 9:06 a.m.