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/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressForeign/AddressLine1 1
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressForeign/AddressLine2 2
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressForeign/City 3
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressForeign/Country 4
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressForeign/PostalCode 5
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressForeign/ProvinceOrState 6
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressUS/AddressLine1 7
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressUS/AddressLine2 8
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressUS/City 9
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressUS/State 10
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressUS/ZIPCode 11
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AmtOfContribsRecdDelivered 12
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AmtPdFromInternalFunds 13
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/EIN 14
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/NameOf527Organization/BusinessNameLine1 15
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/NameOf527Organization/BusinessNameLine2 16
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressForeign/AddressLine1 17
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressForeign/AddressLine2 18
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressForeign/City 19
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressForeign/Country 20
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressForeign/PostalCode 21
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressForeign/ProvinceOrState 22
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressUS/AddressLine1 23
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressUS/AddressLine2 24
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressUS/City 25
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressUS/State 26
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressUS/ZIPCode 27
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AmtOfContribsRecdDelivered 28
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AmtPdFromInternalFunds 29
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/EIN 30
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/NameOf527Organization/BusinessNameLine1 31
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/NameOf527Organization/BusinessNameLine2 32
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ContributionsRcvdDlvrAmt 33
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/EIN 34
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/AddressLine1 35
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/AddressLine1Txt 36
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/AddressLine2 37
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/AddressLine2Txt 38
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/City 39
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/CityNm 40
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/Country 41
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/CountryCd 42
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/ForeignPostalCd 43
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/PostalCode 44
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/ProvinceOrState 45
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/ProvinceOrStateNm 46
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/OrganizationBusinessName/BusinessNameLine1 47
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/OrganizationBusinessName/BusinessNameLine1Txt 48
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/OrganizationBusinessName/BusinessNameLine2 49
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/OrganizationBusinessName/BusinessNameLine2Txt 50
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/PaidInternalFundsAmt 51
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/AddressLine1 52
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/AddressLine1Txt 53
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/AddressLine2 54
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/AddressLine2Txt 55
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/City 56
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/CityNm 57
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/State 58
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/StateAbbreviationCd 59
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/ZIPCd 60
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/ZIPCode 61
xpaths <- as.character( t.xpaths$xpath )
el <- create_edgelist_v1( xpaths )
nd <- FromDataFrameNetwork( network=el )
print( nd )
##                                         levelName
## 1  Return                                        
## 2   °--ReturnData                                
## 3       °--IRS990ScheduleC                       
## 4           ¦--Form990ScheduleCPartI             
## 5           ¦   °--Sec527PolOrgs                 
## 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          ¦       ¦--AmtOfContribsRecdDelivered
## 20          ¦       ¦--AmtPdFromInternalFunds    
## 21          ¦       ¦--EIN                       
## 22          ¦       °--NameOf527Organization     
## 23          ¦           ¦--BusinessNameLine1     
## 24          ¦           °--BusinessNameLine2     
## 25          ¦--Sec527PolOrgs                     
## 26          ¦   ¦--AddressForeign                
## 27          ¦   ¦   ¦--AddressLine1              
## 28          ¦   ¦   ¦--AddressLine2              
## 29          ¦   ¦   ¦--City                      
## 30          ¦   ¦   ¦--Country                   
## 31          ¦   ¦   ¦--PostalCode                
## 32          ¦   ¦   °--ProvinceOrState           
## 33          ¦   ¦--AddressUS                     
## 34          ¦   ¦   ¦--AddressLine1              
## 35          ¦   ¦   ¦--AddressLine2              
## 36          ¦   ¦   ¦--City                      
## 37          ¦   ¦   ¦--State                     
## 38          ¦   ¦   °--ZIPCode                   
## 39          ¦   ¦--AmtOfContribsRecdDelivered    
## 40          ¦   ¦--AmtPdFromInternalFunds        
## 41          ¦   ¦--EIN                           
## 42          ¦   °--NameOf527Organization         
## 43          ¦       ¦--BusinessNameLine1         
## 44          ¦       °--BusinessNameLine2         
## 45          °--Section527PoliticalOrgGrp         
## 46              ¦--ContributionsRcvdDlvrAmt      
## 47              ¦--EIN                           
## 48              ¦--ForeignAddress                
## 49              ¦   ¦--AddressLine1              
## 50              ¦   ¦--AddressLine1Txt           
## 51              ¦   ¦--AddressLine2              
## 52              ¦   ¦--AddressLine2Txt           
## 53              ¦   ¦--City                      
## 54              ¦   ¦--CityNm                    
## 55              ¦   ¦--Country                   
## 56              ¦   ¦--CountryCd                 
## 57              ¦   ¦--ForeignPostalCd           
## 58              ¦   ¦--PostalCode                
## 59              ¦   ¦--ProvinceOrState           
## 60              ¦   °--ProvinceOrStateNm         
## 61              ¦--OrganizationBusinessName      
## 62              ¦   ¦--BusinessNameLine1         
## 63              ¦   ¦--BusinessNameLine1Txt      
## 64              ¦   ¦--BusinessNameLine2         
## 65              ¦   °--BusinessNameLine2Txt      
## 66              ¦--PaidInternalFundsAmt          
## 67              °--USAddress                     
## 68                  ¦--AddressLine1              
## 69                  ¦--AddressLine1Txt           
## 70                  ¦--AddressLine2              
## 71                  ¦--AddressLine2Txt           
## 72                  ¦--City                      
## 73                  ¦--CityNm                    
## 74                  ¦--State                     
## 75                  ¦--StateAbbreviationCd       
## 76                  ¦--ZIPCd                     
## 77                  °--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] "//Form990ScheduleCPartI"     "//Sec527PolOrgs"            
## [3] "//Section527PoliticalOrgGrp"
# new version
find_table_headers( table.name )
##  [1] "//Form990ScheduleCPartI/PoliticalExpenditures"         
##  [2] "//Form990ScheduleCPartI/VolunteerHours"                
##  [3] "//Form990ScheduleCPartI/AmtOf4955Tax"                  
##  [4] "//Form990ScheduleCPartI/AmtOf4955TaxOnManagers"        
##  [5] "//Form990ScheduleCPartI/Form4720Filed4955Tax"          
##  [6] "//Form990ScheduleCPartI/CorrectionMade"                
##  [7] "//Form990ScheduleCPartI/AmtExpendedFor527Activities"   
##  [8] "//Form990ScheduleCPartI/AmtOfInternalFundsContributed" 
##  [9] "//Form990ScheduleCPartI/TotalExmptFunctionExpenditures"
## [10] "//Form990ScheduleCPartI/Form1120PolFiled"              
## [11] "//Form990ScheduleCPartI/Sec527PolOrgs"                 
## [12] "//Sec527PolOrgs/Form990ScheduleCPartI"                 
## [13] "//Sec527PolOrgs/Sec527PolOrgs"                         
## [14] "//Section527PoliticalOrgGrp/OrganizationBusinessName"  
## [15] "//Section527PoliticalOrgGrp/ForeignAddress"            
## [16] "//Section527PoliticalOrgGrp/USAddress"                 
## [17] "//Section527PoliticalOrgGrp/EIN"                       
## [18] "//Section527PoliticalOrgGrp/ContributionsRcvdDlvrAmt"  
## [19] "//Section527PoliticalOrgGrp/PaidInternalFundsAmt"
# 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: SC-P01-T01-POLITICAL-ORGS-INFO

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

