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/IRS990ScheduleJ/Form990ScheduleJPartII/BaseCompensationFilingOrg 1
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/BonusFilingOrg 2
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/BonusRelatedOrgs 3
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/CompBasedOnRelatedOrgs 4
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/CompReportPrior990FilingOrg 5
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/CompReportPrior990RelatedOrgs 6
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/DeferredCompFilingOrg 7
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/DeferredCompRelatedOrgs 8
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/NameBusiness/BusinessNameLine1 9
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/NameBusiness/BusinessNameLine2 10
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/NamePerson 11
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/NontaxableBenefitsFilingOrg 12
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/NontaxableBenefitsRelatedOrgs 13
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/OtherCompensationFilingOrg 14
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/OtherCompensationRelatedOrgs 15
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/Title 16
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/TotalCompensationFilingOrg 17
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/TotalCompensationRelatedOrgs 18
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/BaseCompensationFilingOrgAmt 19
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/BonusFilingOrganizationAmount 20
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/BonusRelatedOrganizationsAmt 21
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/BusinessName/BusinessNameLine1 22
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/BusinessName/BusinessNameLine1Txt 23
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/BusinessName/BusinessNameLine2 24
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/BusinessName/BusinessNameLine2Txt 25
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/CompReportPrior990FilingOrgAmt 26
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/CompReportPrior990RltdOrgsAmt 27
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/CompensationBasedOnRltdOrgsAmt 28
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/DeferredCompRltdOrgsAmt 29
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/DeferredCompensationFlngOrgAmt 30
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/NontaxableBenefitsFilingOrgAmt 31
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/NontaxableBenefitsRltdOrgsAmt 32
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/OtherCompensationFilingOrgAmt 33
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/OtherCompensationRltdOrgsAmt 34
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/PersonNm 35
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/TitleTxt 36
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/TotalCompensationFilingOrgAmt 37
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/TotalCompensationRltdOrgsAmt 38
xpaths <- as.character( t.xpaths$xpath )
el <- create_edgelist_v1( xpaths )
nd <- FromDataFrameNetwork( network=el )
print( nd )
##                                         levelName
## 1  Return                                        
## 2   °--ReturnData                                
## 3       °--IRS990ScheduleJ                       
## 4           ¦--Form990ScheduleJPartII            
## 5           ¦   ¦--BaseCompensationFilingOrg     
## 6           ¦   ¦--BonusFilingOrg                
## 7           ¦   ¦--BonusRelatedOrgs              
## 8           ¦   ¦--CompBasedOnRelatedOrgs        
## 9           ¦   ¦--CompReportPrior990FilingOrg   
## 10          ¦   ¦--CompReportPrior990RelatedOrgs 
## 11          ¦   ¦--DeferredCompFilingOrg         
## 12          ¦   ¦--DeferredCompRelatedOrgs       
## 13          ¦   ¦--NameBusiness                  
## 14          ¦   ¦   ¦--BusinessNameLine1         
## 15          ¦   ¦   °--BusinessNameLine2         
## 16          ¦   ¦--NamePerson                    
## 17          ¦   ¦--NontaxableBenefitsFilingOrg   
## 18          ¦   ¦--NontaxableBenefitsRelatedOrgs 
## 19          ¦   ¦--OtherCompensationFilingOrg    
## 20          ¦   ¦--OtherCompensationRelatedOrgs  
## 21          ¦   ¦--Title                         
## 22          ¦   ¦--TotalCompensationFilingOrg    
## 23          ¦   °--TotalCompensationRelatedOrgs  
## 24          °--RltdOrgOfficerTrstKeyEmplGrp      
## 25              ¦--BaseCompensationFilingOrgAmt  
## 26              ¦--BonusFilingOrganizationAmount 
## 27              ¦--BonusRelatedOrganizationsAmt  
## 28              ¦--BusinessName                  
## 29              ¦   ¦--BusinessNameLine1         
## 30              ¦   ¦--BusinessNameLine1Txt      
## 31              ¦   ¦--BusinessNameLine2         
## 32              ¦   °--BusinessNameLine2Txt      
## 33              ¦--CompReportPrior990FilingOrgAmt
## 34              ¦--CompReportPrior990RltdOrgsAmt 
## 35              ¦--CompensationBasedOnRltdOrgsAmt
## 36              ¦--DeferredCompRltdOrgsAmt       
## 37              ¦--DeferredCompensationFlngOrgAmt
## 38              ¦--NontaxableBenefitsFilingOrgAmt
## 39              ¦--NontaxableBenefitsRltdOrgsAmt 
## 40              ¦--OtherCompensationFilingOrgAmt 
## 41              ¦--OtherCompensationRltdOrgsAmt  
## 42              ¦--PersonNm                      
## 43              ¦--TitleTxt                      
## 44              ¦--TotalCompensationFilingOrgAmt 
## 45              °--TotalCompensationRltdOrgsAmt
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] "//Form990ScheduleJPartII"       "//RltdOrgOfficerTrstKeyEmplGrp"
# new version
find_table_headers( table.name )
##  [1] "//Form990ScheduleJPartII/NameBusiness"                        
##  [2] "//Form990ScheduleJPartII/NamePerson"                          
##  [3] "//Form990ScheduleJPartII/Title"                               
##  [4] "//Form990ScheduleJPartII/BaseCompensationFilingOrg"           
##  [5] "//Form990ScheduleJPartII/CompBasedOnRelatedOrgs"              
##  [6] "//Form990ScheduleJPartII/BonusFilingOrg"                      
##  [7] "//Form990ScheduleJPartII/BonusRelatedOrgs"                    
##  [8] "//Form990ScheduleJPartII/OtherCompensationFilingOrg"          
##  [9] "//Form990ScheduleJPartII/OtherCompensationRelatedOrgs"        
## [10] "//Form990ScheduleJPartII/DeferredCompFilingOrg"               
## [11] "//Form990ScheduleJPartII/DeferredCompRelatedOrgs"             
## [12] "//Form990ScheduleJPartII/NontaxableBenefitsFilingOrg"         
## [13] "//Form990ScheduleJPartII/NontaxableBenefitsRelatedOrgs"       
## [14] "//Form990ScheduleJPartII/TotalCompensationFilingOrg"          
## [15] "//Form990ScheduleJPartII/TotalCompensationRelatedOrgs"        
## [16] "//Form990ScheduleJPartII/CompReportPrior990FilingOrg"         
## [17] "//Form990ScheduleJPartII/CompReportPrior990RelatedOrgs"       
## [18] "//RltdOrgOfficerTrstKeyEmplGrp/BusinessName"                  
## [19] "//RltdOrgOfficerTrstKeyEmplGrp/PersonNm"                      
## [20] "//RltdOrgOfficerTrstKeyEmplGrp/TitleTxt"                      
## [21] "//RltdOrgOfficerTrstKeyEmplGrp/BaseCompensationFilingOrgAmt"  
## [22] "//RltdOrgOfficerTrstKeyEmplGrp/CompensationBasedOnRltdOrgsAmt"
## [23] "//RltdOrgOfficerTrstKeyEmplGrp/BonusFilingOrganizationAmount" 
## [24] "//RltdOrgOfficerTrstKeyEmplGrp/BonusRelatedOrganizationsAmt"  
## [25] "//RltdOrgOfficerTrstKeyEmplGrp/OtherCompensationFilingOrgAmt" 
## [26] "//RltdOrgOfficerTrstKeyEmplGrp/OtherCompensationRltdOrgsAmt"  
## [27] "//RltdOrgOfficerTrstKeyEmplGrp/DeferredCompensationFlngOrgAmt"
## [28] "//RltdOrgOfficerTrstKeyEmplGrp/DeferredCompRltdOrgsAmt"       
## [29] "//RltdOrgOfficerTrstKeyEmplGrp/NontaxableBenefitsFilingOrgAmt"
## [30] "//RltdOrgOfficerTrstKeyEmplGrp/NontaxableBenefitsRltdOrgsAmt" 
## [31] "//RltdOrgOfficerTrstKeyEmplGrp/TotalCompensationFilingOrgAmt" 
## [32] "//RltdOrgOfficerTrstKeyEmplGrp/TotalCompensationRltdOrgsAmt"  
## [33] "//RltdOrgOfficerTrstKeyEmplGrp/CompReportPrior990FilingOrgAmt"
## [34] "//RltdOrgOfficerTrstKeyEmplGrp/CompReportPrior990RltdOrgsAmt"
# 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: SJ-P02-T01-COMPENSATION-DTK

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

