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/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressForeign/AddressLine1 1
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressForeign/AddressLine2 2
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressForeign/City 3
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressForeign/Country 4
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressForeign/PostalCode 5
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressForeign/ProvinceOrState 6
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressLine1 7
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressLine2 8
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressUS/AddressLine1 9
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressUS/AddressLine2 10
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressUS/City 11
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressUS/State 12
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressUS/ZIPCode 13
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/City 14
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/State 15
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/ZIPCode 16
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/ChildrensHospital 17
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/CriticalAccessHospital 18
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Er24Hours 19
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/ErOther 20
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/GeneralMedicalAndSurgical 21
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/LicensedHospital 22
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Name/BusinessNameLine1 23
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Name/BusinessNameLine2 24
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Other 25
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/ResearchFacility 26
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/TeachingHospital 27
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Address/AddressLine1 28
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Address/AddressLine2 29
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Address/City 30
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Address/State 31
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Address/ZIPCode 32
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/ChildrensHospital 33
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/CriticalAccessHospital 34
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Er24Hours 35
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/ErOther 36
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/FacilityReportingGroup 37
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/GeneralMedicalAndSurgical 38
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/LicensedHospital 39
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Name/BusinessNameLine1 40
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Name/BusinessNameLine2 41
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Other 42
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/ResearchFacility 43
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/TeachingHospital 44
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/WebsiteAddress 45
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/BusinessName/BusinessNameLine1 46
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/BusinessName/BusinessNameLine1Txt 47
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/BusinessName/BusinessNameLine2 48
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/BusinessName/BusinessNameLine2Txt 49
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/ChildrensHospitalInd 50
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/CriticalAccessHospitalInd 51
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/EmergencyRoom24HrsInd 52
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/EmergencyRoomOtherInd 53
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/FacilityReportingGroupCd 54
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/GeneralMedicalAndSurgicalInd 55
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/LicensedHospitalInd 56
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/OtherDesc 57
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/ResearchFacilityInd 58
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/StateLicenseNum 59
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/SubordinateHospitalEIN 60
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/SubordinateHospitalName/BusinessNameLine1Txt 61
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/SubordinateHospitalName/BusinessNameLine2Txt 62
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/TeachingHospitalInd 63
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/AddressLine1 64
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/AddressLine1Txt 65
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/AddressLine2 66
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/AddressLine2Txt 67
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/City 68
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/CityNm 69
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/State 70
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/StateAbbreviationCd 71
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/ZIPCd 72
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/ZIPCode 73
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/WebsiteAddressTxt 74
xpaths <- as.character( t.xpaths$xpath )
el <- create_edgelist_v1( xpaths )
nd <- FromDataFrameNetwork( network=el )
print( nd )
##                                        levelName
## 1   Return                                      
## 2    °--ReturnData                              
## 3        °--IRS990ScheduleH                     
## 4            ¦--Form990ScheduleHPartV           
## 5            ¦   ¦--Address                     
## 6            ¦   ¦   ¦--AddressForeign          
## 7            ¦   ¦   ¦   ¦--AddressLine1        
## 8            ¦   ¦   ¦   ¦--AddressLine2        
## 9            ¦   ¦   ¦   ¦--City                
## 10           ¦   ¦   ¦   ¦--Country             
## 11           ¦   ¦   ¦   ¦--PostalCode          
## 12           ¦   ¦   ¦   °--ProvinceOrState     
## 13           ¦   ¦   ¦--AddressLine1            
## 14           ¦   ¦   ¦--AddressLine2            
## 15           ¦   ¦   ¦--AddressUS               
## 16           ¦   ¦   ¦   ¦--AddressLine1        
## 17           ¦   ¦   ¦   ¦--AddressLine2        
## 18           ¦   ¦   ¦   ¦--City                
## 19           ¦   ¦   ¦   ¦--State               
## 20           ¦   ¦   ¦   °--ZIPCode             
## 21           ¦   ¦   ¦--City                    
## 22           ¦   ¦   ¦--State                   
## 23           ¦   ¦   °--ZIPCode                 
## 24           ¦   ¦--ChildrensHospital           
## 25           ¦   ¦--CriticalAccessHospital      
## 26           ¦   ¦--Er24Hours                   
## 27           ¦   ¦--ErOther                     
## 28           ¦   ¦--GeneralMedicalAndSurgical   
## 29           ¦   ¦--LicensedHospital            
## 30           ¦   ¦--Name                        
## 31           ¦   ¦   ¦--BusinessNameLine1       
## 32           ¦   ¦   °--BusinessNameLine2       
## 33           ¦   ¦--Other                       
## 34           ¦   ¦--ResearchFacility            
## 35           ¦   °--TeachingHospital            
## 36           ¦--Form990ScheduleHPartVSectionA   
## 37           ¦   ¦--Address                     
## 38           ¦   ¦   ¦--AddressForeign          
## 39           ¦   ¦   ¦   ¦--AddressLine1        
## 40           ¦   ¦   ¦   ¦--AddressLine2        
## 41           ¦   ¦   ¦   ¦--City                
## 42           ¦   ¦   ¦   ¦--Country             
## 43           ¦   ¦   ¦   ¦--PostalCode          
## 44           ¦   ¦   ¦   °--ProvinceOrState     
## 45           ¦   ¦   ¦--AddressLine1            
## 46           ¦   ¦   ¦--AddressLine2            
## 47           ¦   ¦   ¦--AddressUS               
## 48           ¦   ¦   ¦   ¦--AddressLine1        
## 49           ¦   ¦   ¦   ¦--AddressLine2        
## 50           ¦   ¦   ¦   ¦--City                
## 51           ¦   ¦   ¦   ¦--State               
## 52           ¦   ¦   ¦   °--ZIPCode             
## 53           ¦   ¦   ¦--City                    
## 54           ¦   ¦   ¦--State                   
## 55           ¦   ¦   °--ZIPCode                 
## 56           ¦   ¦--ChildrensHospital           
## 57           ¦   ¦--CriticalAccessHospital      
## 58           ¦   ¦--Er24Hours                   
## 59           ¦   ¦--ErOther                     
## 60           ¦   ¦--FacilityReportingGroup      
## 61           ¦   ¦--GeneralMedicalAndSurgical   
## 62           ¦   ¦--LicensedHospital            
## 63           ¦   ¦--Name                        
## 64           ¦   ¦   ¦--BusinessNameLine1       
## 65           ¦   ¦   °--BusinessNameLine2       
## 66           ¦   ¦--Other                       
## 67           ¦   ¦--ResearchFacility            
## 68           ¦   ¦--TeachingHospital            
## 69           ¦   °--WebsiteAddress              
## 70           °--HospitalFacilitiesGrp           
## 71               ¦--BusinessName                
## 72               ¦   ¦--BusinessNameLine1       
## 73               ¦   ¦--BusinessNameLine1Txt    
## 74               ¦   ¦--BusinessNameLine2       
## 75               ¦   °--BusinessNameLine2Txt    
## 76               ¦--ChildrensHospitalInd        
## 77               ¦--CriticalAccessHospitalInd   
## 78               ¦--EmergencyRoom24HrsInd       
## 79               ¦--EmergencyRoomOtherInd       
## 80               ¦--FacilityReportingGroupCd    
## 81               ¦--GeneralMedicalAndSurgicalInd
## 82               ¦--LicensedHospitalInd         
## 83               ¦--OtherDesc                   
## 84               ¦--ResearchFacilityInd         
## 85               ¦--StateLicenseNum             
## 86               ¦--SubordinateHospitalEIN      
## 87               ¦--SubordinateHospitalName     
## 88               ¦   ¦--BusinessNameLine1Txt    
## 89               ¦   °--BusinessNameLine2Txt    
## 90               ¦--TeachingHospitalInd         
## 91               ¦--USAddress                   
## 92               ¦   ¦--AddressLine1            
## 93               ¦   ¦--AddressLine1Txt         
## 94               ¦   ¦--AddressLine2            
## 95               ¦   ¦--AddressLine2Txt         
## 96               ¦   ¦--City                    
## 97               ¦   ¦--CityNm                  
## 98               ¦   ¦--State                   
## 99               ¦   ¦--StateAbbreviationCd     
## 100              ¦   °--... 2 nodes w/ 0 sub    
## 101              °--... 1 nodes w/ 2 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] "//Form990ScheduleHPartV"         "//Form990ScheduleHPartVSectionA"
## [3] "//HospitalFacilitiesGrp"
# new version
find_table_headers( table.name )
##  [1] "//Form990ScheduleHPartV/Address"                          
##  [2] "//Form990ScheduleHPartV/Name"                             
##  [3] "//Form990ScheduleHPartV/LicensedHospital"                 
##  [4] "//Form990ScheduleHPartV/GeneralMedicalAndSurgical"        
##  [5] "//Form990ScheduleHPartV/ChildrensHospital"                
##  [6] "//Form990ScheduleHPartV/TeachingHospital"                 
##  [7] "//Form990ScheduleHPartV/CriticalAccessHospital"           
##  [8] "//Form990ScheduleHPartV/ResearchFacility"                 
##  [9] "//Form990ScheduleHPartV/Er24Hours"                        
## [10] "//Form990ScheduleHPartV/ErOther"                          
## [11] "//Form990ScheduleHPartV/Other"                            
## [12] "//Form990ScheduleHPartVSectionA/Address"                  
## [13] "//Form990ScheduleHPartVSectionA/Name"                     
## [14] "//Form990ScheduleHPartVSectionA/WebsiteAddress"           
## [15] "//Form990ScheduleHPartVSectionA/LicensedHospital"         
## [16] "//Form990ScheduleHPartVSectionA/GeneralMedicalAndSurgical"
## [17] "//Form990ScheduleHPartVSectionA/ChildrensHospital"        
## [18] "//Form990ScheduleHPartVSectionA/TeachingHospital"         
## [19] "//Form990ScheduleHPartVSectionA/CriticalAccessHospital"   
## [20] "//Form990ScheduleHPartVSectionA/ResearchFacility"         
## [21] "//Form990ScheduleHPartVSectionA/Er24Hours"                
## [22] "//Form990ScheduleHPartVSectionA/ErOther"                  
## [23] "//Form990ScheduleHPartVSectionA/Other"                    
## [24] "//Form990ScheduleHPartVSectionA/FacilityReportingGroup"   
## [25] "//Form990ScheduleHPartVSectionA/FacilityNumber"           
## [26] "//HospitalFacilitiesGrp/USAddress"                        
## [27] "//HospitalFacilitiesGrp/BusinessName"                     
## [28] "//HospitalFacilitiesGrp/StateLicenseNum"                  
## [29] "//HospitalFacilitiesGrp/SubordinateHospitalEIN"           
## [30] "//HospitalFacilitiesGrp/SubordinateHospitalName"          
## [31] "//HospitalFacilitiesGrp/WebsiteAddressTxt"                
## [32] "//HospitalFacilitiesGrp/LicensedHospitalInd"              
## [33] "//HospitalFacilitiesGrp/GeneralMedicalAndSurgicalInd"     
## [34] "//HospitalFacilitiesGrp/ChildrensHospitalInd"             
## [35] "//HospitalFacilitiesGrp/TeachingHospitalInd"              
## [36] "//HospitalFacilitiesGrp/CriticalAccessHospitalInd"        
## [37] "//HospitalFacilitiesGrp/ResearchFacilityInd"              
## [38] "//HospitalFacilitiesGrp/EmergencyRoom24HrsInd"            
## [39] "//HospitalFacilitiesGrp/EmergencyRoomOtherInd"            
## [40] "//HospitalFacilitiesGrp/OtherDesc"                        
## [41] "//HospitalFacilitiesGrp/FacilityReportingGroupCd"         
## [42] "//HospitalFacilitiesGrp/FacilityNum"
# 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: SH-P05-T01-HOSPITAL-FACILITY

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

