Chapter 2 Download FIA
Note that as of 03 Mar 2024 the rFIA R package has not been updated for approximately 1 year. Therefore, some functionality has been lost because the package is not being actively maintained. For example, downloading FIA data for multiple states using the getFIA() function currently results in an error due to recent updates to the online FIA database (FIA DataMart).
Currently, there are two suggested work-arounds: 1) Download the outdated package and manually fix the source code, or 2) Download the rFIA package from an alternative repo with some fixes already applied.
2.2 Setup parallel processing
Setting up parallel processing in R may help with downloading extensive amounts of data from the FIA datamart:
## How many physical cores do you have?
parallel::detectCores(logical = FALSE)
## How many cores do you want to use?
## If you still want to use your computer for anything else during the computations
## (e.g., checking your E-mails or writing a Word document),
## you should reserve at least one core for those remaining tasks.
cores <- parallel::detectCores(logical = FALSE)-2 # set to use all physical cores minus number needed for other processes. 2.3 Download FIA data for each state intersecting APPA
The rFIA function getFIA()(https://rdrr.io/cran/rFIA/man/getFIA.html) downloads State FIA Data from the FIA Datamart.
2.3.1 Test Run
Use the small “test dataset” below to see if the function is working properly before downloading the very large Appalachian trail dataset. Test dataset consists of a small amount of FIA data from US territories, American Samoa and Guam.
## Small subset of FIA dataset to test 'getFIA()' before big download
test <- c('AS', 'GU') # smallest datasets in 2023
## If dir = NULL tables will not be saved on disk and only loaded into R environment
test_FIA_db_object <- getFIA(states = test, dir = NULL, nCores = cores)
str(test_FIA_db_object)2.3.2 Save location
Choose where local FIA database tables will be saved:
## default location:
save_default <- './download_FIA/'
## Alternatively, enter specific custom location:
save_custom <- 'C:/Users/JJGross/Documents/R_projects/FIA_data/allStates'
## Specify `save_location <- save_custom` or `save_location <- save_default`
save_location <- save_default
## Create directory if it doesn't already exist
if (!dir.exists(save_location)) {dir.create(save_location)}2.3.3 Download all FIA data from all 13 APPA states:
This is a large amount of data and depending on connection, may take more than an hour to complete. Note that load = FALSE saves the dataset to hard drive location instead of loading directly into R session. The dataset saved to the hard drive will be loaded into R using steps outlined in the next chapter. “Clip”.
Argument common = TRUE only imports the most commonly used FIA tables, including all those required for rFIA functions.
# Change timeout options from default 60 seconds to 1 hour.
getOption('timeout')
options(timeout=3600)
## APPA States
at_states <- c('CT', 'GA', 'ME', 'MD', 'MA',
'NH', 'NJ', 'NY', 'NC', 'PA',
'TN', 'VT', 'VA')
## Download the data:
getFIA(states = at_states, dir = save_location,
nCores = cores, common = TRUE, load = FALSE)