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/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressForeign/AddressLine1 1
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressForeign/AddressLine2 2
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressForeign/City 3
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressForeign/Country 4
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressForeign/PostalCode 5
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressForeign/ProvinceOrState 6
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressUS/AddressLine1 7
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressUS/AddressLine2 8
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressUS/City 9
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressUS/State 10
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressUS/ZIPCode 11
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AmountOfCashGrant 12
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AmountOfNonCashAssistance 13
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/DescriptionOfNonCashGrant 14
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/EINOfRecipient 15
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/IRCSection 16
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/MethodOfValuation 17
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/PurposeOfGrant 18
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/RecipientNameBusiness/BusinessNameLine1 19
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/RecipientNameBusiness/BusinessNameLine2 20
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressForeign/AddressLine1 21
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressForeign/AddressLine2 22
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressForeign/City 23
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressForeign/Country 24
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressForeign/PostalCode 25
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressForeign/ProvinceOrState 26
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressUS/AddressLine1 27
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressUS/AddressLine2 28
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressUS/City 29
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressUS/State 30
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressUS/ZIPCode 31
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AmountOfCashGrant 32
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AmountOfNonCashAssistance 33
/Return/ReturnData/IRS990ScheduleI/RecipientTable/CashGrantAmt 34
/Return/ReturnData/IRS990ScheduleI/RecipientTable/DescriptionOfNonCashAssistance 35
/Return/ReturnData/IRS990ScheduleI/RecipientTable/EINOfRecipient 36
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/AddressLine1 37
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/AddressLine1Txt 38
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/AddressLine2 39
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/AddressLine2Txt 40
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/City 41
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/CityNm 42
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/Country 43
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/CountryCd 44
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/ForeignPostalCd 45
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/PostalCode 46
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/ProvinceOrState 47
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/ProvinceOrStateNm 48
/Return/ReturnData/IRS990ScheduleI/RecipientTable/IRCSection 49
/Return/ReturnData/IRS990ScheduleI/RecipientTable/IRCSectionDesc 50
/Return/ReturnData/IRS990ScheduleI/RecipientTable/MethodOfValuation 51
/Return/ReturnData/IRS990ScheduleI/RecipientTable/NonCashAssistanceAmt 52
/Return/ReturnData/IRS990ScheduleI/RecipientTable/NonCashAssistanceDesc 53
/Return/ReturnData/IRS990ScheduleI/RecipientTable/PurposeOfGrant 54
/Return/ReturnData/IRS990ScheduleI/RecipientTable/PurposeOfGrantTxt 55
/Return/ReturnData/IRS990ScheduleI/RecipientTable/RecipientBusinessName/BusinessNameLine1 56
/Return/ReturnData/IRS990ScheduleI/RecipientTable/RecipientBusinessName/BusinessNameLine1Txt 57
/Return/ReturnData/IRS990ScheduleI/RecipientTable/RecipientBusinessName/BusinessNameLine2 58
/Return/ReturnData/IRS990ScheduleI/RecipientTable/RecipientBusinessName/BusinessNameLine2Txt 59
/Return/ReturnData/IRS990ScheduleI/RecipientTable/RecipientEIN 60
/Return/ReturnData/IRS990ScheduleI/RecipientTable/RecipientNameBusiness/BusinessNameLine1 61
/Return/ReturnData/IRS990ScheduleI/RecipientTable/RecipientNameBusiness/BusinessNameLine2 62
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/AddressLine1 63
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/AddressLine1Txt 64
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/AddressLine2 65
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/AddressLine2Txt 66
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/City 67
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/CityNm 68
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/State 69
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/StateAbbreviationCd 70
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/ZIPCd 71
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/ZIPCode 72
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ValuationMethodUsedDesc 73
xpaths <- as.character( t.xpaths$xpath )
el <- create_edgelist_v1( xpaths )
nd <- FromDataFrameNetwork( network=el )
print( nd )
##                                              levelName
## 1   Return                                            
## 2    °--ReturnData                                    
## 3        °--IRS990ScheduleI                           
## 4            ¦--Form990ScheduleIPartII                
## 5            ¦   °--RecipientTable                    
## 6            ¦       ¦--AddressForeign                
## 7            ¦       ¦   ¦--AddressLine1              
## 8            ¦       ¦   ¦--AddressLine2              
## 9            ¦       ¦   ¦--City                      
## 10           ¦       ¦   ¦--Country                   
## 11           ¦       ¦   ¦--PostalCode                
## 12           ¦       ¦   °--ProvinceOrState           
## 13           ¦       ¦--AddressUS                     
## 14           ¦       ¦   ¦--AddressLine1              
## 15           ¦       ¦   ¦--AddressLine2              
## 16           ¦       ¦   ¦--City                      
## 17           ¦       ¦   ¦--State                     
## 18           ¦       ¦   °--ZIPCode                   
## 19           ¦       ¦--AmountOfCashGrant             
## 20           ¦       ¦--AmountOfNonCashAssistance     
## 21           ¦       ¦--DescriptionOfNonCashGrant     
## 22           ¦       ¦--EINOfRecipient                
## 23           ¦       ¦--IRCSection                    
## 24           ¦       ¦--MethodOfValuation             
## 25           ¦       ¦--PurposeOfGrant                
## 26           ¦       ¦--RecipientNameBusiness         
## 27           ¦       ¦   ¦--BusinessNameLine1         
## 28           ¦       ¦   °--BusinessNameLine2         
## 29           ¦       ¦--CashGrantAmt                  
## 30           ¦       ¦--DescriptionOfNonCashAssistance
## 31           ¦       ¦--ForeignAddress                
## 32           ¦       ¦   ¦--AddressLine1              
## 33           ¦       ¦   ¦--AddressLine1Txt           
## 34           ¦       ¦   ¦--AddressLine2              
## 35           ¦       ¦   ¦--AddressLine2Txt           
## 36           ¦       ¦   ¦--City                      
## 37           ¦       ¦   ¦--CityNm                    
## 38           ¦       ¦   ¦--Country                   
## 39           ¦       ¦   ¦--CountryCd                 
## 40           ¦       ¦   ¦--ForeignPostalCd           
## 41           ¦       ¦   ¦--PostalCode                
## 42           ¦       ¦   ¦--ProvinceOrState           
## 43           ¦       ¦   °--ProvinceOrStateNm         
## 44           ¦       ¦--IRCSectionDesc                
## 45           ¦       ¦--NonCashAssistanceAmt          
## 46           ¦       ¦--NonCashAssistanceDesc         
## 47           ¦       ¦--PurposeOfGrantTxt             
## 48           ¦       ¦--RecipientBusinessName         
## 49           ¦       ¦   ¦--BusinessNameLine1         
## 50           ¦       ¦   ¦--BusinessNameLine1Txt      
## 51           ¦       ¦   ¦--BusinessNameLine2         
## 52           ¦       ¦   °--BusinessNameLine2Txt      
## 53           ¦       ¦--RecipientEIN                  
## 54           ¦       ¦--USAddress                     
## 55           ¦       ¦   ¦--AddressLine1              
## 56           ¦       ¦   ¦--AddressLine1Txt           
## 57           ¦       ¦   ¦--AddressLine2              
## 58           ¦       ¦   ¦--AddressLine2Txt           
## 59           ¦       ¦   ¦--City                      
## 60           ¦       ¦   ¦--CityNm                    
## 61           ¦       ¦   ¦--State                     
## 62           ¦       ¦   ¦--StateAbbreviationCd       
## 63           ¦       ¦   ¦--ZIPCd                     
## 64           ¦       ¦   °--ZIPCode                   
## 65           ¦       °--ValuationMethodUsedDesc       
## 66           °--RecipientTable                        
## 67               ¦--AddressForeign                    
## 68               ¦   ¦--AddressLine1                  
## 69               ¦   ¦--AddressLine2                  
## 70               ¦   ¦--City                          
## 71               ¦   ¦--Country                       
## 72               ¦   ¦--PostalCode                    
## 73               ¦   °--ProvinceOrState               
## 74               ¦--AddressUS                         
## 75               ¦   ¦--AddressLine1                  
## 76               ¦   ¦--AddressLine2                  
## 77               ¦   ¦--City                          
## 78               ¦   ¦--State                         
## 79               ¦   °--ZIPCode                       
## 80               ¦--AmountOfCashGrant                 
## 81               ¦--AmountOfNonCashAssistance         
## 82               ¦--DescriptionOfNonCashGrant         
## 83               ¦--EINOfRecipient                    
## 84               ¦--IRCSection                        
## 85               ¦--MethodOfValuation                 
## 86               ¦--PurposeOfGrant                    
## 87               ¦--RecipientNameBusiness             
## 88               ¦   ¦--BusinessNameLine1             
## 89               ¦   °--BusinessNameLine2             
## 90               ¦--CashGrantAmt                      
## 91               ¦--DescriptionOfNonCashAssistance    
## 92               ¦--ForeignAddress                    
## 93               ¦   ¦--AddressLine1                  
## 94               ¦   ¦--AddressLine1Txt               
## 95               ¦   ¦--AddressLine2                  
## 96               ¦   ¦--AddressLine2Txt               
## 97               ¦   ¦--City                          
## 98               ¦   ¦--CityNm                        
## 99               ¦   ¦--Country                       
## 100              ¦   °--... 5 nodes w/ 0 sub          
## 101              °--... 8 nodes w/ 19 sub
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] "//Form990ScheduleIPartII" "//RecipientTable"
# new version
find_table_headers( table.name )
## [1] "//Form990ScheduleIPartII/RecipientTable"              
## [2] "//Form990ScheduleIPartII/TotalNbrOf501C3AndGovtGrants"
## [3] "//Form990ScheduleIPartII/TotalNbrOfOtherOrganizations"
## [4] "//Form990ScheduleIPartII/NoGrantMoreThan5000"         
## [5] "//RecipientTable/Form990ScheduleIPartII"              
## [6] "//RecipientTable/RecipientTable"
# manual
if( ! is.null(table.headers) )
{table.headers}
## [1] "//IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable"
## [2] "//IRS990ScheduleI/RecipientTable"








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: SI-P02-T01-GRANTS-US-ORGS-GOVTS

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

