R/getStateData.R

#' Download state tree databases from the FIA Data Mart
#' 
#' A function to download state tree databases (ST\_TREE.CSV) from the FIA data mart, found at \url{http://apps.fs.fed.us/fiadb-downloads/datamart.html}. This function may take a long time, because the data are large and the FIA Data Mart may be slow. You will receive an immediate error if the data are not available. Header=T is the only paramater passed into the read.csv function, you can pass others after the stateID parameter.
#' 
#' @param stateID The two character state code for the data needed. 
#' @export

getStateData <- function(stateID){
  requireNamespace("RCurl")
  loadNamespace("RCurl")
  base_url <- paste("http://apps.fs.fed.us/fiadb-downloads/", stateID, "_TREE.CSV", sep="")
  if(!RCurl::url.exists(base_url)){ stop("Invalid URL, try contacting package owner.")}
  return(read.csv(file=base_url, header=T, ...))
}
ecology-rocks/MakeMyForests documentation built on May 15, 2019, 7:57 p.m.