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/IRS990ScheduleG/Form990ScheduleGPartI/FundraiserActivityInformation/Activity | 1 |
/Return/ReturnData/IRS990ScheduleG/Form990ScheduleGPartI/FundraiserActivityInformation/AmountRetainedByContractor | 2 |
/Return/ReturnData/IRS990ScheduleG/Form990ScheduleGPartI/FundraiserActivityInformation/FundraiserControlOfFunds | 3 |
/Return/ReturnData/IRS990ScheduleG/Form990ScheduleGPartI/FundraiserActivityInformation/GrossReceipts | 4 |
/Return/ReturnData/IRS990ScheduleG/Form990ScheduleGPartI/FundraiserActivityInformation/NameOfIndividualOrOrganization/BusinessName/BusinessNameLine1 | 5 |
/Return/ReturnData/IRS990ScheduleG/Form990ScheduleGPartI/FundraiserActivityInformation/NameOfIndividualOrOrganization/BusinessName/BusinessNameLine2 | 6 |
/Return/ReturnData/IRS990ScheduleG/Form990ScheduleGPartI/FundraiserActivityInformation/NameOfIndividualOrOrganization/PersonName | 7 |
/Return/ReturnData/IRS990ScheduleG/Form990ScheduleGPartI/FundraiserActivityInformation/NetToOrganization | 8 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ActivityTxt | 9 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/AddressLine1 | 10 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/AddressLine1Txt | 11 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/AddressLine2 | 12 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/AddressLine2Txt | 13 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/City | 14 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/CityNm | 15 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/Country | 16 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/CountryCd | 17 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/ForeignPostalCd | 18 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/PostalCode | 19 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/ProvinceOrState | 20 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/ProvinceOrStateNm | 21 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/FundraiserControlOfFundsInd | 22 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/GrossReceiptsAmt | 23 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/NetToOrganizationAmt | 24 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/OrganizationBusinessName/BusinessNameLine1 | 25 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/OrganizationBusinessName/BusinessNameLine1Txt | 26 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/OrganizationBusinessName/BusinessNameLine2 | 27 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/OrganizationBusinessName/BusinessNameLine2Txt | 28 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/PersonNm | 29 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/RetainedByContractorAmt | 30 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/AddressLine1 | 31 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/AddressLine1Txt | 32 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/AddressLine2 | 33 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/AddressLine2Txt | 34 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/City | 35 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/CityNm | 36 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/State | 37 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/StateAbbreviationCd | 38 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/ZIPCd | 39 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/ZIPCode | 40 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/Activity | 41 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressForeign/AddressLine1 | 42 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressForeign/AddressLine2 | 43 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressForeign/City | 44 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressForeign/Country | 45 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressForeign/PostalCode | 46 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressForeign/ProvinceOrState | 47 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressUS/AddressLine1 | 48 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressUS/AddressLine2 | 49 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressUS/City | 50 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressUS/State | 51 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressUS/ZIPCode | 52 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AmountRetainedByContractor | 53 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/FundraiserControlOfFunds | 54 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/GrossReceipts | 55 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/NameOfIndividual | 56 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/NameOfOrganization/BusinessNameLine1 | 57 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/NameOfOrganization/BusinessNameLine2 | 58 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/NetToOrganization | 59 |
<- as.character( t.xpaths$xpath )
xpaths <- create_edgelist_v1( xpaths )
el <- FromDataFrameNetwork( network=el )
nd print( nd )
## levelName
## 1 Return
## 2 °--ReturnData
## 3 °--IRS990ScheduleG
## 4 ¦--Form990ScheduleGPartI
## 5 ¦ °--FundraiserActivityInformation
## 6 ¦ ¦--Activity
## 7 ¦ ¦--AmountRetainedByContractor
## 8 ¦ ¦--FundraiserControlOfFunds
## 9 ¦ ¦--GrossReceipts
## 10 ¦ ¦--NameOfIndividualOrOrganization
## 11 ¦ ¦ ¦--BusinessName
## 12 ¦ ¦ ¦ ¦--BusinessNameLine1
## 13 ¦ ¦ ¦ °--BusinessNameLine2
## 14 ¦ ¦ °--PersonName
## 15 ¦ ¦--NetToOrganization
## 16 ¦ ¦--AddressForeign
## 17 ¦ ¦ ¦--AddressLine1
## 18 ¦ ¦ ¦--AddressLine2
## 19 ¦ ¦ ¦--City
## 20 ¦ ¦ ¦--Country
## 21 ¦ ¦ ¦--PostalCode
## 22 ¦ ¦ °--ProvinceOrState
## 23 ¦ ¦--AddressUS
## 24 ¦ ¦ ¦--AddressLine1
## 25 ¦ ¦ ¦--AddressLine2
## 26 ¦ ¦ ¦--City
## 27 ¦ ¦ ¦--State
## 28 ¦ ¦ °--ZIPCode
## 29 ¦ ¦--NameOfIndividual
## 30 ¦ °--NameOfOrganization
## 31 ¦ ¦--BusinessNameLine1
## 32 ¦ °--BusinessNameLine2
## 33 ¦--FundraiserActivityInfoGrp
## 34 ¦ ¦--ActivityTxt
## 35 ¦ ¦--ForeignAddress
## 36 ¦ ¦ ¦--AddressLine1
## 37 ¦ ¦ ¦--AddressLine1Txt
## 38 ¦ ¦ ¦--AddressLine2
## 39 ¦ ¦ ¦--AddressLine2Txt
## 40 ¦ ¦ ¦--City
## 41 ¦ ¦ ¦--CityNm
## 42 ¦ ¦ ¦--Country
## 43 ¦ ¦ ¦--CountryCd
## 44 ¦ ¦ ¦--ForeignPostalCd
## 45 ¦ ¦ ¦--PostalCode
## 46 ¦ ¦ ¦--ProvinceOrState
## 47 ¦ ¦ °--ProvinceOrStateNm
## 48 ¦ ¦--FundraiserControlOfFundsInd
## 49 ¦ ¦--GrossReceiptsAmt
## 50 ¦ ¦--NetToOrganizationAmt
## 51 ¦ ¦--OrganizationBusinessName
## 52 ¦ ¦ ¦--BusinessNameLine1
## 53 ¦ ¦ ¦--BusinessNameLine1Txt
## 54 ¦ ¦ ¦--BusinessNameLine2
## 55 ¦ ¦ °--BusinessNameLine2Txt
## 56 ¦ ¦--PersonNm
## 57 ¦ ¦--RetainedByContractorAmt
## 58 ¦ °--USAddress
## 59 ¦ ¦--AddressLine1
## 60 ¦ ¦--AddressLine1Txt
## 61 ¦ ¦--AddressLine2
## 62 ¦ ¦--AddressLine2Txt
## 63 ¦ ¦--City
## 64 ¦ ¦--CityNm
## 65 ¦ ¦--State
## 66 ¦ ¦--StateAbbreviationCd
## 67 ¦ ¦--ZIPCd
## 68 ¦ °--ZIPCode
## 69 °--FundraiserActivityInformation
## 70 ¦--Activity
## 71 ¦--AmountRetainedByContractor
## 72 ¦--FundraiserControlOfFunds
## 73 ¦--GrossReceipts
## 74 ¦--NameOfIndividualOrOrganization
## 75 ¦ ¦--BusinessName
## 76 ¦ ¦ ¦--BusinessNameLine1
## 77 ¦ ¦ °--BusinessNameLine2
## 78 ¦ °--PersonName
## 79 ¦--NetToOrganization
## 80 ¦--AddressForeign
## 81 ¦ ¦--AddressLine1
## 82 ¦ ¦--AddressLine2
## 83 ¦ ¦--City
## 84 ¦ ¦--Country
## 85 ¦ ¦--PostalCode
## 86 ¦ °--ProvinceOrState
## 87 ¦--AddressUS
## 88 ¦ ¦--AddressLine1
## 89 ¦ ¦--AddressLine2
## 90 ¦ ¦--City
## 91 ¦ ¦--State
## 92 ¦ °--ZIPCode
## 93 ¦--NameOfIndividual
## 94 °--NameOfOrganization
## 95 ¦--BusinessNameLine1
## 96 °--BusinessNameLine2
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] "//FundraiserActivityInformation" "//FundraiserActivityInfoGrp"
## [3] "//Form990ScheduleGPartI"
# new version
find_table_headers( table.name )
## [1] "//FundraiserActivityInformation/FundraiserActivityInformation"
## [2] "//FundraiserActivityInformation/Form990ScheduleGPartI"
## [3] "//FundraiserActivityInfoGrp/ForeignAddress"
## [4] "//FundraiserActivityInfoGrp/USAddress"
## [5] "//FundraiserActivityInfoGrp/PersonNm"
## [6] "//FundraiserActivityInfoGrp/OrganizationBusinessName"
## [7] "//FundraiserActivityInfoGrp/ActivityTxt"
## [8] "//FundraiserActivityInfoGrp/FundraiserControlOfFundsInd"
## [9] "//FundraiserActivityInfoGrp/GrossReceiptsAmt"
## [10] "//FundraiserActivityInfoGrp/RetainedByContractorAmt"
## [11] "//FundraiserActivityInfoGrp/NetToOrganizationAmt"
## [12] "//Form990ScheduleGPartI/MailSolicitations"
## [13] "//Form990ScheduleGPartI/EmailSolicitations"
## [14] "//Form990ScheduleGPartI/PhoneSolicitations"
## [15] "//Form990ScheduleGPartI/InPersonSolicitations"
## [16] "//Form990ScheduleGPartI/SolicitationOfNonGovtGrants"
## [17] "//Form990ScheduleGPartI/SolicitationOfGovtGrants"
## [18] "//Form990ScheduleGPartI/SpecialFundraisingEvents"
## [19] "//Form990ScheduleGPartI/AgreementRefFundraising"
## [20] "//Form990ScheduleGPartI/FundraiserActivityInformation"
## [21] "//Form990ScheduleGPartI/TotalGrossReceipts"
## [22] "//Form990ScheduleGPartI/TotalNetToOrganization"
## [23] "//Form990ScheduleGPartI/TotalRetainedByContractors"
## [24] "//Form990ScheduleGPartI/LicensedStates"
# 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: SG-P01-T01-FUNDRAISERS-INFO
## [1] "NUMBER OF RETURNS PROCESSED: 1000"
## [1] "TOTAL NUMBER OF TABLE ROWS: 106"
TOTAL RUN TIME:
## Time difference of 14.60528 mins
## Time difference of -0.2434214 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] "SG_01_FUNDRAISER_ACT" "SG_01_FUNDRAISER_CTRL_FUND_X"
## [9] "SG_01_FUNDRAISER_ACT_GRORCPT" "SG_01_FUNDRAISER_AMT_PAID"
## [11] "SG_01_FUNDRAISER_AMT_ORG" "SG_01_FUNDRAISER_NAME_ORG_L1"
## [13] "SG_01_FUNDRAISER_ADDR_L1" "SG_01_FUNDRAISER_ADDR_CITY"
## [15] "SG_01_FUNDRAISER_ADDR_STATE" "SG_01_FUNDRAISER_ADDR_ZIP"
## [17] "SG_01_FUNDRAISER_NAME_INDIV" "SG_01_FUNDRAISER_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/IRS990ScheduleG/FundraiserActivityInfoGrp/OrganizationBusinessName"
## [3] "/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/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 °--IRS990ScheduleG
## 4 °--FundraiserActivityInfoGrp
## 5 ¦--ActivityTxt
## 6 ¦--FundraiserControlOfFundsInd
## 7 ¦--GrossReceiptsAmt
## 8 ¦--NetToOrganizationAmt
## 9 ¦--OrganizationBusinessName
## 10 ¦ °--BusinessNameLine1Txt
## 11 ¦--PersonNm
## 12 ¦--RetainedByContractorAmt
## 13 °--USAddress
## 14 ¦--AddressLine1Txt
## 15 ¦--AddressLine2Txt
## 16 ¦--CityNm
## 17 ¦--StateAbbreviationCd
## 18 °--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/IRS990ScheduleG/Form990ScheduleGPartI/FundraiserActivityInformation/Activity | 1 |
/Return/ReturnData/IRS990ScheduleG/Form990ScheduleGPartI/FundraiserActivityInformation/AmountRetainedByContractor | 2 |
/Return/ReturnData/IRS990ScheduleG/Form990ScheduleGPartI/FundraiserActivityInformation/FundraiserControlOfFunds | 3 |
/Return/ReturnData/IRS990ScheduleG/Form990ScheduleGPartI/FundraiserActivityInformation/GrossReceipts | 4 |
/Return/ReturnData/IRS990ScheduleG/Form990ScheduleGPartI/FundraiserActivityInformation/NameOfIndividualOrOrganization/BusinessName/BusinessNameLine1 | 5 |
/Return/ReturnData/IRS990ScheduleG/Form990ScheduleGPartI/FundraiserActivityInformation/NameOfIndividualOrOrganization/BusinessName/BusinessNameLine2 | 6 |
/Return/ReturnData/IRS990ScheduleG/Form990ScheduleGPartI/FundraiserActivityInformation/NameOfIndividualOrOrganization/PersonName | 7 |
/Return/ReturnData/IRS990ScheduleG/Form990ScheduleGPartI/FundraiserActivityInformation/NetToOrganization | 8 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ActivityTxt | 9 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/AddressLine1 | 10 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/AddressLine1Txt | 11 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/AddressLine2 | 12 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/AddressLine2Txt | 13 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/City | 14 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/CityNm | 15 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/Country | 16 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/CountryCd | 17 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/ForeignPostalCd | 18 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/PostalCode | 19 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/ProvinceOrState | 20 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/ForeignAddress/ProvinceOrStateNm | 21 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/FundraiserControlOfFundsInd | 22 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/GrossReceiptsAmt | 23 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/NetToOrganizationAmt | 24 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/OrganizationBusinessName/BusinessNameLine1 | 25 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/OrganizationBusinessName/BusinessNameLine1Txt | 26 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/OrganizationBusinessName/BusinessNameLine2 | 27 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/OrganizationBusinessName/BusinessNameLine2Txt | 28 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/PersonNm | 29 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/RetainedByContractorAmt | 30 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/AddressLine1 | 31 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/AddressLine1Txt | 32 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/AddressLine2 | 33 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/AddressLine2Txt | 34 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/City | 35 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/CityNm | 36 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/State | 37 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/StateAbbreviationCd | 38 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/ZIPCd | 39 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInfoGrp/USAddress/ZIPCode | 40 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/Activity | 41 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressForeign/AddressLine1 | 42 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressForeign/AddressLine2 | 43 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressForeign/City | 44 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressForeign/Country | 45 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressForeign/PostalCode | 46 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressForeign/ProvinceOrState | 47 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressUS/AddressLine1 | 48 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressUS/AddressLine2 | 49 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressUS/City | 50 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressUS/State | 51 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AddressUS/ZIPCode | 52 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/AmountRetainedByContractor | 53 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/FundraiserControlOfFunds | 54 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/GrossReceipts | 55 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/NameOfIndividual | 56 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/NameOfOrganization/BusinessNameLine1 | 57 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/NameOfOrganization/BusinessNameLine2 | 58 |
/Return/ReturnData/IRS990ScheduleG/FundraiserActivityInformation/NetToOrganization | 59 |
Identify all unique groups used in xpaths.
if( is.null(table.headers) )
find_table_headers( table.name ) } else
{ table.headers
## [1] "//FundraiserActivityInformation/FundraiserActivityInformation"
## [2] "//FundraiserActivityInformation/Form990ScheduleGPartI"
## [3] "//FundraiserActivityInfoGrp/ForeignAddress"
## [4] "//FundraiserActivityInfoGrp/USAddress"
## [5] "//FundraiserActivityInfoGrp/PersonNm"
## [6] "//FundraiserActivityInfoGrp/OrganizationBusinessName"
## [7] "//FundraiserActivityInfoGrp/ActivityTxt"
## [8] "//FundraiserActivityInfoGrp/FundraiserControlOfFundsInd"
## [9] "//FundraiserActivityInfoGrp/GrossReceiptsAmt"
## [10] "//FundraiserActivityInfoGrp/RetainedByContractorAmt"
## [11] "//FundraiserActivityInfoGrp/NetToOrganizationAmt"
## [12] "//Form990ScheduleGPartI/MailSolicitations"
## [13] "//Form990ScheduleGPartI/EmailSolicitations"
## [14] "//Form990ScheduleGPartI/PhoneSolicitations"
## [15] "//Form990ScheduleGPartI/InPersonSolicitations"
## [16] "//Form990ScheduleGPartI/SolicitationOfNonGovtGrants"
## [17] "//Form990ScheduleGPartI/SolicitationOfGovtGrants"
## [18] "//Form990ScheduleGPartI/SpecialFundraisingEvents"
## [19] "//Form990ScheduleGPartI/AgreementRefFundraising"
## [20] "//Form990ScheduleGPartI/FundraiserActivityInformation"
## [21] "//Form990ScheduleGPartI/TotalGrossReceipts"
## [22] "//Form990ScheduleGPartI/TotalNetToOrganization"
## [23] "//Form990ScheduleGPartI/TotalRetainedByContractors"
## [24] "//Form990ScheduleGPartI/LicensedStates"
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