ejscreen.download: Download the EJSCREEN Dataset csv for use in R and rename...

View source: R/ejscreen.download.R

ejscreen.downloadR Documentation

Download the EJSCREEN Dataset csv for use in R and rename variables

Description

Download EJSCREEN dataset from FTP site, unzip if necessary, import to R as data.table, renaming fields with friendly colnames, optionally adding a flag field (see parameter called addflag). Note that since 2020v, State percentiles are also available in a separate zipped csv.

Usage

ejscreen.download(
  folder = getwd(),
  yr = NULL,
  ftpurlbase = "https://gaftp.epa.gov/EJSCREEN/",
  justreadname = NULL,
  statepctiles = FALSE,
  addflag = FALSE,
  threshold = 80,
  or.tied = TRUE
)

Arguments

folder

Optional path to folder (directory) where the file will be downloaded and unzipped. Default is current working directory.

yr

Default is latest available year found as a folder on the FTP site. Optional numeric year designating EJSCREEN version such as 2015, 2016, 2017, 2018, 2019, 2020, etc.

ftpurlbase

Optional. where to find the zipped data.

justreadname

Optional character file name - if specified, skips downloading and just tries to read previously-downloaded csv found in folder.

statepctiles

Optional, default FALSE. If TRUE, gets State Percentiles csv instead of the USPR file.

addflag

Optional. Default is FALSE. If TRUE, it adds a field called flagged, which is TRUE if 1 or more of the EJ Indexes is at/above the threshold US percentile.

threshold

Optional. Default is 80. See addflag parameter.

or.tied

Optional. Default is TRUE, meaning at or above the threshold FALSE means above only. See addflag parameter.

Details

Not fully tested.

  Each version of EJSCREEN uses updated environmental data and updated 5-year 
  summary file estimates from the American Community Survey (ACS).

  The 2017-2021 American Community Survey 5-year estimates are scheduled to 
  be released on Thursday, December 8, 2022.
  The 2016-2020 ACS 5-year estimates were released Dec 2021.

  EJScreen 2.0 (released February 2022),
    actually uses ACS2019 5-year summary file data, which is from 2015-2019
     (released Dec 2020).
    It is avail as data in \link{bg21}
  (EJScreen 2.0 would have been called the 2021 version in old naming scheme).

 Note the 2020 version of EJSCREEN 
 (confusingly released early/mid 2021 not late 2020)
    actually used ACS2018, which is from 2014-2018 (released late 2019).
    It had been called bg20

       TO JUST READ THE EJSCREEN DATA ONCE DOWNLOADED FROM THE FTP SITE:

      May recode ejscreen.download to split out just the part that 
       downloads, unzips, reads into R verbatim.

 x <- readr::read_csv('~/Downloads/EJSCREEN_2020_USPR.csv', na = 'None')
 x <- data.frame(x, stringsAsFactors=FALSE) #if want data.frame not data.table

       TO JUST RENAME COLUMNS TO FRIENDLY NAMES USED IN THIS PACKAGE:

       names(x) <- ejscreen::change.fieldnames.ejscreen.csv(names(x))

       TO JUST ADD SOME USEFUL COLUMNS (FIPS, countyname, statename, etc.):

       x <- ejanalysis::addFIPScomponents(x)
       # and could add attribute to indicate vintage
  

Value

Returns a data.frame with ejscreen dataset of environmental and demographics indicators, and EJ Indexes, as raw values, US percentiles, text for popups. Output has one row per block group, sorted by FIPS.

Source

See http://www.epa.gov/ejscreen for more information, and see http://www.epa.gov/ejscreen/download-ejscreen-data

See Also

ejscreen.create change.fieldnames.ejscreen.csv

Examples

   # bg <- ejscreen.download('~')
   ## bg <- ejscreen.download('~',
   #  justreadname = 'EJSCREEN_Full_USPR_2020.csv')
   # bg <- bg[ , !grepl(pattern = 'pctile\.text', x = names(bg))]
   # bg <- bg[ , !grepl(pattern = 'svi6', x = names(bg))]
   # setwd('~')
   # save(bg, file = 'bgYEAR20XX.rdata')

ejanalysis/ejscreen documentation built on April 2, 2024, 10:15 a.m.