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/IRS990ScheduleK/Form990ScheduleKPartIV/BondReferenceCd 1
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/ExceptionToRebate 2
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/Form8038TFiled 3
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/GrossProceedsInvested 4
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/GrossProceedsInvestedInGIC 5
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/HedgeIdentifiedInBooksAndRecds 6
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/HedgeTerminated 7
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/NameOfGICProvider/BusinessNameLine1 8
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/NameOfGICProvider/BusinessNameLine2 9
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/NameOfHedgeProvider/BusinessNameLine1 10
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/NameOfHedgeProvider/BusinessNameLine2 11
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/NoRebateDue 12
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/RebateNotDueYet 13
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/RegulatorySafeHarborSatisfied 14
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/SuperintegratedHedge 15
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/TermOfGIC 16
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/TermOfHedge 17
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/VariableRateIssue 18
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/WrittenProcToMonitorReqs 19
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/BondReferenceCd 20
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/ExceptionToRebateInd 21
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/Form8038TFiledInd 22
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/GICProviderName/BusinessNameLine1 23
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/GICProviderName/BusinessNameLine1Txt 24
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/GICProviderName/BusinessNameLine2 25
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/GICProviderName/BusinessNameLine2Txt 26
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/GrossProceedsInvestedInGICInd 27
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/GrossProceedsInvestedInd 28
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/HedgeIdentifiedInBksAndRecInd 29
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/HedgeProviderName/BusinessNameLine1 30
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/HedgeProviderName/BusinessNameLine1Txt 31
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/HedgeProviderName/BusinessNameLine2 32
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/HedgeProviderName/BusinessNameLine2Txt 33
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/HedgeTerminatedInd 34
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/NoRebateDueInd 35
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/RebateNotDueYetInd 36
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/RegulatorySafeHarborStsfdInd 37
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/SuperintegratedHedgeInd 38
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/TermOfGICPct 39
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/TermOfHedgePct 40
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/VariableRateIssueInd 41
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/WrittenProcToMonitorReqsInd 42
xpaths <- as.character( t.xpaths$xpath )
el <- create_edgelist_v1( xpaths )
nd <- FromDataFrameNetwork( network=el )
print( nd )
##                                         levelName
## 1  Return                                        
## 2   °--ReturnData                                
## 3       °--IRS990ScheduleK                       
## 4           ¦--Form990ScheduleKPartIV            
## 5           ¦   ¦--BondReferenceCd               
## 6           ¦   ¦--ExceptionToRebate             
## 7           ¦   ¦--Form8038TFiled                
## 8           ¦   ¦--GrossProceedsInvested         
## 9           ¦   ¦--GrossProceedsInvestedInGIC    
## 10          ¦   ¦--HedgeIdentifiedInBooksAndRecds
## 11          ¦   ¦--HedgeTerminated               
## 12          ¦   ¦--NameOfGICProvider             
## 13          ¦   ¦   ¦--BusinessNameLine1         
## 14          ¦   ¦   °--BusinessNameLine2         
## 15          ¦   ¦--NameOfHedgeProvider           
## 16          ¦   ¦   ¦--BusinessNameLine1         
## 17          ¦   ¦   °--BusinessNameLine2         
## 18          ¦   ¦--NoRebateDue                   
## 19          ¦   ¦--RebateNotDueYet               
## 20          ¦   ¦--RegulatorySafeHarborSatisfied 
## 21          ¦   ¦--SuperintegratedHedge          
## 22          ¦   ¦--TermOfGIC                     
## 23          ¦   ¦--TermOfHedge                   
## 24          ¦   ¦--VariableRateIssue             
## 25          ¦   °--WrittenProcToMonitorReqs      
## 26          °--TaxExemptBondsArbitrageGrp        
## 27              ¦--BondReferenceCd               
## 28              ¦--ExceptionToRebateInd          
## 29              ¦--Form8038TFiledInd             
## 30              ¦--GICProviderName               
## 31              ¦   ¦--BusinessNameLine1         
## 32              ¦   ¦--BusinessNameLine1Txt      
## 33              ¦   ¦--BusinessNameLine2         
## 34              ¦   °--BusinessNameLine2Txt      
## 35              ¦--GrossProceedsInvestedInGICInd 
## 36              ¦--GrossProceedsInvestedInd      
## 37              ¦--HedgeIdentifiedInBksAndRecInd 
## 38              ¦--HedgeProviderName             
## 39              ¦   ¦--BusinessNameLine1         
## 40              ¦   ¦--BusinessNameLine1Txt      
## 41              ¦   ¦--BusinessNameLine2         
## 42              ¦   °--BusinessNameLine2Txt      
## 43              ¦--HedgeTerminatedInd            
## 44              ¦--NoRebateDueInd                
## 45              ¦--RebateNotDueYetInd            
## 46              ¦--RegulatorySafeHarborStsfdInd  
## 47              ¦--SuperintegratedHedgeInd       
## 48              ¦--TermOfGICPct                  
## 49              ¦--TermOfHedgePct                
## 50              ¦--VariableRateIssueInd          
## 51              °--WrittenProcToMonitorReqsInd
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] "//Form990ScheduleKPartIV"     "//TaxExemptBondsArbitrageGrp"
# new version
find_table_headers( table.name )
##  [1] "//Form990ScheduleKPartIV/BondReferenceCd"                  
##  [2] "//Form990ScheduleKPartIV/Form8038TFiled"                   
##  [3] "//Form990ScheduleKPartIV/RebateNotDueYet"                  
##  [4] "//Form990ScheduleKPartIV/ExceptionToRebate"                
##  [5] "//Form990ScheduleKPartIV/NoRebateDue"                      
##  [6] "//Form990ScheduleKPartIV/VariableRateIssue"                
##  [7] "//Form990ScheduleKPartIV/HedgeIdentifiedInBooksAndRecds"   
##  [8] "//Form990ScheduleKPartIV/NameOfHedgeProvider"              
##  [9] "//Form990ScheduleKPartIV/TermOfHedge"                      
## [10] "//Form990ScheduleKPartIV/SuperintegratedHedge"             
## [11] "//Form990ScheduleKPartIV/HedgeTerminated"                  
## [12] "//Form990ScheduleKPartIV/GrossProceedsInvestedInGIC"       
## [13] "//Form990ScheduleKPartIV/NameOfGICProvider"                
## [14] "//Form990ScheduleKPartIV/TermOfGIC"                        
## [15] "//Form990ScheduleKPartIV/RegulatorySafeHarborSatisfied"    
## [16] "//Form990ScheduleKPartIV/GrossProceedsInvested"            
## [17] "//Form990ScheduleKPartIV/WrittenProcToMonitorReqs"         
## [18] "//TaxExemptBondsArbitrageGrp/BondReferenceCd"              
## [19] "//TaxExemptBondsArbitrageGrp/Form8038TFiledInd"            
## [20] "//TaxExemptBondsArbitrageGrp/RebateNotDueYetInd"           
## [21] "//TaxExemptBondsArbitrageGrp/ExceptionToRebateInd"         
## [22] "//TaxExemptBondsArbitrageGrp/NoRebateDueInd"               
## [23] "//TaxExemptBondsArbitrageGrp/VariableRateIssueInd"         
## [24] "//TaxExemptBondsArbitrageGrp/HedgeIdentifiedInBksAndRecInd"
## [25] "//TaxExemptBondsArbitrageGrp/HedgeProviderName"            
## [26] "//TaxExemptBondsArbitrageGrp/TermOfHedgePct"               
## [27] "//TaxExemptBondsArbitrageGrp/SuperintegratedHedgeInd"      
## [28] "//TaxExemptBondsArbitrageGrp/HedgeTerminatedInd"           
## [29] "//TaxExemptBondsArbitrageGrp/GrossProceedsInvestedInGICInd"
## [30] "//TaxExemptBondsArbitrageGrp/GICProviderName"              
## [31] "//TaxExemptBondsArbitrageGrp/TermOfGICPct"                 
## [32] "//TaxExemptBondsArbitrageGrp/RegulatorySafeHarborStsfdInd" 
## [33] "//TaxExemptBondsArbitrageGrp/GrossProceedsInvestedInd"     
## [34] "//TaxExemptBondsArbitrageGrp/WrittenProcToMonitorReqsInd"
# 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: SK-P04-T01-BOND-ARBITRAGE

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