TOTAL RUN TIME:

## Time difference of 19.98196 mins
## Time difference of -0.3330326 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] "SC_01_POLI_ORG_EIN"           "SC_01_POLI_ORG_AMT_CONTR_REC"
##  [9] "SC_01_POLI_ORG_NAME_L1"       "SC_01_POLI_ORG_ADDR_L1"      
## [11] "SC_01_POLI_ORG_ADDR_CITY"     "SC_01_POLI_ORG_ADDR_STATE"   
## [13] "SC_01_POLI_ORG_ADDR_ZIP"      "SC_01_POLI_ORG_AMT_FUND_PAID"
## [15] "SC_01_POLI_ORG_ADDR_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/IRS990ScheduleC/Section527PoliticalOrgGrp/OrganizationBusinessName"
## [3] "/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/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       °--IRS990ScheduleC                 
## 4           °--Section527PoliticalOrgGrp   
## 5               ¦--ContributionsRcvdDlvrAmt
## 6               ¦--EIN                     
## 7               ¦--OrganizationBusinessName
## 8               ¦   °--BusinessNameLine1Txt
## 9               ¦--PaidInternalFundsAmt    
## 10              °--USAddress               
## 11                  ¦--AddressLine1Txt     
## 12                  ¦--AddressLine2Txt     
## 13                  ¦--CityNm              
## 14                  ¦--StateAbbreviationCd 
## 15                  °--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/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressForeign/AddressLine1 1
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressForeign/AddressLine2 2
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressForeign/City 3
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressForeign/Country 4
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressForeign/PostalCode 5
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressForeign/ProvinceOrState 6
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressUS/AddressLine1 7
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressUS/AddressLine2 8
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressUS/City 9
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressUS/State 10
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AddressUS/ZIPCode 11
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AmtOfContribsRecdDelivered 12
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/AmtPdFromInternalFunds 13
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/EIN 14
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/NameOf527Organization/BusinessNameLine1 15
/Return/ReturnData/IRS990ScheduleC/Form990ScheduleCPartI/Sec527PolOrgs/NameOf527Organization/BusinessNameLine2 16
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressForeign/AddressLine1 17
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressForeign/AddressLine2 18
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressForeign/City 19
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressForeign/Country 20
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressForeign/PostalCode 21
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressForeign/ProvinceOrState 22
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressUS/AddressLine1 23
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressUS/AddressLine2 24
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressUS/City 25
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressUS/State 26
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AddressUS/ZIPCode 27
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AmtOfContribsRecdDelivered 28
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/AmtPdFromInternalFunds 29
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/EIN 30
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/NameOf527Organization/BusinessNameLine1 31
/Return/ReturnData/IRS990ScheduleC/Sec527PolOrgs/NameOf527Organization/BusinessNameLine2 32
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ContributionsRcvdDlvrAmt 33
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/EIN 34
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/AddressLine1 35
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/AddressLine1Txt 36
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/AddressLine2 37
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/AddressLine2Txt 38
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/City 39
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/CityNm 40
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/Country 41
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/CountryCd 42
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/ForeignPostalCd 43
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/PostalCode 44
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/ProvinceOrState 45
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/ForeignAddress/ProvinceOrStateNm 46
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/OrganizationBusinessName/BusinessNameLine1 47
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/OrganizationBusinessName/BusinessNameLine1Txt 48
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/OrganizationBusinessName/BusinessNameLine2 49
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/OrganizationBusinessName/BusinessNameLine2Txt 50
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/PaidInternalFundsAmt 51
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/AddressLine1 52
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/AddressLine1Txt 53
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/AddressLine2 54
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/AddressLine2Txt 55
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/City 56
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/CityNm 57
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/State 58
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/StateAbbreviationCd 59
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/ZIPCd 60
/Return/ReturnData/IRS990ScheduleC/Section527PoliticalOrgGrp/USAddress/ZIPCode 61

