Setup

Load Packages

library( irs990efile )  # functions for parsing efile XMLs
library( dplyr )        # data wrangling
library( purrr )        # data wrangling 
library( pander )       # formatting
library( knitr )        # formatting
library( DT )           # table printing
library( httr )         # web requests 
library( xmltools )     # xml utilities
library( xml2 )         # xml utilities
library( XML )          # xml utilities 
library( data.tree )    # network visualization
library( networkD3 )    # network visualization
library( igraph )       # network visualization

source( "R/rdb-functions-v2.R")
source( "R/utils.R")

Data

head( index )

The Concordance File

The concordance is an RDB to XML Crosswalk that maps all xpaths onto a specified set of variables. It is located in the irs990efile package.


The full data dictionary is available on GitHub.

DATA DICTIONARY


concordance %>% 
  filter( rdb_table == table.name )  








xpath id
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressForeign/AddressLine1 1
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressForeign/AddressLine2 2
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressForeign/City 3
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressForeign/Country 4
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressForeign/PostalCode 5
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressForeign/ProvinceOrState 6
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressUS/AddressLine1 7
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressUS/AddressLine2 8
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressUS/City 9
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressUS/State 10
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressUS/ZIPCode 11
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/DirectControllingEntity/NameBusiness/BusinessNameLine1 12
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/DirectControllingEntity/NameBusiness/BusinessNameLine2 13
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/DirectControllingEntity/NotApplicable 14
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/DirectControllingEntityNA 15
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/DirectControllingEntityName/BusinessNameLine1 16
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/DirectControllingEntityName/BusinessNameLine2 17
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/EIN 18
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/EOYAssets 19
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/LegalDomicile/ForeignCountry 20
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/LegalDomicile/State 21
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/LegalDomicileForeignCountry 22
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/LegalDomicileState 23
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/NameOfDisregardedEntity/BusinessNameLine1 24
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/NameOfDisregardedEntity/BusinessNameLine2 25
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/PrimaryActivities 26
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/TotalIncome 27
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DirectControllingEntityName/BusinessNameLine1 28
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DirectControllingEntityName/BusinessNameLine1Txt 29
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DirectControllingEntityName/BusinessNameLine2 30
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DirectControllingEntityName/BusinessNameLine2Txt 31
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DirectControllingNACd 32
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DisregardedEntityName/BusinessNameLine1 33
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DisregardedEntityName/BusinessNameLine1Txt 34
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DisregardedEntityName/BusinessNameLine2 35
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DisregardedEntityName/BusinessNameLine2Txt 36
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/EIN 37
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/EndOfYearAssetsAmt 38
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/AddressLine1 39
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/AddressLine1Txt 40
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/AddressLine2 41
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/AddressLine2Txt 42
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/City 43
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/CityNm 44
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/Country 45
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/CountryCd 46
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/ForeignPostalCd 47
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/PostalCode 48
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/ProvinceOrState 49
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/ProvinceOrStateNm 50
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/LegalDomicileForeignCountryCd 51
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/LegalDomicileStateCd 52
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/PrimaryActivitiesTxt 53
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/TotalIncomeAmt 54
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/AddressLine1 55
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/AddressLine1Txt 56
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/AddressLine2 57
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/AddressLine2Txt 58
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/City 59
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/CityNm 60
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/State 61
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/StateAbbreviationCd 62
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/ZIPCd 63
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/ZIPCode 64
xpaths <- as.character( t.xpaths$xpath )
el <- create_edgelist_v1( xpaths )
nd <- FromDataFrameNetwork( network=el )
print( nd )
##                                        levelName
## 1  Return                                       
## 2   °--ReturnData                               
## 3       °--IRS990ScheduleR                      
## 4           ¦--Form990ScheduleRPartI            
## 5           ¦   ¦--AddressForeign               
## 6           ¦   ¦   ¦--AddressLine1             
## 7           ¦   ¦   ¦--AddressLine2             
## 8           ¦   ¦   ¦--City                     
## 9           ¦   ¦   ¦--Country                  
## 10          ¦   ¦   ¦--PostalCode               
## 11          ¦   ¦   °--ProvinceOrState          
## 12          ¦   ¦--AddressUS                    
## 13          ¦   ¦   ¦--AddressLine1             
## 14          ¦   ¦   ¦--AddressLine2             
## 15          ¦   ¦   ¦--City                     
## 16          ¦   ¦   ¦--State                    
## 17          ¦   ¦   °--ZIPCode                  
## 18          ¦   ¦--DirectControllingEntity      
## 19          ¦   ¦   ¦--NameBusiness             
## 20          ¦   ¦   ¦   ¦--BusinessNameLine1    
## 21          ¦   ¦   ¦   °--BusinessNameLine2    
## 22          ¦   ¦   °--NotApplicable            
## 23          ¦   ¦--DirectControllingEntityNA    
## 24          ¦   ¦--DirectControllingEntityName  
## 25          ¦   ¦   ¦--BusinessNameLine1        
## 26          ¦   ¦   ¦--BusinessNameLine2        
## 27          ¦   ¦   ¦--BusinessNameLine1Txt     
## 28          ¦   ¦   °--BusinessNameLine2Txt     
## 29          ¦   ¦--EIN                          
## 30          ¦   ¦--EOYAssets                    
## 31          ¦   ¦--LegalDomicile                
## 32          ¦   ¦   ¦--ForeignCountry           
## 33          ¦   ¦   °--State                    
## 34          ¦   ¦--LegalDomicileForeignCountry  
## 35          ¦   ¦--LegalDomicileState           
## 36          ¦   ¦--NameOfDisregardedEntity      
## 37          ¦   ¦   ¦--BusinessNameLine1        
## 38          ¦   ¦   °--BusinessNameLine2        
## 39          ¦   ¦--PrimaryActivities            
## 40          ¦   °--TotalIncome                  
## 41          °--IdDisregardedEntitiesGrp         
## 42              ¦--DirectControllingEntityName  
## 43              ¦   ¦--BusinessNameLine1        
## 44              ¦   ¦--BusinessNameLine2        
## 45              ¦   ¦--BusinessNameLine1Txt     
## 46              ¦   °--BusinessNameLine2Txt     
## 47              ¦--DirectControllingNACd        
## 48              ¦--DisregardedEntityName        
## 49              ¦   ¦--BusinessNameLine1        
## 50              ¦   ¦--BusinessNameLine1Txt     
## 51              ¦   ¦--BusinessNameLine2        
## 52              ¦   °--BusinessNameLine2Txt     
## 53              ¦--EIN                          
## 54              ¦--EndOfYearAssetsAmt           
## 55              ¦--ForeignAddress               
## 56              ¦   ¦--AddressLine1             
## 57              ¦   ¦--AddressLine1Txt          
## 58              ¦   ¦--AddressLine2             
## 59              ¦   ¦--AddressLine2Txt          
## 60              ¦   ¦--City                     
## 61              ¦   ¦--CityNm                   
## 62              ¦   ¦--Country                  
## 63              ¦   ¦--CountryCd                
## 64              ¦   ¦--ForeignPostalCd          
## 65              ¦   ¦--PostalCode               
## 66              ¦   ¦--ProvinceOrState          
## 67              ¦   °--ProvinceOrStateNm        
## 68              ¦--LegalDomicileForeignCountryCd
## 69              ¦--LegalDomicileStateCd         
## 70              ¦--PrimaryActivitiesTxt         
## 71              ¦--TotalIncomeAmt               
## 72              °--USAddress                    
## 73                  ¦--AddressLine1             
## 74                  ¦--AddressLine1Txt          
## 75                  ¦--AddressLine2             
## 76                  ¦--AddressLine2Txt          
## 77                  ¦--City                     
## 78                  ¦--CityNm                   
## 79                  ¦--State                    
## 80                  ¦--StateAbbreviationCd      
## 81                  ¦--ZIPCd                    
## 82                  °--ZIPCode
SetGraphStyle( nd, rankdir = "LR")
SetEdgeStyle( nd, arrowhead = "vee", color = "grey20", penwidth = 2 )
SetNodeStyle( nd, 
              style = "filled,rounded", 
              shape = "box", 
              fillcolor = "LightBlue", 
              fontname = "helvetica", 
              fontcolor="black",
              tooltip = GetDefaultTooltip )