TOTAL RUN TIME:

## Time difference of 35.85313 mins
## Time difference of -0.5975521 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] "SJ_02_COMP_DTK_NAME_PERS"      "SJ_02_COMP_DTK_TITLE"         
##  [9] "SJ_02_COMP_DTK_BASE_ORG"       "SJ_02_COMP_DTK_BASE_RLTD"     
## [11] "SJ_02_COMP_DTK_BONUS_ORG"      "SJ_02_COMP_DTK_BONUS_RLTD"    
## [13] "SJ_02_COMP_DTK_OTH_ORG"        "SJ_02_COMP_DTK_OTH_RLTD"      
## [15] "SJ_02_COMP_DTK_DEFERRED_ORG"   "SJ_02_COMP_DTK_DEFERRED_RLTD" 
## [17] "SJ_02_COMP_DTK_BENFIT_ORG"     "SJ_02_COMP_DTK_BENFIT_RLTD"   
## [19] "SJ_02_COMP_DTK_TOT_ORG"        "SJ_02_COMP_DTK_TOT_RLTD"      
## [21] "SJ_02_COMP_DTK_PRIOR_990_ORG"  "SJ_02_COMP_DTK_PRIOR_990_RLTD"
## [23] "SJ_02_COMP_DTK_NAME_ORG_L1"








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/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/BusinessName"

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       °--IRS990ScheduleJ                       
## 4           °--RltdOrgOfficerTrstKeyEmplGrp      
## 5               ¦--BaseCompensationFilingOrgAmt  
## 6               ¦--BonusFilingOrganizationAmount 
## 7               ¦--BonusRelatedOrganizationsAmt  
## 8               ¦--BusinessName                  
## 9               ¦   °--BusinessNameLine1Txt      
## 10              ¦--CompensationBasedOnRltdOrgsAmt
## 11              ¦--CompReportPrior990FilingOrgAmt
## 12              ¦--CompReportPrior990RltdOrgsAmt 
## 13              ¦--DeferredCompensationFlngOrgAmt
## 14              ¦--DeferredCompRltdOrgsAmt       
## 15              ¦--NontaxableBenefitsFilingOrgAmt
## 16              ¦--NontaxableBenefitsRltdOrgsAmt 
## 17              ¦--OtherCompensationFilingOrgAmt 
## 18              ¦--OtherCompensationRltdOrgsAmt  
## 19              ¦--PersonNm                      
## 20              ¦--TitleTxt                      
## 21              ¦--TotalCompensationFilingOrgAmt 
## 22              °--TotalCompensationRltdOrgsAmt
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/IRS990ScheduleJ/Form990ScheduleJPartII/BaseCompensationFilingOrg 1
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/BonusFilingOrg 2
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/BonusRelatedOrgs 3
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/CompBasedOnRelatedOrgs 4
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/CompReportPrior990FilingOrg 5
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/CompReportPrior990RelatedOrgs 6
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/DeferredCompFilingOrg 7
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/DeferredCompRelatedOrgs 8
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/NameBusiness/BusinessNameLine1 9
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/NameBusiness/BusinessNameLine2 10
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/NamePerson 11
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/NontaxableBenefitsFilingOrg 12
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/NontaxableBenefitsRelatedOrgs 13
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/OtherCompensationFilingOrg 14
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/OtherCompensationRelatedOrgs 15
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/Title 16
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/TotalCompensationFilingOrg 17
/Return/ReturnData/IRS990ScheduleJ/Form990ScheduleJPartII/TotalCompensationRelatedOrgs 18
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/BaseCompensationFilingOrgAmt 19
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/BonusFilingOrganizationAmount 20
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/BonusRelatedOrganizationsAmt 21
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/BusinessName/BusinessNameLine1 22
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/BusinessName/BusinessNameLine1Txt 23
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/BusinessName/BusinessNameLine2 24
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/BusinessName/BusinessNameLine2Txt 25
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/CompReportPrior990FilingOrgAmt 26
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/CompReportPrior990RltdOrgsAmt 27
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/CompensationBasedOnRltdOrgsAmt 28
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/DeferredCompRltdOrgsAmt 29
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/DeferredCompensationFlngOrgAmt 30
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/NontaxableBenefitsFilingOrgAmt 31
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/NontaxableBenefitsRltdOrgsAmt 32
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/OtherCompensationFilingOrgAmt 33
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/OtherCompensationRltdOrgsAmt 34
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/PersonNm 35
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/TitleTxt 36
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/TotalCompensationFilingOrgAmt 37
/Return/ReturnData/IRS990ScheduleJ/RltdOrgOfficerTrstKeyEmplGrp/TotalCompensationRltdOrgsAmt 38

