Skip to content

Commit

Permalink
Fix broken datamart links
Browse files Browse the repository at this point in the history
  • Loading branch information
hunter-stanke committed Apr 9, 2023
1 parent f10e09f commit b80e180
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions R/readWriteGet.R
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ getFIA <- function(states,
stop('Must specify a directory ("dir") to save data when "load = FALSE".')
}

if ('REF' %in% states & length(unique(states)) > 1) {
stop('Please download reference tables and state subsets seperately.')
}

## All or nothing w/ new FIADB for some reason
if (states == 'REF') {
tables <- NULL
}

## If dir is not specified, hold in a temporary directory
#if (is.null(dir)){tempDir <- tempdir()}
tempDir <- tempdir()
Expand Down Expand Up @@ -423,17 +432,13 @@ Did you accidentally include the state abbreviation in front of the table name?
# Make sure state Abbs are in right format
states <- str_to_upper(states)

## If you want all of the reference tables zipped together
if ('REF' %in% states) {
states[states == 'REF'] <- 'FIADB_REFERENCE'
}

## Download each state and extract to directory
for (i in 1:length(states)){
# Temporary directory to download to
temp <- paste0(tempDir, '/', states[i],'.zip') #tempfile()
temp <- paste0(tempDir, '/', states[i],'_CSV.zip') #tempfile()
## Make the URL
url <- paste0('https://apps.fs.usda.gov/fia/datamart/CSV/', states[i],'.zip')
url <- paste0('https://apps.fs.usda.gov/fia/datamart/CSV/', states[i],'_CSV.zip')
if (states == 'REF') {url <- paste0('https://apps.fs.usda.gov/fia/datamart/CSV/FIADB_REFERENCE.zip')}
#newName <- paste0(str_sub(url, 1, -4), 'csv')
## Download as temporary file
download.file(url, temp, timeout = 3600)
Expand All @@ -448,11 +453,6 @@ Did you accidentally include the state abbreviation in front of the table name?

if (load){

## If you want all of the reference tables read in, change it back
if ('FIADB_REFERENCE' %in% states) {
states[states == 'FIADB_REFERENCE'] <- 'REF'
}

## Read in the files w/ readFIA
if (is.null(dir)){
outTables <- readFIA(tempDir, nCores = nCores, common = common, states = states)
Expand Down

0 comments on commit b80e180

Please sign in to comment.