TOTAL RUN TIME:

## Time difference of 37.91935 mins
## Time difference of -0.6319892 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] "FacilityNum"                      "SH_05_HOSPITAL_WEBSITE"          
##  [9] "SH_05_HOSPITAL_STATE_LIC_NUM"     "SH_05_HOSPITAL_LIC_X"            
## [11] "SH_05_HOSPITAL_MEDICAL_X"         "SH_05_HOSPITAL_TEACHING_X"       
## [13] "SH_05_HOSPITAL_ER_24HOURS_X"      "SH_05_HOSPITAL_FACILITY_GROUP"   
## [15] "SH_05_HOSPITAL_NAME_L1"           "SH_05_HOSPITAL_ADDR_L1"          
## [17] "SH_05_HOSPITAL_ADDR_CITY"         "SH_05_HOSPITAL_ADDR_STATE"       
## [19] "SH_05_HOSPITAL_ADDR_ZIP"          "SH_05_HOSPITAL_CHILDREN_X"       
## [21] "SH_05_HOSPITAL_OTH"               "SH_05_HOSPITAL_RSRCH_FACILITY_X" 
## [23] "SH_05_HOSPITAL_CRITICAL_ACCESS_X" "SH_05_HOSPITAL_ADDR_L2"          
## [25] "SH_05_HOSPITAL_ER_OTH_X"          "SH_05_HOSPITAL_SUBORD_EIN"       
## [27] "SH_05_HOSPITAL_NAME_L1.1"         "SH_05_HOSPITAL_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] "/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/BusinessName"           
## [2] "/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/FacilityNum"            
## [3] "/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/SubordinateHospitalName"
## [4] "/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/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       °--IRS990ScheduleH                     
## 4           °--HospitalFacilitiesGrp           
## 5               ¦--BusinessName                
## 6               ¦   ¦--BusinessNameLine1Txt    
## 7               ¦   °--BusinessNameLine2Txt    
## 8               ¦--ChildrensHospitalInd        
## 9               ¦--CriticalAccessHospitalInd   
## 10              ¦--EmergencyRoom24HrsInd       
## 11              ¦--EmergencyRoomOtherInd       
## 12              ¦--FacilityNum                 
## 13              ¦--FacilityReportingGroupCd    
## 14              ¦--GeneralMedicalAndSurgicalInd
## 15              ¦--LicensedHospitalInd         
## 16              ¦--OtherDesc                   
## 17              ¦--ResearchFacilityInd         
## 18              ¦--StateLicenseNum             
## 19              ¦--SubordinateHospitalEIN      
## 20              ¦--SubordinateHospitalName     
## 21              ¦   °--BusinessNameLine1Txt    
## 22              ¦--TeachingHospitalInd         
## 23              ¦--USAddress                   
## 24              ¦   ¦--AddressLine1Txt         
## 25              ¦   ¦--AddressLine2Txt         
## 26              ¦   ¦--CityNm                  
## 27              ¦   ¦--StateAbbreviationCd     
## 28              ¦   °--ZIPCd                   
## 29              °--WebsiteAddressTxt
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/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressForeign/AddressLine1 1
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressForeign/AddressLine2 2
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressForeign/City 3
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressForeign/Country 4
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressForeign/PostalCode 5
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressForeign/ProvinceOrState 6
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressLine1 7
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressLine2 8
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressUS/AddressLine1 9
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressUS/AddressLine2 10
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressUS/City 11
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressUS/State 12
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/AddressUS/ZIPCode 13
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/City 14
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/State 15
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Address/ZIPCode 16
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/ChildrensHospital 17
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/CriticalAccessHospital 18
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Er24Hours 19
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/ErOther 20
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/GeneralMedicalAndSurgical 21
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/LicensedHospital 22
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Name/BusinessNameLine1 23
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Name/BusinessNameLine2 24
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/Other 25
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/ResearchFacility 26
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartV/TeachingHospital 27
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Address/AddressLine1 28
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Address/AddressLine2 29
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Address/City 30
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Address/State 31
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Address/ZIPCode 32
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/ChildrensHospital 33
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/CriticalAccessHospital 34
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Er24Hours 35
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/ErOther 36
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/FacilityReportingGroup 37
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/GeneralMedicalAndSurgical 38
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/LicensedHospital 39
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Name/BusinessNameLine1 40
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Name/BusinessNameLine2 41
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/Other 42
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/ResearchFacility 43
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/TeachingHospital 44
/Return/ReturnData/IRS990ScheduleH/Form990ScheduleHPartVSectionA/WebsiteAddress 45
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/BusinessName/BusinessNameLine1 46
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/BusinessName/BusinessNameLine1Txt 47
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/BusinessName/BusinessNameLine2 48
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/BusinessName/BusinessNameLine2Txt 49
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/ChildrensHospitalInd 50
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/CriticalAccessHospitalInd 51
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/EmergencyRoom24HrsInd 52
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/EmergencyRoomOtherInd 53
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/FacilityReportingGroupCd 54
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/GeneralMedicalAndSurgicalInd 55
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/LicensedHospitalInd 56
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/OtherDesc 57
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/ResearchFacilityInd 58
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/StateLicenseNum 59
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/SubordinateHospitalEIN 60
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/SubordinateHospitalName/BusinessNameLine1Txt 61
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/SubordinateHospitalName/BusinessNameLine2Txt 62
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/TeachingHospitalInd 63
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/AddressLine1 64
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/AddressLine1Txt 65
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/AddressLine2 66
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/AddressLine2Txt 67
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/City 68
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/CityNm 69
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/State 70
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/StateAbbreviationCd 71
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/ZIPCd 72
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/USAddress/ZIPCode 73
/Return/ReturnData/IRS990ScheduleH/HospitalFacilitiesGrp/WebsiteAddressTxt 74