# SetNodeStyle(acme$IT, fillcolor = "LightBlue", penwidth = "5px")
plot( nd )
# old version
find_group_names( table.name )
## [1] "//Form990ScheduleRPartI"    "//IdDisregardedEntitiesGrp"
# new version
find_table_headers( table.name )
##  [1] "//Form990ScheduleRPartI/AddressForeign"                  
##  [2] "//Form990ScheduleRPartI/AddressUS"                       
##  [3] "//Form990ScheduleRPartI/EIN"                             
##  [4] "//Form990ScheduleRPartI/NameOfDisregardedEntity"         
##  [5] "//Form990ScheduleRPartI/PrimaryActivities"               
##  [6] "//Form990ScheduleRPartI/LegalDomicile"                   
##  [7] "//Form990ScheduleRPartI/LegalDomicileForeignCountry"     
##  [8] "//Form990ScheduleRPartI/LegalDomicileState"              
##  [9] "//Form990ScheduleRPartI/TotalIncome"                     
## [10] "//Form990ScheduleRPartI/EOYAssets"                       
## [11] "//Form990ScheduleRPartI/DirectControllingEntityNA"       
## [12] "//Form990ScheduleRPartI/DirectControllingEntity"         
## [13] "//Form990ScheduleRPartI/DirectControllingEntityName"     
## [14] "//IdDisregardedEntitiesGrp/ForeignAddress"               
## [15] "//IdDisregardedEntitiesGrp/USAddress"                    
## [16] "//IdDisregardedEntitiesGrp/EIN"                          
## [17] "//IdDisregardedEntitiesGrp/DisregardedEntityName"        
## [18] "//IdDisregardedEntitiesGrp/PrimaryActivitiesTxt"         
## [19] "//IdDisregardedEntitiesGrp/LegalDomicileForeignCountryCd"
## [20] "//IdDisregardedEntitiesGrp/LegalDomicileStateCd"         
## [21] "//IdDisregardedEntitiesGrp/TotalIncomeAmt"               
## [22] "//IdDisregardedEntitiesGrp/EndOfYearAssetsAmt"           
## [23] "//IdDisregardedEntitiesGrp/DirectControllingNACd"        
## [24] "//IdDisregardedEntitiesGrp/DirectControllingEntityName"
# manual
if( ! is.null(table.headers) )
{table.headers}