TOTAL RUN TIME:

## Time difference of 35.38779 mins
## Time difference of -0.5897964 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] "SK_04_BOND_ISSUE_REFERENCE_NUM"   "SK_04_BOND_ARB_FORM_8038_FILED_X"
##  [9] "SK_04_BOND_ARB_REBATE_NOT_DUE_X"  "SK_04_BOND_ARB_REBATE_EXCEPT_X"  
## [11] "SK_04_BOND_ARB_NO_REBATE_DUE_X"   "SK_04_BOND_ARB_VAR_RATE_ISSUE_X" 
## [13] "SK_04_BOND_ARB_HEDGE_IDENTIFY_X"  "SK_04_BOND_ARB_GIC_INVESTED_X"   
## [15] "SK_04_BOND_ARB_PROCEED_INVEST_X"  "SK_04_BOND_ARB_WRITTEN_PROC_X"   
## [17] "SK_04_BOND_ARB_HEDGE_NAME_L1"     "SK_04_BOND_ARB_HEDGE_NAME_L1.1"  
## [19] "SK_04_BOND_ARB_HEDGE_INTEGRATE_X" "SK_04_BOND_ARB_HEDGE_TERMINATE_X"
## [21] "SK_04_BOND_ARB_HEDGE_TERM"        "SK_04_BOND_ARB_GIC_TERM"         
## [23] "SK_04_BOND_ARB_GIC_SAFE_HARBOR_X" "SK_04_BOND_ARB_HEDGE_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/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/GICProviderName"  
## [3] "/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/HedgeProviderName"

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       °--IRS990ScheduleK                      
## 4           °--TaxExemptBondsArbitrageGrp       
## 5               ¦--BondReferenceCd              
## 6               ¦--ExceptionToRebateInd         
## 7               ¦--Form8038TFiledInd            
## 8               ¦--GICProviderName              
## 9               ¦   ¦--BusinessNameLine1Txt     
## 10              ¦   °--BusinessNameLine2Txt     
## 11              ¦--GrossProceedsInvestedInd     
## 12              ¦--GrossProceedsInvestedInGICInd
## 13              ¦--HedgeIdentifiedInBksAndRecInd
## 14              ¦--HedgeProviderName            
## 15              ¦   ¦--BusinessNameLine1Txt     
## 16              ¦   °--BusinessNameLine2Txt     
## 17              ¦--HedgeTerminatedInd           
## 18              ¦--NoRebateDueInd               
## 19              ¦--RebateNotDueYetInd           
## 20              ¦--RegulatorySafeHarborStsfdInd 
## 21              ¦--SuperintegratedHedgeInd      
## 22              ¦--TermOfGICPct                 
## 23              ¦--TermOfHedgePct               
## 24              ¦--VariableRateIssueInd         
## 25              °--WrittenProcToMonitorReqsInd
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/IRS990ScheduleK/Form990ScheduleKPartIV/BondReferenceCd 1
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/ExceptionToRebate 2
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/Form8038TFiled 3
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/GrossProceedsInvested 4
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/GrossProceedsInvestedInGIC 5
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/HedgeIdentifiedInBooksAndRecds 6
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/HedgeTerminated 7
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/NameOfGICProvider/BusinessNameLine1 8
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/NameOfGICProvider/BusinessNameLine2 9
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/NameOfHedgeProvider/BusinessNameLine1 10
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/NameOfHedgeProvider/BusinessNameLine2 11
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/NoRebateDue 12
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/RebateNotDueYet 13
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/RegulatorySafeHarborSatisfied 14
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/SuperintegratedHedge 15
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/TermOfGIC 16
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/TermOfHedge 17
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/VariableRateIssue 18
/Return/ReturnData/IRS990ScheduleK/Form990ScheduleKPartIV/WrittenProcToMonitorReqs 19
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/BondReferenceCd 20
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/ExceptionToRebateInd 21
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/Form8038TFiledInd 22
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/GICProviderName/BusinessNameLine1 23
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/GICProviderName/BusinessNameLine1Txt 24
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/GICProviderName/BusinessNameLine2 25
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/GICProviderName/BusinessNameLine2Txt 26
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/GrossProceedsInvestedInGICInd 27
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/GrossProceedsInvestedInd 28
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/HedgeIdentifiedInBksAndRecInd 29
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/HedgeProviderName/BusinessNameLine1 30
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/HedgeProviderName/BusinessNameLine1Txt 31
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/HedgeProviderName/BusinessNameLine2 32
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/HedgeProviderName/BusinessNameLine2Txt 33
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/HedgeTerminatedInd 34
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/NoRebateDueInd 35
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/RebateNotDueYetInd 36
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/RegulatorySafeHarborStsfdInd 37
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/SuperintegratedHedgeInd 38
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/TermOfGICPct 39
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/TermOfHedgePct 40
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/VariableRateIssueInd 41
/Return/ReturnData/IRS990ScheduleK/TaxExemptBondsArbitrageGrp/WrittenProcToMonitorReqsInd 42

