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")
head( index )
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.
%>%
concordance filter( rdb_table == table.name )
xpath | id |
---|---|
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressForeign/AddressLine1 | 1 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressForeign/AddressLine2 | 2 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressForeign/City | 3 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressForeign/Country | 4 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressForeign/PostalCode | 5 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressForeign/ProvinceOrState | 6 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressUS/AddressLine1 | 7 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressUS/AddressLine2 | 8 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressUS/City | 9 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressUS/State | 10 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressUS/ZIPCode | 11 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/ControlledOrg | 12 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/DirectControllingEntity/NameBusiness/BusinessNameLine1 | 13 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/DirectControllingEntity/NameBusiness/BusinessNameLine2 | 14 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/DirectControllingEntity/NotApplicable | 15 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/DirectControllingEntityNA | 16 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/DirectControllingEntityName/BusinessNameLine1 | 17 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/DirectControllingEntityName/BusinessNameLine2 | 18 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/EIN | 19 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/LegalDomicile/ForeignCountry | 20 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/LegalDomicile/State | 21 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/LegalDomicileForeignCountry | 22 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/LegalDomicileState | 23 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/NameOfRelatedOrg/BusinessNameLine1 | 24 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/NameOfRelatedOrg/BusinessNameLine2 | 25 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/PercentageOwnership | 26 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/PrimaryActivity | 27 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/ShareOfEOYAssets | 28 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/ShareOfTotalIncome | 29 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/TypeOfEntity | 30 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ControlledOrganizationInd | 31 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/DirectControllingEntityName/BusinessNameLine1 | 32 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/DirectControllingEntityName/BusinessNameLine1Txt | 33 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/DirectControllingEntityName/BusinessNameLine2 | 34 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/DirectControllingEntityName/BusinessNameLine2Txt | 35 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/DirectControllingNACd | 36 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/EIN | 37 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/EntityTypeTxt | 38 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/AddressLine1 | 39 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/AddressLine1Txt | 40 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/AddressLine2 | 41 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/AddressLine2Txt | 42 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/City | 43 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/CityNm | 44 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/Country | 45 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/CountryCd | 46 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/ForeignPostalCd | 47 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/PostalCode | 48 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/ProvinceOrState | 49 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/ProvinceOrStateNm | 50 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/LegalDomicileForeignCountryCd | 51 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/LegalDomicileStateCd | 52 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/OwnershipPct | 53 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/PrimaryActivitiesTxt | 54 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/RelatedOrganizationName/BusinessNameLine1 | 55 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/RelatedOrganizationName/BusinessNameLine1Txt | 56 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/RelatedOrganizationName/BusinessNameLine2 | 57 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/RelatedOrganizationName/BusinessNameLine2Txt | 58 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ShareOfEOYAssetsAmt | 59 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ShareOfTotalIncomeAmt | 60 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/AddressLine1 | 61 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/AddressLine1Txt | 62 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/AddressLine2 | 63 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/AddressLine2Txt | 64 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/City | 65 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/CityNm | 66 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/State | 67 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/StateAbbreviationCd | 68 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/ZIPCd | 69 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/ZIPCode | 70 |
<- as.character( t.xpaths$xpath )
xpaths <- create_edgelist_v1( xpaths )
el <- FromDataFrameNetwork( network=el )
nd print( nd )
## levelName
## 1 Return
## 2 °--ReturnData
## 3 °--IRS990ScheduleR
## 4 ¦--Form990ScheduleRPartIV
## 5 ¦ ¦--AddressForeign
## 6 ¦ ¦ ¦--AddressLine1
## 7 ¦ ¦ ¦--AddressLine2
## 8 ¦ ¦ ¦--City
## 9 ¦ ¦ ¦--Country
## 10 ¦ ¦ ¦--PostalCode
## 11 ¦ ¦ °--ProvinceOrState
## 12 ¦ ¦--AddressUS
## 13 ¦ ¦ ¦--AddressLine1
## 14 ¦ ¦ ¦--AddressLine2
## 15 ¦ ¦ ¦--City
## 16 ¦ ¦ ¦--State
## 17 ¦ ¦ °--ZIPCode
## 18 ¦ ¦--ControlledOrg
## 19 ¦ ¦--DirectControllingEntity
## 20 ¦ ¦ ¦--NameBusiness
## 21 ¦ ¦ ¦ ¦--BusinessNameLine1
## 22 ¦ ¦ ¦ °--BusinessNameLine2
## 23 ¦ ¦ °--NotApplicable
## 24 ¦ ¦--DirectControllingEntityNA
## 25 ¦ ¦--DirectControllingEntityName
## 26 ¦ ¦ ¦--BusinessNameLine1
## 27 ¦ ¦ ¦--BusinessNameLine2
## 28 ¦ ¦ ¦--BusinessNameLine1Txt
## 29 ¦ ¦ °--BusinessNameLine2Txt
## 30 ¦ ¦--EIN
## 31 ¦ ¦--LegalDomicile
## 32 ¦ ¦ ¦--ForeignCountry
## 33 ¦ ¦ °--State
## 34 ¦ ¦--LegalDomicileForeignCountry
## 35 ¦ ¦--LegalDomicileState
## 36 ¦ ¦--NameOfRelatedOrg
## 37 ¦ ¦ ¦--BusinessNameLine1
## 38 ¦ ¦ °--BusinessNameLine2
## 39 ¦ ¦--PercentageOwnership
## 40 ¦ ¦--PrimaryActivity
## 41 ¦ ¦--ShareOfEOYAssets
## 42 ¦ ¦--ShareOfTotalIncome
## 43 ¦ °--TypeOfEntity
## 44 °--IdRelatedOrgTxblCorpTrGrp
## 45 ¦--ControlledOrganizationInd
## 46 ¦--DirectControllingEntityName
## 47 ¦ ¦--BusinessNameLine1
## 48 ¦ ¦--BusinessNameLine2
## 49 ¦ ¦--BusinessNameLine1Txt
## 50 ¦ °--BusinessNameLine2Txt
## 51 ¦--DirectControllingNACd
## 52 ¦--EIN
## 53 ¦--EntityTypeTxt
## 54 ¦--ForeignAddress
## 55 ¦ ¦--AddressLine1
## 56 ¦ ¦--AddressLine1Txt
## 57 ¦ ¦--AddressLine2
## 58 ¦ ¦--AddressLine2Txt
## 59 ¦ ¦--City
## 60 ¦ ¦--CityNm
## 61 ¦ ¦--Country
## 62 ¦ ¦--CountryCd
## 63 ¦ ¦--ForeignPostalCd
## 64 ¦ ¦--PostalCode
## 65 ¦ ¦--ProvinceOrState
## 66 ¦ °--ProvinceOrStateNm
## 67 ¦--LegalDomicileForeignCountryCd
## 68 ¦--LegalDomicileStateCd
## 69 ¦--OwnershipPct
## 70 ¦--PrimaryActivitiesTxt
## 71 ¦--RelatedOrganizationName
## 72 ¦ ¦--BusinessNameLine1
## 73 ¦ ¦--BusinessNameLine1Txt
## 74 ¦ ¦--BusinessNameLine2
## 75 ¦ °--BusinessNameLine2Txt
## 76 ¦--ShareOfEOYAssetsAmt
## 77 ¦--ShareOfTotalIncomeAmt
## 78 °--USAddress
## 79 ¦--AddressLine1
## 80 ¦--AddressLine1Txt
## 81 ¦--AddressLine2
## 82 ¦--AddressLine2Txt
## 83 ¦--City
## 84 ¦--CityNm
## 85 ¦--State
## 86 ¦--StateAbbreviationCd
## 87 ¦--ZIPCd
## 88 °--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] "//Form990ScheduleRPartIV" "//IdRelatedOrgTxblCorpTrGrp"
# new version
find_table_headers( table.name )
## [1] "//Form990ScheduleRPartIV/AddressForeign"
## [2] "//Form990ScheduleRPartIV/AddressUS"
## [3] "//Form990ScheduleRPartIV/EIN"
## [4] "//Form990ScheduleRPartIV/NameOfRelatedOrg"
## [5] "//Form990ScheduleRPartIV/PrimaryActivity"
## [6] "//Form990ScheduleRPartIV/LegalDomicile"
## [7] "//Form990ScheduleRPartIV/LegalDomicileForeignCountry"
## [8] "//Form990ScheduleRPartIV/LegalDomicileState"
## [9] "//Form990ScheduleRPartIV/DirectControllingEntityNA"
## [10] "//Form990ScheduleRPartIV/DirectControllingEntity"
## [11] "//Form990ScheduleRPartIV/DirectControllingEntityName"
## [12] "//Form990ScheduleRPartIV/TypeOfEntity"
## [13] "//Form990ScheduleRPartIV/ShareOfTotalIncome"
## [14] "//Form990ScheduleRPartIV/ShareOfEOYAssets"
## [15] "//Form990ScheduleRPartIV/PercentageOwnership"
## [16] "//Form990ScheduleRPartIV/ControlledOrg"
## [17] "//IdRelatedOrgTxblCorpTrGrp/ForeignAddress"
## [18] "//IdRelatedOrgTxblCorpTrGrp/USAddress"
## [19] "//IdRelatedOrgTxblCorpTrGrp/EIN"
## [20] "//IdRelatedOrgTxblCorpTrGrp/RelatedOrganizationName"
## [21] "//IdRelatedOrgTxblCorpTrGrp/PrimaryActivitiesTxt"
## [22] "//IdRelatedOrgTxblCorpTrGrp/LegalDomicileForeignCountryCd"
## [23] "//IdRelatedOrgTxblCorpTrGrp/LegalDomicileStateCd"
## [24] "//IdRelatedOrgTxblCorpTrGrp/DirectControllingNACd"
## [25] "//IdRelatedOrgTxblCorpTrGrp/DirectControllingEntityName"
## [26] "//IdRelatedOrgTxblCorpTrGrp/EntityTypeTxt"
## [27] "//IdRelatedOrgTxblCorpTrGrp/ShareOfTotalIncomeAmt"
## [28] "//IdRelatedOrgTxblCorpTrGrp/ShareOfEOYAssetsAmt"
## [29] "//IdRelatedOrgTxblCorpTrGrp/OwnershipPct"
## [30] "//IdRelatedOrgTxblCorpTrGrp/ControlledOrganizationInd"
# manual
if( ! is.null(table.headers) )
{table.headers}
# create new folder
dir.create( folder.name )
setwd( folder.name )
# create sample
set.seed( 1234 )
<- sample_n( index, sample.size )
sample.index write.csv( index, "sample-index.csv", row.names=F )
<- sample.index$URL
sample.urls
# erase existing log files
file.create("XPATH-LOG.txt")
file.create("FAIL-LOG.txt")
<- Sys.time() # --------------------
start.build.time
<- list()
results.list <- list()
xpath.list
for( i in 1:length( sample.urls ) )
{
<- sample.urls[i]
url
<-
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) }
}
<- Sys.time() # --------------------
end.build.time
<- dplyr::bind_rows( results.list )
df
<- readLines( "FAIL-LOG.txt" )
fail.log <- xpath.list %>% unlist() %>% unique() %>% sort()
all.xpaths cat( all.xpaths, sep="\n", file="XPATH-LOG.txt" )
TABLE: SR-P04-T01-ID-RLTD-ORGS-TAXABLE-CORPORATION
## [1] "NUMBER OF RETURNS PROCESSED: 1000"
## [1] "TOTAL NUMBER OF TABLE ROWS: 3158"
TOTAL RUN TIME:
## Time difference of 38.52813 mins
## Time difference of -0.6421354 hours
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] "SR_04_RLTD_ORG_CORP_EIN" "SR_04_RLTD_ORG_CORP_PRIMARY_ACT"
## [9] "SR_04_RLTD_ORG_CORP_DMCL_STATE" "SR_04_RLTD_ORG_CORP_CTRL_NA"
## [11] "SR_04_RLTD_ORG_CORP_CTRL_512_X" "SR_04_RLTD_ORG_CORP_TYPE"
## [13] "SR_04_RLTD_ORG_CORP_TOT_INCOME" "SR_04_RLTD_ORG_CORP_EOY_ASSETS"
## [15] "SR_04_RLTD_ORG_CORP_PCT_OWN" "SR_04_RLTD_ORG_CORP_NAME_L1"
## [17] "SR_04_RLTD_ORG_CORP_ADDR_L1" "SR_04_RLTD_ORG_CORP_ADDR_CITY"
## [19] "SR_04_RLTD_ORG_CORP_ADDR_STATE" "SR_04_RLTD_ORG_CORP_ADDR_ZIP"
## [21] "SR_04_RLTD_ORG_CORP_NAME_L1.1" "SR_04_RLTD_ORG_CORP_DMCL_CNTR"
## [23] "SR_04_RLTD_ORG_CORP_ADDR_CNTR" "SR_04_RLTD_ORG_CORP_NAME_L2"
## [25] "SR_04_RLTD_ORG_CORP_ADDR_L2"
Check for xpaths that were used in the tables but do not exist in the Concordance file.
<- dplyr::filter( concordance, rdb_table == table.name )
c.table <- c.table$xpath
xpath.concordance setdiff( all.xpaths, xpath.concordance )
## [1] ""
## [2] "/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/DirectControllingEntityName"
## [3] "/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress"
## [4] "/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/RelatedOrganizationName"
## [5] "/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress"
Capture to update the Concordance file.
<- setdiff( all.xpaths, xpath.concordance )
these cat( these, sep="\n", file=paste0( folder.name, "/MISSING-XPATHS.txt" ) )
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"
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
<- create_edgelist_v1( all.xpaths ) el
Edgelist format:
V1 | V2 |
---|---|
Return | ReturnData |
ReturnData | IRS990 |
IRS990 | Form990PartVIISectionAGrp |
Form990PartVIISectionAGrp | PersonNm |
Form990PartVIISectionAGrp | TitleTxt |
Form990PartVIISectionAGrp | AverageHoursPerWeekRt |
Form990PartVIISectionAGrp | IndividualTrusteeOrDirectorInd |
Form990PartVIISectionAGrp | OfficerInd |
Form990PartVIISectionAGrp | ReportableCompFromOrgAmt |
Form990PartVIISectionAGrp | ReportableCompFromRltdOrgAmt |
# library( data.tree )
<- FromDataFrameNetwork( network=el )
nd print( nd )
## levelName
## 1 Return
## 2 °--ReturnData
## 3 °--IRS990ScheduleR
## 4 °--IdRelatedOrgTxblCorpTrGrp
## 5 ¦--ControlledOrganizationInd
## 6 ¦--DirectControllingEntityName
## 7 ¦ °--BusinessNameLine1Txt
## 8 ¦--DirectControllingNACd
## 9 ¦--EIN
## 10 ¦--EntityTypeTxt
## 11 ¦--ForeignAddress
## 12 ¦ ¦--AddressLine1Txt
## 13 ¦ ¦--AddressLine2Txt
## 14 ¦ ¦--CityNm
## 15 ¦ ¦--CountryCd
## 16 ¦ ¦--ForeignPostalCd
## 17 ¦ °--ProvinceOrStateNm
## 18 ¦--LegalDomicileForeignCountryCd
## 19 ¦--LegalDomicileStateCd
## 20 ¦--OwnershipPct
## 21 ¦--PrimaryActivitiesTxt
## 22 ¦--RelatedOrganizationName
## 23 ¦ ¦--BusinessNameLine1Txt
## 24 ¦ °--BusinessNameLine2Txt
## 25 ¦--ShareOfEOYAssetsAmt
## 26 ¦--ShareOfTotalIncomeAmt
## 27 °--USAddress
## 28 ¦--AddressLine1Txt
## 29 ¦--AddressLine2Txt
## 30 ¦--CityNm
## 31 ¦--StateAbbreviationCd
## 32 °--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
<- ToListExplicit( nd, unname = TRUE )
radnet radialNetwork( radnet, fontSize = 12 )
<-
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/IRS990ScheduleR/Form990ScheduleRPartIV/AddressForeign/AddressLine1 | 1 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressForeign/AddressLine2 | 2 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressForeign/City | 3 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressForeign/Country | 4 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressForeign/PostalCode | 5 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressForeign/ProvinceOrState | 6 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressUS/AddressLine1 | 7 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressUS/AddressLine2 | 8 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressUS/City | 9 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressUS/State | 10 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/AddressUS/ZIPCode | 11 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/ControlledOrg | 12 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/DirectControllingEntity/NameBusiness/BusinessNameLine1 | 13 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/DirectControllingEntity/NameBusiness/BusinessNameLine2 | 14 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/DirectControllingEntity/NotApplicable | 15 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/DirectControllingEntityNA | 16 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/DirectControllingEntityName/BusinessNameLine1 | 17 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/DirectControllingEntityName/BusinessNameLine2 | 18 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/EIN | 19 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/LegalDomicile/ForeignCountry | 20 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/LegalDomicile/State | 21 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/LegalDomicileForeignCountry | 22 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/LegalDomicileState | 23 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/NameOfRelatedOrg/BusinessNameLine1 | 24 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/NameOfRelatedOrg/BusinessNameLine2 | 25 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/PercentageOwnership | 26 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/PrimaryActivity | 27 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/ShareOfEOYAssets | 28 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/ShareOfTotalIncome | 29 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartIV/TypeOfEntity | 30 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ControlledOrganizationInd | 31 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/DirectControllingEntityName/BusinessNameLine1 | 32 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/DirectControllingEntityName/BusinessNameLine1Txt | 33 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/DirectControllingEntityName/BusinessNameLine2 | 34 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/DirectControllingEntityName/BusinessNameLine2Txt | 35 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/DirectControllingNACd | 36 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/EIN | 37 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/EntityTypeTxt | 38 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/AddressLine1 | 39 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/AddressLine1Txt | 40 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/AddressLine2 | 41 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/AddressLine2Txt | 42 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/City | 43 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/CityNm | 44 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/Country | 45 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/CountryCd | 46 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/ForeignPostalCd | 47 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/PostalCode | 48 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/ProvinceOrState | 49 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ForeignAddress/ProvinceOrStateNm | 50 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/LegalDomicileForeignCountryCd | 51 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/LegalDomicileStateCd | 52 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/OwnershipPct | 53 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/PrimaryActivitiesTxt | 54 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/RelatedOrganizationName/BusinessNameLine1 | 55 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/RelatedOrganizationName/BusinessNameLine1Txt | 56 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/RelatedOrganizationName/BusinessNameLine2 | 57 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/RelatedOrganizationName/BusinessNameLine2Txt | 58 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ShareOfEOYAssetsAmt | 59 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/ShareOfTotalIncomeAmt | 60 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/AddressLine1 | 61 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/AddressLine1Txt | 62 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/AddressLine2 | 63 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/AddressLine2Txt | 64 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/City | 65 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/CityNm | 66 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/State | 67 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/StateAbbreviationCd | 68 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/ZIPCd | 69 |
/Return/ReturnData/IRS990ScheduleR/IdRelatedOrgTxblCorpTrGrp/USAddress/ZIPCode | 70 |
Identify all unique groups used in xpaths.
if( is.null(table.headers) )
find_table_headers( table.name ) } else
{ table.headers
## [1] "//Form990ScheduleRPartIV/AddressForeign"
## [2] "//Form990ScheduleRPartIV/AddressUS"
## [3] "//Form990ScheduleRPartIV/EIN"
## [4] "//Form990ScheduleRPartIV/NameOfRelatedOrg"
## [5] "//Form990ScheduleRPartIV/PrimaryActivity"
## [6] "//Form990ScheduleRPartIV/LegalDomicile"
## [7] "//Form990ScheduleRPartIV/LegalDomicileForeignCountry"
## [8] "//Form990ScheduleRPartIV/LegalDomicileState"
## [9] "//Form990ScheduleRPartIV/DirectControllingEntityNA"
## [10] "//Form990ScheduleRPartIV/DirectControllingEntity"
## [11] "//Form990ScheduleRPartIV/DirectControllingEntityName"
## [12] "//Form990ScheduleRPartIV/TypeOfEntity"
## [13] "//Form990ScheduleRPartIV/ShareOfTotalIncome"
## [14] "//Form990ScheduleRPartIV/ShareOfEOYAssets"
## [15] "//Form990ScheduleRPartIV/PercentageOwnership"
## [16] "//Form990ScheduleRPartIV/ControlledOrg"
## [17] "//IdRelatedOrgTxblCorpTrGrp/ForeignAddress"
## [18] "//IdRelatedOrgTxblCorpTrGrp/USAddress"
## [19] "//IdRelatedOrgTxblCorpTrGrp/EIN"
## [20] "//IdRelatedOrgTxblCorpTrGrp/RelatedOrganizationName"
## [21] "//IdRelatedOrgTxblCorpTrGrp/PrimaryActivitiesTxt"
## [22] "//IdRelatedOrgTxblCorpTrGrp/LegalDomicileForeignCountryCd"
## [23] "//IdRelatedOrgTxblCorpTrGrp/LegalDomicileStateCd"
## [24] "//IdRelatedOrgTxblCorpTrGrp/DirectControllingNACd"
## [25] "//IdRelatedOrgTxblCorpTrGrp/DirectControllingEntityName"
## [26] "//IdRelatedOrgTxblCorpTrGrp/EntityTypeTxt"
## [27] "//IdRelatedOrgTxblCorpTrGrp/ShareOfTotalIncomeAmt"
## [28] "//IdRelatedOrgTxblCorpTrGrp/ShareOfEOYAssetsAmt"
## [29] "//IdRelatedOrgTxblCorpTrGrp/OwnershipPct"
## [30] "//IdRelatedOrgTxblCorpTrGrp/ControlledOrganizationInd"
Groups can then be used to extract the 1:M RDB tables:
if( is.null(table.headers) )
<- find_table_headers( table.name ) }
{ table.headers <- "https://nccs-efile.s3.us-east-1.amazonaws.com/xml/201913079349300206_public.xml"
demo.url <- xml2::read_xml( demo.url )
doc ::xml_ns_strip( doc )
xml2<- get_table_v2( doc, table.name, table.headers )
df.demo df.demo
## NULL
Mapping of xml variable names to concordance variable names:
get_var_map( table.name=table.name )
A table with proper names:
<- get_var_map( table.name=table.name )
v.map
if( ! is.null(df.demo) )
re_name( df.demo, v.map ) %>% as.data.frame()} {
Demo of functions - demo data only.
[[1]]
<Form990PartVIISectionAGrp>
<PersonNm>
{text}
<TitleTxt>
{text}
<AverageHoursPerWeekRt>
{text}
<IndividualTrusteeOrDirectorInd>
{text}
<OfficerInd>
{text}
<ReportableCompFromOrgAmt>
{text}
<ReportableCompFromRltdOrgAmt>
{text}
<OtherCompensationAmt>
{text}
1]] %>% xml_parent() %>% xmltools::xml_view_trees() node.list[[
(1) ------------
+-- Form990PartVIISectionAGrp
+-- PersonNm
+-- TitleTxt
+-- AverageHoursPerWeekRt
+-- IndividualTrusteeOrDirectorInd
+-- OfficerInd
+-- ReportableCompFromOrgAmt
+-- ReportableCompFromRltdOrgAmt
++-- OtherCompensationAmt
(2) ------------
+-- Form990PartVIISectionAGrp
+-- PersonNm
+-- TitleTxt
+-- AverageHoursPerWeekRt
+-- IndividualTrusteeOrDirectorInd
+-- OfficerInd
+-- ReportableCompFromOrgAmt
+-- ReportableCompFromRltdOrgAmt
++-- OtherCompensationAmt