Grouping Variables

Identify all unique groups used in xpaths.

if( is.null(table.headers) )
{ find_table_headers( table.name ) } else
table.headers
##  [1] "//Form990ScheduleHPartV/Address"                          
##  [2] "//Form990ScheduleHPartV/Name"                             
##  [3] "//Form990ScheduleHPartV/LicensedHospital"                 
##  [4] "//Form990ScheduleHPartV/GeneralMedicalAndSurgical"        
##  [5] "//Form990ScheduleHPartV/ChildrensHospital"                
##  [6] "//Form990ScheduleHPartV/TeachingHospital"                 
##  [7] "//Form990ScheduleHPartV/CriticalAccessHospital"           
##  [8] "//Form990ScheduleHPartV/ResearchFacility"                 
##  [9] "//Form990ScheduleHPartV/Er24Hours"                        
## [10] "//Form990ScheduleHPartV/ErOther"                          
## [11] "//Form990ScheduleHPartV/Other"                            
## [12] "//Form990ScheduleHPartVSectionA/Address"                  
## [13] "//Form990ScheduleHPartVSectionA/Name"                     
## [14] "//Form990ScheduleHPartVSectionA/WebsiteAddress"           
## [15] "//Form990ScheduleHPartVSectionA/LicensedHospital"         
## [16] "//Form990ScheduleHPartVSectionA/GeneralMedicalAndSurgical"
## [17] "//Form990ScheduleHPartVSectionA/ChildrensHospital"        
## [18] "//Form990ScheduleHPartVSectionA/TeachingHospital"         
## [19] "//Form990ScheduleHPartVSectionA/CriticalAccessHospital"   
## [20] "//Form990ScheduleHPartVSectionA/ResearchFacility"         
## [21] "//Form990ScheduleHPartVSectionA/Er24Hours"                
## [22] "//Form990ScheduleHPartVSectionA/ErOther"                  
## [23] "//Form990ScheduleHPartVSectionA/Other"                    
## [24] "//Form990ScheduleHPartVSectionA/FacilityReportingGroup"   
## [25] "//Form990ScheduleHPartVSectionA/FacilityNumber"           
## [26] "//HospitalFacilitiesGrp/USAddress"                        
## [27] "//HospitalFacilitiesGrp/BusinessName"                     
## [28] "//HospitalFacilitiesGrp/StateLicenseNum"                  
## [29] "//HospitalFacilitiesGrp/SubordinateHospitalEIN"           
## [30] "//HospitalFacilitiesGrp/SubordinateHospitalName"          
## [31] "//HospitalFacilitiesGrp/WebsiteAddressTxt"                
## [32] "//HospitalFacilitiesGrp/LicensedHospitalInd"              
## [33] "//HospitalFacilitiesGrp/GeneralMedicalAndSurgicalInd"     
## [34] "//HospitalFacilitiesGrp/ChildrensHospitalInd"             
## [35] "//HospitalFacilitiesGrp/TeachingHospitalInd"              
## [36] "//HospitalFacilitiesGrp/CriticalAccessHospitalInd"        
## [37] "//HospitalFacilitiesGrp/ResearchFacilityInd"              
## [38] "//HospitalFacilitiesGrp/EmergencyRoom24HrsInd"            
## [39] "//HospitalFacilitiesGrp/EmergencyRoomOtherInd"            
## [40] "//HospitalFacilitiesGrp/OtherDesc"                        
## [41] "//HospitalFacilitiesGrp/FacilityReportingGroupCd"         
## [42] "//HospitalFacilitiesGrp/FacilityNum"

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