TOTAL RUN TIME:

## Time difference of 36.6707 mins
## Time difference of -0.6111783 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] "SI_02_GRANT_US_ORG_EIN"         "SI_02_GRANT_US_ORG_IRC_SECTION"
##  [9] "SI_02_GRANT_US_ORG_AMT_CASH"    "SI_02_GRANT_US_ORG_PURPOSE"    
## [11] "SI_02_GRANT_US_ORG_NAME_L1"     "SI_02_GRANT_US_ORG_ADDR_L1"    
## [13] "SI_02_GRANT_US_ORG_ADDR_CITY"   "SI_02_GRANT_US_ORG_ADDR_STATE" 
## [15] "SI_02_GRANT_US_ORG_ADDR_ZIP"    "SI_02_GRANT_US_ORG_AMT_NONCSH" 
## [17] "SI_02_GRANT_US_ORG_MOV"         "SI_02_GRANT_US_ORG_DESC_NONCSH"
## [19] "SI_02_GRANT_US_ORG_ADDR_L2"     "SI_02_GRANT_US_ORG_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/IRS990ScheduleI/RecipientTable"                      
## [3] "/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress"       
## [4] "/Return/ReturnData/IRS990ScheduleI/RecipientTable/RecipientBusinessName"
## [5] "/Return/ReturnData/IRS990ScheduleI/RecipientTable/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       °--IRS990ScheduleI                 
## 4           °--RecipientTable              
## 5               ¦--CashGrantAmt            
## 6               ¦--ForeignAddress          
## 7               ¦   ¦--AddressLine1Txt     
## 8               ¦   ¦--CityNm              
## 9               ¦   ¦--CountryCd           
## 10              ¦   ¦--ForeignPostalCd     
## 11              ¦   °--ProvinceOrStateNm   
## 12              ¦--IRCSectionDesc          
## 13              ¦--NonCashAssistanceAmt    
## 14              ¦--NonCashAssistanceDesc   
## 15              ¦--PurposeOfGrantTxt       
## 16              ¦--RecipientBusinessName   
## 17              ¦   ¦--BusinessNameLine1Txt
## 18              ¦   °--BusinessNameLine2Txt
## 19              ¦--RecipientEIN            
## 20              ¦--USAddress               
## 21              ¦   ¦--AddressLine1Txt     
## 22              ¦   ¦--AddressLine2Txt     
## 23              ¦   ¦--CityNm              
## 24              ¦   ¦--StateAbbreviationCd 
## 25              ¦   °--ZIPCd               
## 26              °--ValuationMethodUsedDesc
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/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressForeign/AddressLine1 1
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressForeign/AddressLine2 2
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressForeign/City 3
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressForeign/Country 4
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressForeign/PostalCode 5
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressForeign/ProvinceOrState 6
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressUS/AddressLine1 7
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressUS/AddressLine2 8
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressUS/City 9
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressUS/State 10
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AddressUS/ZIPCode 11
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AmountOfCashGrant 12
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/AmountOfNonCashAssistance 13
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/DescriptionOfNonCashGrant 14
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/EINOfRecipient 15
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/IRCSection 16
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/MethodOfValuation 17
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/PurposeOfGrant 18
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/RecipientNameBusiness/BusinessNameLine1 19
/Return/ReturnData/IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable/RecipientNameBusiness/BusinessNameLine2 20
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressForeign/AddressLine1 21
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressForeign/AddressLine2 22
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressForeign/City 23
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressForeign/Country 24
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressForeign/PostalCode 25
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressForeign/ProvinceOrState 26
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressUS/AddressLine1 27
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressUS/AddressLine2 28
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressUS/City 29
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressUS/State 30
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AddressUS/ZIPCode 31
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AmountOfCashGrant 32
/Return/ReturnData/IRS990ScheduleI/RecipientTable/AmountOfNonCashAssistance 33
/Return/ReturnData/IRS990ScheduleI/RecipientTable/CashGrantAmt 34
/Return/ReturnData/IRS990ScheduleI/RecipientTable/DescriptionOfNonCashAssistance 35
/Return/ReturnData/IRS990ScheduleI/RecipientTable/EINOfRecipient 36
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/AddressLine1 37
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/AddressLine1Txt 38
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/AddressLine2 39
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/AddressLine2Txt 40
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/City 41
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/CityNm 42
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/Country 43
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/CountryCd 44
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/ForeignPostalCd 45
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/PostalCode 46
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/ProvinceOrState 47
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ForeignAddress/ProvinceOrStateNm 48
/Return/ReturnData/IRS990ScheduleI/RecipientTable/IRCSection 49
/Return/ReturnData/IRS990ScheduleI/RecipientTable/IRCSectionDesc 50
/Return/ReturnData/IRS990ScheduleI/RecipientTable/MethodOfValuation 51
/Return/ReturnData/IRS990ScheduleI/RecipientTable/NonCashAssistanceAmt 52
/Return/ReturnData/IRS990ScheduleI/RecipientTable/NonCashAssistanceDesc 53
/Return/ReturnData/IRS990ScheduleI/RecipientTable/PurposeOfGrant 54
/Return/ReturnData/IRS990ScheduleI/RecipientTable/PurposeOfGrantTxt 55
/Return/ReturnData/IRS990ScheduleI/RecipientTable/RecipientBusinessName/BusinessNameLine1 56
/Return/ReturnData/IRS990ScheduleI/RecipientTable/RecipientBusinessName/BusinessNameLine1Txt 57
/Return/ReturnData/IRS990ScheduleI/RecipientTable/RecipientBusinessName/BusinessNameLine2 58
/Return/ReturnData/IRS990ScheduleI/RecipientTable/RecipientBusinessName/BusinessNameLine2Txt 59
/Return/ReturnData/IRS990ScheduleI/RecipientTable/RecipientEIN 60
/Return/ReturnData/IRS990ScheduleI/RecipientTable/RecipientNameBusiness/BusinessNameLine1 61
/Return/ReturnData/IRS990ScheduleI/RecipientTable/RecipientNameBusiness/BusinessNameLine2 62
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/AddressLine1 63
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/AddressLine1Txt 64
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/AddressLine2 65
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/AddressLine2Txt 66
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/City 67
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/CityNm 68
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/State 69
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/StateAbbreviationCd 70
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/ZIPCd 71
/Return/ReturnData/IRS990ScheduleI/RecipientTable/USAddress/ZIPCode 72
/Return/ReturnData/IRS990ScheduleI/RecipientTable/ValuationMethodUsedDesc 73

Grouping Variables

Identify all unique groups used in xpaths.

if( is.null(table.headers) )
{ find_table_headers( table.name ) } else
table.headers
## [1] "//IRS990ScheduleI/Form990ScheduleIPartII/RecipientTable"
## [2] "//IRS990ScheduleI/RecipientTable"

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()}