Build the Table

# create new folder
dir.create( folder.name )
setwd( folder.name )

# create sample
set.seed( 1234 )
sample.index <- sample_n( index, sample.size )
write.csv( index, "sample-index.csv", row.names=F )
sample.urls <- sample.index$URL

# erase existing log files
file.create("XPATH-LOG.txt") 
file.create("FAIL-LOG.txt")


start.build.time <- Sys.time()    # --------------------

results.list <- list()
xpath.list <- list()


for( i in 1:length( sample.urls ) )
{
  
  url <- sample.urls[i]
  
  results.list[[i]] <- 
    build_rdb_table_v2( url, 
                        table.name, 
                        table.headers=table.headers )
  
  xpath.list[[i]]   <- 
    get_table_xpaths( url, 
                      table.name, 
                      table.headers=table.headers )
  
  if( i %% 100 == 0 ){ print(i) }
  
}


end.build.time <- Sys.time()      # --------------------


df <- dplyr::bind_rows( results.list )


fail.log <- readLines( "FAIL-LOG.txt" )
all.xpaths <- xpath.list %>% unlist() %>% unique() %>% sort()
cat( all.xpaths, sep="\n", file="XPATH-LOG.txt" )

TABLE: SR-P01-T01-ID-DISREGARDED-ENTITIES