Grouping Variables

Identify all unique groups used in xpaths.

if( is.null(table.headers) )
{ find_table_headers( table.name ) } else
table.headers
##  [1] "//Form990ScheduleCPartI/PoliticalExpenditures"         
##  [2] "//Form990ScheduleCPartI/VolunteerHours"                
##  [3] "//Form990ScheduleCPartI/AmtOf4955Tax"                  
##  [4] "//Form990ScheduleCPartI/AmtOf4955TaxOnManagers"        
##  [5] "//Form990ScheduleCPartI/Form4720Filed4955Tax"          
##  [6] "//Form990ScheduleCPartI/CorrectionMade"                
##  [7] "//Form990ScheduleCPartI/AmtExpendedFor527Activities"   
##  [8] "//Form990ScheduleCPartI/AmtOfInternalFundsContributed" 
##  [9] "//Form990ScheduleCPartI/TotalExmptFunctionExpenditures"
## [10] "//Form990ScheduleCPartI/Form1120PolFiled"              
## [11] "//Form990ScheduleCPartI/Sec527PolOrgs"                 
## [12] "//Sec527PolOrgs/Form990ScheduleCPartI"                 
## [13] "//Sec527PolOrgs/Sec527PolOrgs"                         
## [14] "//Section527PoliticalOrgGrp/OrganizationBusinessName"  
## [15] "//Section527PoliticalOrgGrp/ForeignAddress"            
## [16] "//Section527PoliticalOrgGrp/USAddress"                 
## [17] "//Section527PoliticalOrgGrp/EIN"                       
## [18] "//Section527PoliticalOrgGrp/ContributionsRcvdDlvrAmt"  
## [19] "//Section527PoliticalOrgGrp/PaidInternalFundsAmt"

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