# An Open-Source R Package for Building and Using US Environmentally-Extended Input-Output Models
## 1 Introduction
### Background  
Prior to the creation of the modeling framework, we reviewed computer languages and modeling tools that would be most pertinent in creating and maintaining USEEIO models. The criteria that the languages/tools should meet included:  
* Be free and open-source;
* Use and produce human-readable, non-proprietary data formats;
* Be easily distributed, and installed and used in common computing environments (Windows, MacOS, Linux);Support high-level and efficient matrix mathematical operations;  
Be able to be maintained on GitHub or a similar git-based cloud version control platform;  
Have a simple syntax, and support structured programs (modules, sub-route);  
Have an active community;  
Optionally permit graphical user interface development. Languages and tools that were evaluated and found suitable included Python, Go, R, Julia, Scilab, Java, and Jupyter. Python was initially selected based on it being used by the research team to reassemble the openIO model (See SI2 of [1]), because of its rapidly developing libraries for data science, and its growing usage in the life cycle assessment community. An open source Python package for USEEIO assembly called the input-output model builder (iomb) was the first tool created for the USEEIO modeling framework. The _iomb_ required that users independently generate all model economic, environmental, and indicator components in standard.csv data files, with type-specific formats. The first USEEIO model [1] was assembled with the _iomb_. However, collecting various data components and preparing them in correct formats in a way that is reproducible is a challenging process. A simple Python package used to organize some of the USEEIO input data for feeding into the _iomb_, called _useeiopy_, was later developed to assist users with assembling these data to recreate USEEIO models. Nevertheless, the acquisition and transformation of core economic input data were not performed with the package. These data, along with the indicators and environmental data, were each prepared with a large set of independent Excel(r) models that were not managed in a version control system and were unique to a given USEEIO model. As a result, a lot of core data, such as industry output, lists of environmental flows, and economic data, were replicated across these various Excel(r) models, which also posed a risk of synchrony or data errors and required more labor to update. Some of the Excel(r) models of the environmental data grew large enough to consume all available RAM on a typical scientific laptop computer (8-16 GB), which made operation slow and increased the risk of program failure. The R language, which has many similarities in data science applications to Python [5], was also used in USEEIO model component development, initially to retrieve and process larger environmental datasets such as the National Emissions Inventory and USDA chemical use survey. The use of the R language in USEEIO model component preparation continued to grow as USEEIO expanded to cover new datasets, such as the addition of the waste datasets in v1.2 [6], and was used to assemble the simplified two-region USEEIO state models [7]. The early work in the USEEIO modeling framework in R culminated in a set of interdependent R scripts coupled with the _useeiopy_ and _iomb_ packages that:  
* Retrieved and processed Bureau of Economic Analysis (BEA) input-output tables and industry gross output;
* Performed flow and sector mapping using stored.csv files;
* Used a model build script, specific to a given model version, for formatting and writing all the core economic direct requirements and market shares matrices, the environmental and indicator components, and demand vectors for use by _useeiopy/iomb_ to assemble the model;
* This work was captured in v0.1 of the USEEIO modeling framework [8]. While the USEEIO modeling framework continued to evolve, a need grew for an increased variety of USEEIO models for various applications.