Grouping Variables

Identify all unique groups used in xpaths.

if( is.null(table.headers) )
{ find_table_headers( table.name ) } else
table.headers
##  [1] "//Form990ScheduleKPartIV/BondReferenceCd"                  
##  [2] "//Form990ScheduleKPartIV/Form8038TFiled"                   
##  [3] "//Form990ScheduleKPartIV/RebateNotDueYet"                  
##  [4] "//Form990ScheduleKPartIV/ExceptionToRebate"                
##  [5] "//Form990ScheduleKPartIV/NoRebateDue"                      
##  [6] "//Form990ScheduleKPartIV/VariableRateIssue"                
##  [7] "//Form990ScheduleKPartIV/HedgeIdentifiedInBooksAndRecds"   
##  [8] "//Form990ScheduleKPartIV/NameOfHedgeProvider"              
##  [9] "//Form990ScheduleKPartIV/TermOfHedge"                      
## [10] "//Form990ScheduleKPartIV/SuperintegratedHedge"             
## [11] "//Form990ScheduleKPartIV/HedgeTerminated"                  
## [12] "//Form990ScheduleKPartIV/GrossProceedsInvestedInGIC"       
## [13] "//Form990ScheduleKPartIV/NameOfGICProvider"                
## [14] "//Form990ScheduleKPartIV/TermOfGIC"                        
## [15] "//Form990ScheduleKPartIV/RegulatorySafeHarborSatisfied"    
## [16] "//Form990ScheduleKPartIV/GrossProceedsInvested"            
## [17] "//Form990ScheduleKPartIV/WrittenProcToMonitorReqs"         
## [18] "//TaxExemptBondsArbitrageGrp/BondReferenceCd"              
## [19] "//TaxExemptBondsArbitrageGrp/Form8038TFiledInd"            
## [20] "//TaxExemptBondsArbitrageGrp/RebateNotDueYetInd"           
## [21] "//TaxExemptBondsArbitrageGrp/ExceptionToRebateInd"         
## [22] "//TaxExemptBondsArbitrageGrp/NoRebateDueInd"               
## [23] "//TaxExemptBondsArbitrageGrp/VariableRateIssueInd"         
## [24] "//TaxExemptBondsArbitrageGrp/HedgeIdentifiedInBksAndRecInd"
## [25] "//TaxExemptBondsArbitrageGrp/HedgeProviderName"            
## [26] "//TaxExemptBondsArbitrageGrp/TermOfHedgePct"               
## [27] "//TaxExemptBondsArbitrageGrp/SuperintegratedHedgeInd"      
## [28] "//TaxExemptBondsArbitrageGrp/HedgeTerminatedInd"           
## [29] "//TaxExemptBondsArbitrageGrp/GrossProceedsInvestedInGICInd"
## [30] "//TaxExemptBondsArbitrageGrp/GICProviderName"              
## [31] "//TaxExemptBondsArbitrageGrp/TermOfGICPct"                 
## [32] "//TaxExemptBondsArbitrageGrp/RegulatorySafeHarborStsfdInd" 
## [33] "//TaxExemptBondsArbitrageGrp/GrossProceedsInvestedInd"     
## [34] "//TaxExemptBondsArbitrageGrp/WrittenProcToMonitorReqsInd"

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