Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ae440b7
Per plan in #1, refactor load and download data commons functions to …
Sep 2, 2025
1a8d9a1
replace uses of loadDataCommonsfile() with loadDataFile() and pass it…
Sep 2, 2025
014d73c
Replace param for getFlowbySector to use spec to have access to file …
Sep 2, 2025
d045dee
Drop slash from end of root URL; add in new location for a Zenodo dat…
Sep 3, 2025
154fd41
Modify loadDataFile and downloadDataFile to handle file names without…
Sep 3, 2025
c7d5e63
Modify fxn to get TwoRegionIOData to allow using IOFileLocation
Sep 4, 2025
a161f43
Add IOFileLocation as optional parameter in model specification..assu…
Sep 4, 2025
f5270cb
Update docs with changes associated with #1
Sep 4, 2025
7630a44
Update package metadata with Wes new email and package update to 1.8.0
Sep 4, 2025
0981664
keep actions only for linux
bl-young Sep 4, 2025
58babf4
implement loadDataFile for satellite table loading without ScriptCall…
Sep 4, 2025
f5f1061
Merge branch '1-load-data-from-other-sources' of https://github.com/c…
Sep 4, 2025
ead6afa
Rename DataStorageConfig to RemoteStorageConfig to differentiate it f…
Sep 5, 2025
6e6ebf2
Modify data storage to use a set path for local storage for Satellite…
Sep 5, 2025
80b5acc
only assess RemoteLocation if not found locally
bl-young Sep 5, 2025
f334ef0
clean up logging, no need to report FileLocation or url unless it is …
bl-young Sep 5, 2025
987f54d
if the remote does contain a subdirectory structure, match it for loc…
bl-young Sep 5, 2025
370b282
minor legibility cleanup
bl-young Sep 5, 2025
61f2aaa
Merge pull request #2 from cornerstone-data/1-load-data-from-other-so…
WesIngwersen Sep 8, 2025
d99121e
for zenodo entries, allow more flexible use of RemoteLocationConfig, …
bl-young Sep 24, 2025
4007dad
update GO, CPI, and Value added from annual update #7
bl-young Sep 26, 2025
15c8a06
Merge pull request #6 from cornerstone-data/5-flexible-remote
WesIngwersen Sep 29, 2025
1368a7b
make sure tests in summary model use a more recent IOYear
bl-young Sep 29, 2025
616d1b5
add vscodecounter to gitignore
WesIngwersen Oct 14, 2025
d12505f
Merge pull request #8 from cornerstone-data/7-annual_data_update
WesIngwersen Oct 14, 2025
152b703
update license drop disclaimer
bl-young Oct 15, 2025
40d8997
drop deprecated sector data retrieval
bl-young Oct 22, 2025
842b88a
consolidate functions to unpack zip files; update links for IO tables…
bl-young Oct 22, 2025
0af19f3
add 2024 and update 2012-2023 data objects for Summary_Import_BeforeR…
bl-young Oct 22, 2025
bc4f793
add documentation for new tables and update urls
bl-young Oct 22, 2025
1f9219b
Remove extra space in string argument of unpackFile function call
Oct 22, 2025
4d823be
In getBEACOdeName, replace "AllTableIO" path with "MAKE-USE-IMPORTS (…
Oct 22, 2025
8a8c3c7
Edit file path for retrieving SUT tables
Oct 23, 2025
a53fd71
Merge pull request #11 from cornerstone-data/9-io-data-release
bl-young Oct 31, 2025
a953d69
update version date
WesIngwersen Nov 10, 2025
959f39d
Merge branch 'develop' of https://github.com/cornerstone-data/useeior…
WesIngwersen Nov 10, 2025
17e38d0
update org in more links to cornerstone-data
WesIngwersen Nov 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 4 additions & 4 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: R CI/CD test #R-CMD-check

on:
push:
# branches: [main, master, develop]
branches: [main, master, develop]
paths-ignore:
- '**.md' # prevent md files (e.g., README.md) in any repo dir from trigering workflow
- '**.bib'
Expand Down Expand Up @@ -37,10 +37,10 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
# - {os: macOS-latest, r: 'release'}
# - {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
# - {os: ubuntu-latest, r: 'oldrel-1'}

