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/Form990ScheduleRPartVI/AddressForeign/AddressLine1 | 1 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressForeign/AddressLine2 | 2 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressForeign/City | 3 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressForeign/Country | 4 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressForeign/PostalCode | 5 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressForeign/ProvinceOrState | 6 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressUS/AddressLine1 | 7 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressUS/AddressLine2 | 8 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressUS/City | 9 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressUS/State | 10 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressUS/ZIPCode | 11 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AllPartnersC3S | 12 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/CodeVAmount | 13 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/DisproportionateAllocations | 14 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/EIN | 15 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/GeneralOrManagingPartner | 16 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/LegalDomicile/ForeignCountry | 17 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/LegalDomicile/State | 18 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/LegalDomicileForeignCountry | 19 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/LegalDomicileState | 20 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/NameOfBusiness/BusinessNameLine1 | 21 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/NameOfBusiness/BusinessNameLine2 | 22 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/PercentageOwnership | 23 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/PredominateIncomeDesc | 24 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/PrimaryActivity | 25 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/ShareOfEOYAssets | 26 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/ShareOfTotalIncome | 27 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/AllPartnersC3SInd | 28 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/BusinessName/BusinessNameLine1 | 29 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/BusinessName/BusinessNameLine1Txt | 30 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/BusinessName/BusinessNameLine2 | 31 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/BusinessName/BusinessNameLine2Txt | 32 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/DisproportionateAllocationsInd | 33 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/EIN | 34 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/AddressLine1 | 35 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/AddressLine1Txt | 36 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/AddressLine2 | 37 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/AddressLine2Txt | 38 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/City | 39 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/CityNm | 40 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/Country | 41 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/CountryCd | 42 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/ForeignPostalCd | 43 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/PostalCode | 44 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/ProvinceOrState | 45 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/ProvinceOrStateNm | 46 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/GeneralOrManagingPartnerInd | 47 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/LegalDomicileForeignCountryCd | 48 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/LegalDomicileStateCd | 49 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/OwnershipPct | 50 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/PredominateIncomeDesc | 51 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/PrimaryActivitiesTxt | 52 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ShareOfEOYAssetsAmt | 53 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ShareOfTotalIncomeAmt | 54 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/UBICodeVAmt | 55 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/AddressLine1 | 56 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/AddressLine1Txt | 57 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/AddressLine2 | 58 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/AddressLine2Txt | 59 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/City | 60 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/CityNm | 61 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/State | 62 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/StateAbbreviationCd | 63 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/ZIPCd | 64 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/ZIPCode | 65 |
<- 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 ¦--Form990ScheduleRPartVI
## 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 ¦ ¦--AllPartnersC3S
## 19 ¦ ¦--CodeVAmount
## 20 ¦ ¦--DisproportionateAllocations
## 21 ¦ ¦--EIN
## 22 ¦ ¦--GeneralOrManagingPartner
## 23 ¦ ¦--LegalDomicile
## 24 ¦ ¦ ¦--ForeignCountry
## 25 ¦ ¦ °--State
## 26 ¦ ¦--LegalDomicileForeignCountry
## 27 ¦ ¦--LegalDomicileState
## 28 ¦ ¦--NameOfBusiness
## 29 ¦ ¦ ¦--BusinessNameLine1
## 30 ¦ ¦ °--BusinessNameLine2
## 31 ¦ ¦--PercentageOwnership
## 32 ¦ ¦--PredominateIncomeDesc
## 33 ¦ ¦--PrimaryActivity
## 34 ¦ ¦--ShareOfEOYAssets
## 35 ¦ °--ShareOfTotalIncome
## 36 °--UnrelatedOrgTxblPartnershipGrp
## 37 ¦--AllPartnersC3SInd
## 38 ¦--BusinessName
## 39 ¦ ¦--BusinessNameLine1
## 40 ¦ ¦--BusinessNameLine1Txt
## 41 ¦ ¦--BusinessNameLine2
## 42 ¦ °--BusinessNameLine2Txt
## 43 ¦--DisproportionateAllocationsInd
## 44 ¦--EIN
## 45 ¦--ForeignAddress
## 46 ¦ ¦--AddressLine1
## 47 ¦ ¦--AddressLine1Txt
## 48 ¦ ¦--AddressLine2
## 49 ¦ ¦--AddressLine2Txt
## 50 ¦ ¦--City
## 51 ¦ ¦--CityNm
## 52 ¦ ¦--Country
## 53 ¦ ¦--CountryCd
## 54 ¦ ¦--ForeignPostalCd
## 55 ¦ ¦--PostalCode
## 56 ¦ ¦--ProvinceOrState
## 57 ¦ °--ProvinceOrStateNm
## 58 ¦--GeneralOrManagingPartnerInd
## 59 ¦--LegalDomicileForeignCountryCd
## 60 ¦--LegalDomicileStateCd
## 61 ¦--OwnershipPct
## 62 ¦--PredominateIncomeDesc
## 63 ¦--PrimaryActivitiesTxt
## 64 ¦--ShareOfEOYAssetsAmt
## 65 ¦--ShareOfTotalIncomeAmt
## 66 ¦--UBICodeVAmt
## 67 °--USAddress
## 68 ¦--AddressLine1
## 69 ¦--AddressLine1Txt
## 70 ¦--AddressLine2
## 71 ¦--AddressLine2Txt
## 72 ¦--City
## 73 ¦--CityNm
## 74 ¦--State
## 75 ¦--StateAbbreviationCd
## 76 ¦--ZIPCd
## 77 °--ZIPCode
SetGraphStyle( nd, rankdir = "LR")
SetEdgeStyle( nd, arrowhead = "vee", color = "grey20", penwidth = 2 )
SetNodeStyle( nd,
style = "filled,rounded",
shape = "box",
fillcolor = "LightBlue",
fontname = "helvetica",
fontcolor="black",
tooltip = GetDefaultTooltip )
# SetNodeStyle(acme$IT, fillcolor = "LightBlue", penwidth = "5px")
plot( nd )
# old version
find_group_names( table.name )
## [1] "//Form990ScheduleRPartVI" "//UnrelatedOrgTxblPartnershipGrp"
# new version
find_table_headers( table.name )
## [1] "//Form990ScheduleRPartVI/AddressForeign"
## [2] "//Form990ScheduleRPartVI/AddressUS"
## [3] "//Form990ScheduleRPartVI/EIN"
## [4] "//Form990ScheduleRPartVI/NameOfBusiness"
## [5] "//Form990ScheduleRPartVI/PrimaryActivity"
## [6] "//Form990ScheduleRPartVI/LegalDomicile"
## [7] "//Form990ScheduleRPartVI/LegalDomicileForeignCountry"
## [8] "//Form990ScheduleRPartVI/LegalDomicileState"
## [9] "//Form990ScheduleRPartVI/PredominateIncomeDesc"
## [10] "//Form990ScheduleRPartVI/AllPartnersC3S"
## [11] "//Form990ScheduleRPartVI/ShareOfTotalIncome"
## [12] "//Form990ScheduleRPartVI/ShareOfEOYAssets"
## [13] "//Form990ScheduleRPartVI/DisproportionateAllocations"
## [14] "//Form990ScheduleRPartVI/CodeVAmount"
## [15] "//Form990ScheduleRPartVI/GeneralOrManagingPartner"
## [16] "//Form990ScheduleRPartVI/PercentageOwnership"
## [17] "//UnrelatedOrgTxblPartnershipGrp/ForeignAddress"
## [18] "//UnrelatedOrgTxblPartnershipGrp/USAddress"
## [19] "//UnrelatedOrgTxblPartnershipGrp/EIN"
## [20] "//UnrelatedOrgTxblPartnershipGrp/BusinessName"
## [21] "//UnrelatedOrgTxblPartnershipGrp/PrimaryActivitiesTxt"
## [22] "//UnrelatedOrgTxblPartnershipGrp/LegalDomicileForeignCountryCd"
## [23] "//UnrelatedOrgTxblPartnershipGrp/LegalDomicileStateCd"
## [24] "//UnrelatedOrgTxblPartnershipGrp/PredominateIncomeDesc"
## [25] "//UnrelatedOrgTxblPartnershipGrp/AllPartnersC3SInd"
## [26] "//UnrelatedOrgTxblPartnershipGrp/ShareOfTotalIncomeAmt"
## [27] "//UnrelatedOrgTxblPartnershipGrp/ShareOfEOYAssetsAmt"
## [28] "//UnrelatedOrgTxblPartnershipGrp/DisproportionateAllocationsInd"
## [29] "//UnrelatedOrgTxblPartnershipGrp/UBICodeVAmt"
## [30] "//UnrelatedOrgTxblPartnershipGrp/GeneralOrManagingPartnerInd"
## [31] "//UnrelatedOrgTxblPartnershipGrp/OwnershipPct"
# manual
if( ! is.null(table.headers) )
{table.headers}
## [1] "//IRS990ScheduleR/Form990ScheduleRPartVI"
## [2] "//IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp"
# 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-P06-T01-UNRLTD-ORGS-TAXABLE-PARTNERSHIP
## [1] "NUMBER OF RETURNS PROCESSED: 1000"
## [1] "TOTAL NUMBER OF TABLE ROWS: 13"
TOTAL RUN TIME:
## Time difference of 13.12158 mins
## Time difference of -0.2186931 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_06_UNRLTD_ORG_PTR_EIN" "SR_06_UNRLTD_ORG_PTR_PRIMARY_ACT"
## [9] "SR_06_UNRLTD_ORG_PTR_DMCL_STATE" "SR_06_UNRLTD_ORG_PTR_PREDMNT"
## [11] "SR_06_UNRLTD_ORG_PTR_501C3_X" "SR_06_UNRLTD_ORG_PTR_ALLOC_X"
## [13] "SR_06_UNRLTD_ORG_PTR_GENERAL_X" "SR_06_UNRLTD_ORG_PTR_PCT_OWN"
## [15] "SR_06_UNRLTD_ORG_PTR_NAME_L1" "SR_06_UNRLTD_ORG_PTR_ADDR_L1"
## [17] "SR_06_UNRLTD_ORG_PTR_ADDR_CITY" "SR_06_UNRLTD_ORG_PTR_ADDR_STATE"
## [19] "SR_06_UNRLTD_ORG_PTR_ADDR_ZIP" "SR_06_UNRLTD_ORG_PTR_TOT_INCOME"
## [21] "SR_06_UNRLTD_ORG_PTR_EOY_ASSETS" "SR_06_UNRLTD_ORG_PTR_CODE_V_AMT"
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/UnrelatedOrgTxblPartnershipGrp"
## [3] "/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/BusinessName"
## [4] "/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/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 °--UnrelatedOrgTxblPartnershipGrp
## 5 ¦--AllPartnersC3SInd
## 6 ¦--BusinessName
## 7 ¦ °--BusinessNameLine1Txt
## 8 ¦--DisproportionateAllocationsInd
## 9 ¦--EIN
## 10 ¦--GeneralOrManagingPartnerInd
## 11 ¦--LegalDomicileStateCd
## 12 ¦--OwnershipPct
## 13 ¦--PredominateIncomeDesc
## 14 ¦--PrimaryActivitiesTxt
## 15 ¦--ShareOfEOYAssetsAmt
## 16 ¦--ShareOfTotalIncomeAmt
## 17 ¦--UBICodeVAmt
## 18 °--USAddress
## 19 ¦--AddressLine1Txt
## 20 ¦--CityNm
## 21 ¦--StateAbbreviationCd
## 22 °--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/Form990ScheduleRPartVI/AddressForeign/AddressLine1 | 1 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressForeign/AddressLine2 | 2 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressForeign/City | 3 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressForeign/Country | 4 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressForeign/PostalCode | 5 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressForeign/ProvinceOrState | 6 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressUS/AddressLine1 | 7 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressUS/AddressLine2 | 8 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressUS/City | 9 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressUS/State | 10 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AddressUS/ZIPCode | 11 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/AllPartnersC3S | 12 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/CodeVAmount | 13 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/DisproportionateAllocations | 14 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/EIN | 15 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/GeneralOrManagingPartner | 16 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/LegalDomicile/ForeignCountry | 17 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/LegalDomicile/State | 18 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/LegalDomicileForeignCountry | 19 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/LegalDomicileState | 20 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/NameOfBusiness/BusinessNameLine1 | 21 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/NameOfBusiness/BusinessNameLine2 | 22 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/PercentageOwnership | 23 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/PredominateIncomeDesc | 24 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/PrimaryActivity | 25 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/ShareOfEOYAssets | 26 |
/Return/ReturnData/IRS990ScheduleR/Form990ScheduleRPartVI/ShareOfTotalIncome | 27 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/AllPartnersC3SInd | 28 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/BusinessName/BusinessNameLine1 | 29 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/BusinessName/BusinessNameLine1Txt | 30 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/BusinessName/BusinessNameLine2 | 31 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/BusinessName/BusinessNameLine2Txt | 32 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/DisproportionateAllocationsInd | 33 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/EIN | 34 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/AddressLine1 | 35 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/AddressLine1Txt | 36 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/AddressLine2 | 37 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/AddressLine2Txt | 38 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/City | 39 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/CityNm | 40 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/Country | 41 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/CountryCd | 42 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/ForeignPostalCd | 43 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/PostalCode | 44 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/ProvinceOrState | 45 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ForeignAddress/ProvinceOrStateNm | 46 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/GeneralOrManagingPartnerInd | 47 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/LegalDomicileForeignCountryCd | 48 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/LegalDomicileStateCd | 49 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/OwnershipPct | 50 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/PredominateIncomeDesc | 51 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/PrimaryActivitiesTxt | 52 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ShareOfEOYAssetsAmt | 53 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/ShareOfTotalIncomeAmt | 54 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/UBICodeVAmt | 55 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/AddressLine1 | 56 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/AddressLine1Txt | 57 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/AddressLine2 | 58 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/AddressLine2Txt | 59 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/City | 60 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/CityNm | 61 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/State | 62 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/StateAbbreviationCd | 63 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/ZIPCd | 64 |
/Return/ReturnData/IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp/USAddress/ZIPCode | 65 |
Identify all unique groups used in xpaths.
if( is.null(table.headers) )
find_table_headers( table.name ) } else
{ table.headers
## [1] "//IRS990ScheduleR/Form990ScheduleRPartVI"
## [2] "//IRS990ScheduleR/UnrelatedOrgTxblPartnershipGrp"
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