## [1] "NUMBER OF RETURNS PROCESSED:   1000"
## [1] "TOTAL NUMBER OF TABLE ROWS:   807"

TOTAL RUN TIME:

## Time difference of 24.27167 mins
## Time difference of -0.4045278 hours

Write to File

write.csv( df, paste0( folder.name, "/", table.name, ".csv" ), row.names=F )
head(df) 

Are all names standardized?

names(df)
##  [1] "OBJECT_ID"                       "EIN"                            
##  [3] "NAME"                            "TAXYR"                          
##  [5] "FORMTYPE"                        "URL"                            
##  [7] "SR_01_DISREG_ENTITY_EIN"         "SR_01_DISREG_ENTITY_PRIMARY_ACT"
##  [9] "SR_01_DISREG_ENTITY_DMCL_STATE"  "SR_01_DISREG_ENTITY_INCOME_TOT" 
## [11] "SR_01_DISREG_ENTITY_ASSETS_EOY"  "SR_01_DISREG_ENTITY_NAME_L1"    
## [13] "SR_01_DISREG_ENTITY_ADDR_L1"     "SR_01_DISREG_ENTITY_ADDR_CITY"  
## [15] "SR_01_DISREG_ENTITY_ADDR_STATE"  "SR_01_DISREG_ENTITY_ADDR_ZIP"   
## [17] "SR_01_DISREG_ENTITY_NAME_L1.1"   "SR_01_DISREG_ENTITY_CTRL_NA"    
## [19] "SR_01_DISREG_ENTITY_DMCL_CNTR"   "SR_01_DISREG_ENTITY_ADDR_L2"    
## [21] "SR_01_DISREG_ENTITY_ADDR_CNTR"   "SR_01_DISREG_ENTITY_NAME_L2"








Diagnostics

Missing or Extra XPATHS

Check for xpaths that were used in the tables but do not exist in the Concordance file.

c.table <- dplyr::filter( concordance, rdb_table == table.name ) 
xpath.concordance <- c.table$xpath
setdiff( all.xpaths, xpath.concordance )
## [1] ""                                                                                       
## [2] "/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DirectControllingEntityName"
## [3] "/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DisregardedEntityName"      
## [4] "/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress"             
## [5] "/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress"

Capture to update the Concordance file.

these <- setdiff( all.xpaths, xpath.concordance )
cat( these, sep="\n", file=paste0( folder.name, "/MISSING-XPATHS.txt" ) )

Failes URLs

Check the status of failed URLs.

if( length(fail.log) > 0 )
{ 
  sapply( fail.log, get_message ) %>% 
  table() %>% 
  pander() 
} else {
  print("ALL URLs ARE VALID")
}
## [1] "ALL URLs ARE VALID"








XML Table Structure

Create Network Edgelists

The create_edgelist() functions v1 and v2 are in R/utils.R.

V1 retains the root nodes Return and ReturnData.

V2 drops the root nodes and uses form versions “990” and “990EZ” as the root to visualize the sets of tables separately.

# KEEP ROOT NOTES Return & ReturnData
el <- create_edgelist_v1( all.xpaths )



Edgelist format:

V1 V2
Return ReturnData
ReturnData IRS990
IRS990 Form990PartVIISectionAGrp
Form990PartVIISectionAGrp PersonNm
Form990PartVIISectionAGrp TitleTxt
Form990PartVIISectionAGrp AverageHoursPerWeekRt
Form990PartVIISectionAGrp IndividualTrusteeOrDirectorInd
Form990PartVIISectionAGrp OfficerInd
Form990PartVIISectionAGrp ReportableCompFromOrgAmt
Form990PartVIISectionAGrp ReportableCompFromRltdOrgAmt








Visualize Tree Structure