env:
#GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ inst/doc/**/*.html
renv/
examples
tests/*.xlsx
.VSCodeCounter/*
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Package: useeior
Type: Package
Title: USEEIO R modeling software
Version: 1.7.2
Date: 2025-7-28
Version: 1.8.0
Date: 2025-11-10
Authors@R: c(
person("Ben","Young", email="ben.young@erg.com", role="aut"),
person("Jorge","Vendries", email="jvendries@gmail.com", role="aut"),
person("Wesley","Ingwersen", email="ingwersen.wesley@epa.gov", role= c("aut", "cre")))
person("Wesley","Ingwersen", email="ingwersw@stanford.edu", role= c("aut", "cre")))
Description: The United States Environmentally-Extended Input-Output model
is a model used to estimate potential environmental and economic impacts
associated with the production and consumption of goods and services in the US.
This package constructs a USEEIO model based on defined configuration parameters,
calculates, validates, visualizes, and exports USEEIO models.
URL: https://github.com/USEPA/useeior
BugReports: https://github.com/USEPA/useeior/issues
URL: https://github.com/cornerstone-data/useeior
BugReports: https://github.com/cornerstone-data/useeior/issues
Imports:
arrow (>= 2.0.0),
configr (>= 0.3.4),
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 U.S. EPA
Copyright (c) 2025 Cornerstone Sustainability Data Initiative

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
235 changes: 135 additions & 100 deletions R/DataDocumentation.R

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion R/DisaggregateFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ disaggregateSetup <- function (model, configpaths = NULL, setupType = "Disaggreg
}

if(!is.null(spec$SourceFile)) {
fbs <- getFlowbySector(spec$SourceFile)
fbs <- getFlowbySector(spec)

# TODO: check if this if statement is necessary.
# That is, confirm that disaggregation cannot happen from SourceFile and thus this if statement would not be entered
Expand Down
12 changes: 5 additions & 7 deletions R/ExternalImportFactors.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ loadExternalImportFactors <- function(model, configpaths = NULL) {
#' @return IFtable, dataframe of unprocessed import factors
readImportFactorTable <- function(IFSpec, configpaths = NULL) {
# Read in file with Import factors
if(is.null(IFSpec$FileLocation)){
if(is.null(IFSpec$FileLocation) || IFSpec$FileLocation == "useeior"){
filename <- getInputFilePath(configpaths, folderPath = "extdata", filename = IFSpec$StaticFile)
} else if(IFSpec$FileLocation == "DataCommons") {
filename <- loadDataCommonsfile(IFSpec$StaticFile)
} else if(IFSpec$FileLocation == "useeior") {
filename <- getInputFilePath(configpaths, folderPath = "extdata", filename = IFSpec$StaticFile)
}
IFTable <- utils::read.table(filename, sep = ",", header = TRUE,
} else {
filename <- loadDataFile(IFSpec$StaticFile, IFSpec$FileLocation, "ImportFactors")
IFTable <- utils::read.table(filename, sep = ",", header = TRUE,
stringsAsFactors = FALSE)
}
return(IFTable)
}

Expand Down
8 changes: 4 additions & 4 deletions R/FlowsaFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ getFlowbySectorCollapsed <- function(sat_spec) {
}
}
} else {
f <- loadDataCommonsfile(sat_spec$StaticFile)
f <- loadDataFile(sat_spec$StaticFile, sat_spec$FileLocation, "SatelliteTable")
fbs <- as.data.frame(arrow::read_parquet(f))
# collapse the FBS sector columns into one column based on FlowType
fbs$Sector <- NA
Expand Down Expand Up @@ -77,10 +77,10 @@ prepareFlowBySectorCollapsed <- function(fbsc, satellite=TRUE) {


#' Load flowsa's FlowBySector df
#' @param filepath, a filepath to local parquet file
#' @param sat_spec, a specification file
#' @return A data frame for flowsa data in sector by region totals format
getFlowbySector <- function(filepath) {
f <- loadDataCommonsfile(filepath)
getFlowbySector <- function(sat_spec) {
f <- loadDataFile(sat_spec$StaticFile, sat_spec$FileLocation, "SatelliteTable")
fbs <- as.data.frame(arrow::read_parquet(f))
fbs <- prepareFlowBySectorCollapsed(fbs, satellite=FALSE)
return(fbs)
Expand Down
2 changes: 1 addition & 1 deletion R/LCIAfmtFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ getImpactMethod <- function(ind_spec) {
imp_method <- lciafmt$get_mapped_method(method_id = parameters$method_id,
indicators = indicators, methods = methods)
} else {
f <- loadDataCommonsfile(ind_spec$StaticFile)
f <- loadDataFile(ind_spec$StaticFile, ind_spec$FileLocation, "Indicators")
imp_method <- as.data.frame(arrow::read_parquet(f))
}

Expand Down
2 changes: 1 addition & 1 deletion R/LoadIndicators.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ loadIndicators <- function(model) {
meta <- data.frame()
factors <- data.frame()
for (s in model$specs$Indicators) {
logging::loginfo(paste0("Getting ", s$Name, " indicator from ", s$FileLocation, "..."))
logging::loginfo(paste0("Loading ", s$Name, " indicator..."))

# Populate metadata
meta_fields <- c("Name","Code","Group","Unit","SimpleUnit","SimpleName")
Expand Down
9 changes: 3 additions & 6 deletions R/LoadSatellites.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ loadSatTables <- function(model) {
if(sat_spec$FileLocation == 'None'){
logging::loginfo(paste0("Generating ", sat_spec$FullName, " flows..."))
} else {
logging::loginfo(paste0("Loading ", sat_spec$FullName, " flows from ", sat_spec$FileLocation, "..."))
logging::loginfo(paste0("Loading ", sat_spec$FullName, " flows..."))
}
if(sat_spec$SectorListSource == "NAICS" && sat_spec$SectorListYear != model$specs$BaseIOSchema) {
logging::logwarn(paste0("SectorListYear of ", sat_spec$FullName," does not match the BaseIOSchema ",
Expand Down Expand Up @@ -117,12 +117,9 @@ generateTbSfromSatSpec <- function(sat_spec, model) {
}
}
totals_by_sector <- do.call(eval(totalsgenfunction), list(params))
} else if (sat_spec$FileLocation == "DataCommons") {
f <- loadDataCommonsfile(sat_spec$StaticFile)
totals_by_sector <- utils::read.table(f, sep = ",", header = TRUE, stringsAsFactors = FALSE,
fileEncoding = 'UTF-8-BOM')
} else {
totals_by_sector <- utils::read.table(sat_spec$StaticFile, sep = ",",
f <- loadDataFile(sat_spec$StaticFile, sat_spec$FileLocation, "SatelliteTable")
totals_by_sector <- utils::read.table(f, sep = ",",
header = TRUE, stringsAsFactors = FALSE,
fileEncoding = 'UTF-8-BOM')
}
Expand Down
14 changes: 11 additions & 3 deletions R/StateiorFunctions.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Functions for handling data from stateior, https://github.com/USEPA/stateior

#' Load two-region IO data of model iolevel and year from user's local directory
#' or the EPA Data Commons.
#' or a specified file location.
#' @description Load two-region IO data of model iolevel and year from user's
#' local directory or the EPA Data Commons.
#' local directory or specified file location.
#' @param model An EEIO form USEEIO model object with model specs and IO meta data loaded.
#' @param dataname Name of desired IO data, can be "Make", "Use", "DomesticUse",
#' "UseTransactions", "FinalDemand", "InternationalTradeAdjustment,
Expand Down Expand Up @@ -35,7 +35,15 @@ getTwoRegionIOData <- function(model, dataname) {
}
# Load data
logging::loginfo(paste0("Loading ", filename))
TwoRegionIOData <- readRDS(loadDataCommonsfile(paste0("stateio/", filename, ".rds")))
filename <- paste0(filename, ".rds")
if (!is.null(model$specs$IOFileLocation)) {
f <- loadDataFile(filename, model$specs$IOFileLocation, "stateior")
} else {
#handle case where Data Commons files have subdirectory
f <- loadDataFile(paste0("stateio/",filename), "DataCommons", "stateior")
}

TwoRegionIOData <- readRDS(f)
# Keep SoI and RoUS only
TwoRegionIOData <- TwoRegionIOData[[state]]
if(dataname %in% c("UseTransactions", "DomesticUseTransactions")) {
Expand Down
87 changes: 67 additions & 20 deletions R/UtilityFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,51 +150,98 @@ writeMatrixasBinFile <- function(matrix, path) {
close(out)
}

#' downloads files from the Data Commons and stores in a local temporary data directory
#' Downloads files from a given source and stores in a local data directory
#' @param source The name of the source file (e.g. "TRACI_2.1_v1.parquet")
#' @param subdirectory The name of the package where the source file is stored on
#' Data Commons including any subfolders (e.g. "lciafmt/traci_2_1")
#' @param debug_url The Data Commons base url, including directory and subdirectories
downloadDataCommonsfile <- function(source, subdirectory, debug_url) {
#' @param subdirectory The name of the subdirectory where the source file is stored on
#' remote location including any subfolders (e.g. "lciafmt/traci_2_1"). May be empty.
#' @param url The url of the data storage location
#' @param query_string A string for URLs where query string is present after file name.
#' e.g. "?download=1". May be empty.
#' @param localpath A string value looked up from LocalStorageConfig with a path for local storage
#' like "flowsa/FlowBySector"
#' @return NULL if successful
downloadDataFile <- function(source, subdirectory, url, query_string, localpath) {
# Define file directory
directory <- paste0(rappdirs::user_data_dir(), "/", subdirectory)
directory <- paste0(rappdirs::user_data_dir(), "/", localpath)
# Check for and create subdirectory if necessary
if(!file.exists(directory)){
dir.create(directory, recursive = TRUE)
}

# Download file
utils::download.file(paste0(debug_url, "/", source),
paste0(directory, "/", source),
utils::download.file(paste0(file.path(url, source), query_string),
file.path(directory, source),
mode = "wb", quiet = TRUE)
}

#' Load the static file originating from Data Commons either by loading from local directory
#' or downloading from Data Commons and
#' saving to local directory
#' Load the file originating from a remote location
#' @param static_file The name of a static file, including the subdirectories
#' @return The static file originating from Data Commons
loadDataCommonsfile <- function(static_file) {
#' @param location The name of the data store location, which is used to look up the URL in RemoteLocationConfig.yml
#' @param type A string that matches a key value in LocalStorageConfig.yml
#' @return The static file loaded from the location or local cache
loadDataFile <- function(static_file, location, type) {
# load method name
method_name <- static_file
# define symbol to split method name
pat <- "(.*)/(.*)"
# subdirectory is the string of the method name prior to the last "/"
subdirectory <- sub(pat, "\\1", method_name)

if (grepl(pat,method_name)) {
remotesubdirectory <- sub(pat, "\\1", method_name)
} else {
remotesubdirectory <- ""
}

# file name is the string of the method name after the last "/"
file_name <- sub(pat, "\\2", method_name)

# url for data commons
debug_url <- paste0("https://dmap-data-commons-ord.s3.amazonaws.com/", subdirectory)

directory <- paste0(rappdirs::user_data_dir(), "/", subdirectory)
#If file name has a query string strip it off
query_string <- ""
if(grepl("\\?",file_name)) {
name_parts <- strsplit(method_name,"\\?")
file_name <- name_parts[[1]][1]
query_string <- paste0("?",name_parts[[1]][2])
}

#Load location config
configpath <- system.file("extdata/RemoteLocationConfig.yml", package = "useeior")
remoteconfig <- configr::read.config(configpath)
#Load local storage config
configpath <- system.file("extdata/LocalStorageConfig.yml", package = "useeior")
localconfig <- configr::read.config(configpath)

#Use local storage info for local storage path
#Local cache
localpath <- ""
if(remotesubdirectory != "") {
localpath <- remotesubdirectory
} else if(!is.null(localconfig[[type]])) {
localpath <- localconfig[[type]]
}
directory <- file.path(rappdirs::user_data_dir(), localpath)

# file must be saved in the local directory
f <- paste0(directory,'/', file_name)

if(!file.exists(f)){
logging::loginfo(paste0("file not found, downloading from ", debug_url))
downloadDataCommonsfile(file_name, subdirectory, debug_url)
if (grepl("Zenodo", location)) {
# Extract the entry ID from the model spec for use in url
id <- sub("Zenodo", "", location)
location <- "Zenodo"
} else {
id <- ""
}
if (is.null(remoteconfig[[location]])) {
logging::logerror(paste("The location", location," does not have a URL associated with it. ",
"Ensure it is listed in RemoteLocationConfig.yml"))
return(NULL)
} else {
url <- file.path(sub("__ID__", id, remoteconfig[[location]]),
remotesubdirectory)
}
logging::loginfo(paste0("file not found, downloading from ", url))
downloadDataFile(file_name, remotesubdirectory, url, query_string=query_string,
localpath=localpath)
}
return(f)
}
Expand Down
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# useeior <img src="inst/img/logo.png" align="right" width="240" />
<!-- badges: start -->
[![R CI/CD test](https://github.com/USEPA/useeior/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/USEPA/useeior/actions/workflows/R-CMD-check.yaml)
[![R CI/CD test](https://github.com/cornerstone-data/useeior/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/cornerstone-data/useeior/actions/workflows/R-CMD-check.yaml)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![useeior DOI](http://img.shields.io/badge/useeior%20DOI-10.5281/zenodo.7020213-blue.svg)](https://doi.org/10.5281/zenodo.7020213)
[![useeior paper](http://img.shields.io/badge/useeior%20paper-10.3390/app12094469-blue.svg)](https://doi.org/10.3390/app12094469)
Expand All @@ -12,8 +12,8 @@ The [model object](format_specs/Model.md) is the primary output that is built ac
[Model specifications](inst/extdata/modelspecs) and associated hybridization specifications, e.g. [disaggregation](inst/extdata/disaggspecs), for EPA-validated models are included in the package.

`useeior` offers various functions for validating, calculating, visualizing, and writing out models and/or their components.
`useeior` is a core component of the [USEEIO Modeling Framework](https://github.com/USEPA/useeio) and is in a stable development state.
Users intending to use the package for production purposes and applications should use [Releases](https://github.com/USEPA/useeior/releases).
`useeior` is a core component of the [USEEIO Modeling Framework](https://github.com/cornerstone-data/useeio) and is in a stable development state.
Users intending to use the package for production purposes and applications should use [Releases](https://github.com/cornerstone-data/useeior/releases).
`useeior` v1.0.0 was peer-reviewed internally at USEPA and published at Zenodo.

An peer-reviewed article describing `useeior` was published in the journal Applied Sciences in April 2022.
Expand All @@ -37,22 +37,22 @@ Li, M., Ingwersen, W.W., Young, B., Vendries, J. and Birney, C., 2022. useeior:

See the following sections for installation and basic usage of `useeior`.

See [Wiki](https://github.com/USEPA/useeior/wiki) for advanced uses, details about built-in data and metadata and how to contribute to `useeior`.
<!-- See [Wiki](https://github.com/USEPA/useeior/wiki) for advanced uses, details about built-in data and metadata and how to contribute to `useeior`. -->

## Installation

```r
# Install development version from GitHub
install.packages("devtools")
devtools::install_github("USEPA/useeior")
devtools::install_github("cornerstone-data/useeior")
```

```r
# Install a previously released version (e.g. v1.0.0) from GitHub
devtools::install_github("USEPA/useeior@v1.0.0")
devtools::install_github("cornerstone-data/useeior@v1.7.0")
```

See [Releases](https://github.com/USEPA/useeior/releases) for all previously released versions.
See [Releases](https://github.com/cornerstone-data/useeior/releases) for all previously released versions.

## Usage

Expand Down Expand Up @@ -225,7 +225,3 @@ Currently, it only compares flow totals between two models. More comparisons wil
### Additional Information

A complete list of available functions for calculating, validating, exporting and visualizing model can be found [here](https://github.com/USEPA/useeior/wiki/Using-useeior#calculate-validate-export-visualize-model) in the Wiki.

## Disclaimer

The United States Environmental Protection Agency (EPA) GitHub project code is provided on an "as is" basis and the user assumes responsibility for its use. EPA has relinquished control of the information and no longer has responsibility to protect the integrity , confidentiality, or availability of the information. Any reference to specific commercial products, processes, or services by service mark, trademark, manufacturer, or otherwise, does not constitute or imply their endorsement, recommendation or favoring by EPA. The EPA seal and logo shall not be used in any manner to imply endorsement of any commercial product or activity by EPA or the United States Government.
Loading