Grouping Variables

Identify all unique groups used in xpaths.

if( is.null(table.headers) )
{ find_table_headers( table.name ) } else
table.headers
##  [1] "//Form990ScheduleJPartII/NameBusiness"                        
##  [2] "//Form990ScheduleJPartII/NamePerson"                          
##  [3] "//Form990ScheduleJPartII/Title"                               
##  [4] "//Form990ScheduleJPartII/BaseCompensationFilingOrg"           
##  [5] "//Form990ScheduleJPartII/CompBasedOnRelatedOrgs"              
##  [6] "//Form990ScheduleJPartII/BonusFilingOrg"                      
##  [7] "//Form990ScheduleJPartII/BonusRelatedOrgs"                    
##  [8] "//Form990ScheduleJPartII/OtherCompensationFilingOrg"          
##  [9] "//Form990ScheduleJPartII/OtherCompensationRelatedOrgs"        
## [10] "//Form990ScheduleJPartII/DeferredCompFilingOrg"               
## [11] "//Form990ScheduleJPartII/DeferredCompRelatedOrgs"             
## [12] "//Form990ScheduleJPartII/NontaxableBenefitsFilingOrg"         
## [13] "//Form990ScheduleJPartII/NontaxableBenefitsRelatedOrgs"       
## [14] "//Form990ScheduleJPartII/TotalCompensationFilingOrg"          
## [15] "//Form990ScheduleJPartII/TotalCompensationRelatedOrgs"        
## [16] "//Form990ScheduleJPartII/CompReportPrior990FilingOrg"         
## [17] "//Form990ScheduleJPartII/CompReportPrior990RelatedOrgs"       
## [18] "//RltdOrgOfficerTrstKeyEmplGrp/BusinessName"                  
## [19] "//RltdOrgOfficerTrstKeyEmplGrp/PersonNm"                      
## [20] "//RltdOrgOfficerTrstKeyEmplGrp/TitleTxt"                      
## [21] "//RltdOrgOfficerTrstKeyEmplGrp/BaseCompensationFilingOrgAmt"  
## [22] "//RltdOrgOfficerTrstKeyEmplGrp/CompensationBasedOnRltdOrgsAmt"
## [23] "//RltdOrgOfficerTrstKeyEmplGrp/BonusFilingOrganizationAmount" 
## [24] "//RltdOrgOfficerTrstKeyEmplGrp/BonusRelatedOrganizationsAmt"  
## [25] "//RltdOrgOfficerTrstKeyEmplGrp/OtherCompensationFilingOrgAmt" 
## [26] "//RltdOrgOfficerTrstKeyEmplGrp/OtherCompensationRltdOrgsAmt"  
## [27] "//RltdOrgOfficerTrstKeyEmplGrp/DeferredCompensationFlngOrgAmt"
## [28] "//RltdOrgOfficerTrstKeyEmplGrp/DeferredCompRltdOrgsAmt"       
## [29] "//RltdOrgOfficerTrstKeyEmplGrp/NontaxableBenefitsFilingOrgAmt"
## [30] "//RltdOrgOfficerTrstKeyEmplGrp/NontaxableBenefitsRltdOrgsAmt" 
## [31] "//RltdOrgOfficerTrstKeyEmplGrp/TotalCompensationFilingOrgAmt" 
## [32] "//RltdOrgOfficerTrstKeyEmplGrp/TotalCompensationRltdOrgsAmt"  
## [33] "//RltdOrgOfficerTrstKeyEmplGrp/CompReportPrior990FilingOrgAmt"
## [34] "//RltdOrgOfficerTrstKeyEmplGrp/CompReportPrior990RltdOrgsAmt"

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