# library( data.tree )
nd <- FromDataFrameNetwork( network=el )
print( nd )
##                                        levelName
## 1  Return                                       
## 2   °--ReturnData                               
## 3       °--IRS990ScheduleR                      
## 4           °--IdDisregardedEntitiesGrp         
## 5               ¦--DirectControllingEntityName  
## 6               ¦   ¦--BusinessNameLine1Txt     
## 7               ¦   °--BusinessNameLine2Txt     
## 8               ¦--DirectControllingNACd        
## 9               ¦--DisregardedEntityName        
## 10              ¦   ¦--BusinessNameLine1Txt     
## 11              ¦   °--BusinessNameLine2Txt     
## 12              ¦--EIN                          
## 13              ¦--EndOfYearAssetsAmt           
## 14              ¦--ForeignAddress               
## 15              ¦   ¦--AddressLine1Txt          
## 16              ¦   ¦--AddressLine2Txt          
## 17              ¦   ¦--CityNm                   
## 18              ¦   ¦--CountryCd                
## 19              ¦   ¦--ForeignPostalCd          
## 20              ¦   °--ProvinceOrStateNm        
## 21              ¦--LegalDomicileForeignCountryCd
## 22              ¦--LegalDomicileStateCd         
## 23              ¦--PrimaryActivitiesTxt         
## 24              ¦--TotalIncomeAmt               
## 25              °--USAddress                    
## 26                  ¦--AddressLine1Txt          
## 27                  ¦--AddressLine2Txt          
## 28                  ¦--CityNm                   
## 29                  ¦--StateAbbreviationCd      
## 30                  °--ZIPCd
SetGraphStyle( nd, rankdir = "LR")
SetEdgeStyle( nd, arrowhead = "vee", color = "grey20", penwidth = 2 )
SetNodeStyle( nd, 
              style = "filled,rounded", 
              shape = "box", 
              fillcolor = "LightBlue", 
              fontname = "helvetica", 
              fontcolor="black",
              tooltip = GetDefaultTooltip )

# SetNodeStyle(acme$IT, fillcolor = "LightBlue", penwidth = "5px")
plot( nd )
# library( networkD3 )
# net <- ToDataFrameNetwork( nd, "name" )
# simpleNetwork( net, fontSize = 12 )
simpleNetwork( el, fontSize = 12 )
#plot with networkD3
radnet <- ToListExplicit( nd, unname = TRUE )
radialNetwork( radnet, fontSize = 12 )








XPATH Summary

Unique Xpaths for this RDB Table

t.xpaths <- 
  concordance %>%
  filter( rdb_table == table.name ) %>% 
  select( xpath ) %>% 
  unique() %>% 
  arrange( xpath ) %>% 
  mutate( id=row_number() ) 

t.xpaths %>% 
  kable( align="l" )
xpath id
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressForeign/AddressLine1 1
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressForeign/AddressLine2 2
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressForeign/City 3
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressForeign/Country 4
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressForeign/PostalCode 5
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressForeign/ProvinceOrState 6
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressUS/AddressLine1 7
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressUS/AddressLine2 8
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressUS/City 9
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressUS/State 10
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/AddressUS/ZIPCode 11
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/DirectControllingEntity/NameBusiness/BusinessNameLine1 12
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/DirectControllingEntity/NameBusiness/BusinessNameLine2 13
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/DirectControllingEntity/NotApplicable 14
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/DirectControllingEntityNA 15
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/DirectControllingEntityName/BusinessNameLine1 16
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/DirectControllingEntityName/BusinessNameLine2 17
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/EIN 18
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/EOYAssets 19
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/LegalDomicile/ForeignCountry 20
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/LegalDomicile/State 21
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/LegalDomicileForeignCountry 22
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/LegalDomicileState 23
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/NameOfDisregardedEntity/BusinessNameLine1 24
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/NameOfDisregardedEntity/BusinessNameLine2 25
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/PrimaryActivities 26
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartI/TotalIncome 27
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DirectControllingEntityName/BusinessNameLine1 28
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DirectControllingEntityName/BusinessNameLine1Txt 29
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DirectControllingEntityName/BusinessNameLine2 30
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DirectControllingEntityName/BusinessNameLine2Txt 31
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DirectControllingNACd 32
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DisregardedEntityName/BusinessNameLine1 33
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DisregardedEntityName/BusinessNameLine1Txt 34
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DisregardedEntityName/BusinessNameLine2 35
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/DisregardedEntityName/BusinessNameLine2Txt 36
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/EIN 37
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/EndOfYearAssetsAmt 38
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/AddressLine1 39
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/AddressLine1Txt 40
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/AddressLine2 41
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/AddressLine2Txt 42
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/City 43
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/CityNm 44
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/Country 45
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/CountryCd 46
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/ForeignPostalCd 47
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/PostalCode 48
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/ProvinceOrState 49
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/ForeignAddress/ProvinceOrStateNm 50
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/LegalDomicileForeignCountryCd 51
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/LegalDomicileStateCd 52
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/PrimaryActivitiesTxt 53
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/TotalIncomeAmt 54
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/AddressLine1 55
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/AddressLine1Txt 56
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/AddressLine2 57
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/AddressLine2Txt 58
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/City 59
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/CityNm 60
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/State 61
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/StateAbbreviationCd 62
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/ZIPCd 63
/Return/ReturnData/IRS990ScheduleR/IdDisregardedEntitiesGrp/USAddress/ZIPCode 64

Grouping Variables

Identify all unique groups used in xpaths.

if( is.null(table.headers) )
{ find_table_headers( table.name ) } else
table.headers
##  [1] "//Form990ScheduleRPartI/AddressForeign"                  
##  [2] "//Form990ScheduleRPartI/AddressUS"                       
##  [3] "//Form990ScheduleRPartI/EIN"                             
##  [4] "//Form990ScheduleRPartI/NameOfDisregardedEntity"         
##  [5] "//Form990ScheduleRPartI/PrimaryActivities"               
##  [6] "//Form990ScheduleRPartI/LegalDomicile"                   
##  [7] "//Form990ScheduleRPartI/LegalDomicileForeignCountry"     
##  [8] "//Form990ScheduleRPartI/LegalDomicileState"              
##  [9] "//Form990ScheduleRPartI/TotalIncome"                     
## [10] "//Form990ScheduleRPartI/EOYAssets"                       
## [11] "//Form990ScheduleRPartI/DirectControllingEntityNA"       
## [12] "//Form990ScheduleRPartI/DirectControllingEntity"         
## [13] "//Form990ScheduleRPartI/DirectControllingEntityName"     
## [14] "//IdDisregardedEntitiesGrp/ForeignAddress"               
## [15] "//IdDisregardedEntitiesGrp/USAddress"                    
## [16] "//IdDisregardedEntitiesGrp/EIN"                          
## [17] "//IdDisregardedEntitiesGrp/DisregardedEntityName"        
## [18] "//IdDisregardedEntitiesGrp/PrimaryActivitiesTxt"         
## [19] "//IdDisregardedEntitiesGrp/LegalDomicileForeignCountryCd"
## [20] "//IdDisregardedEntitiesGrp/LegalDomicileStateCd"         
## [21] "//IdDisregardedEntitiesGrp/TotalIncomeAmt"               
## [22] "//IdDisregardedEntitiesGrp/EndOfYearAssetsAmt"           
## [23] "//IdDisregardedEntitiesGrp/DirectControllingNACd"        
## [24] "//IdDisregardedEntitiesGrp/DirectControllingEntityName"

Groups can then be used to extract the 1:M RDB tables:

if( is.null(table.headers) )
{ table.headers <- find_table_headers( table.name ) }
demo.url <- "https://nccs-efile.s3.us-east-1.amazonaws.com/xml/201913079349300206_public.xml"
doc <- xml2::read_xml( demo.url )
xml2::xml_ns_strip( doc )
df.demo <- get_table_v2( doc, table.name, table.headers )
df.demo 
## NULL

Standardize Variable Names

Mapping of xml variable names to concordance variable names:

get_var_map( table.name=table.name )

A table with proper names:

v.map <- get_var_map( table.name=table.name )

if( ! is.null(df.demo) )
{re_name( df.demo, v.map ) %>% as.data.frame()}