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/IRS990ScheduleN/DispositionOfAssetsDetail/AssetsDistriOrExpnssPaidDesc | 1 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/BusinessName/BusinessNameLine1 | 2 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/BusinessName/BusinessNameLine1Txt | 3 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/BusinessName/BusinessNameLine2 | 4 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/BusinessName/BusinessNameLine2Txt | 5 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/DistributionDt | 6 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/EIN | 7 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/FairMarketValueOfAssetAmt | 8 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/AddressLine1 | 9 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/AddressLine1Txt | 10 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/AddressLine2 | 11 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/AddressLine2Txt | 12 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/City | 13 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/CityNm | 14 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/Country | 15 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/CountryCd | 16 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/ForeignPostalCd | 17 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/PostalCode | 18 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/ProvinceOrState | 19 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/ProvinceOrStateNm | 20 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/IRCSectionTxt | 21 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/MethodOfFMVDeterminationTxt | 22 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/PersonNm | 23 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/AddressLine1 | 24 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/AddressLine1Txt | 25 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/AddressLine2 | 26 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/AddressLine2Txt | 27 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/City | 28 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/CityNm | 29 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/State | 30 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/StateAbbreviationCd | 31 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/ZIPCd | 32 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/ZIPCode | 33 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressForeign/AddressLine1 | 34 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressForeign/AddressLine2 | 35 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressForeign/City | 36 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressForeign/Country | 37 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressForeign/PostalCode | 38 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressForeign/ProvinceOrState | 39 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressUS/AddressLine1 | 40 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressUS/AddressLine2 | 41 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressUS/City | 42 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressUS/State | 43 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressUS/ZIPCode | 44 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/DateOfDistribution | 45 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/DescriptionOfAsset | 46 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/EIN | 47 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/FMVOfAsset | 48 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/IRCSection | 49 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/MethodOfFMVDetermination | 50 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/NameBusiness/BusinessNameLine1 | 51 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/NameBusiness/BusinessNameLine2 | 52 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/NamePerson | 53 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressForeign/AddressLine1 | 54 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressForeign/AddressLine2 | 55 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressForeign/City | 56 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressForeign/Country | 57 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressForeign/PostalCode | 58 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressForeign/ProvinceOrState | 59 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressUS/AddressLine1 | 60 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressUS/AddressLine2 | 61 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressUS/City | 62 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressUS/State | 63 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressUS/ZIPCode | 64 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/DateOfDistribution | 65 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/DescriptionOfAsset | 66 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/EIN | 67 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/FMVOfAsset | 68 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/IRCSection | 69 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/MethodOfFMVDetermination | 70 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/NameBusiness/BusinessNameLine1 | 71 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/NameBusiness/BusinessNameLine2 | 72 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/NamePerson | 73 |
<- as.character( t.xpaths$xpath )
xpaths <- create_edgelist_v1( xpaths )
el <- FromDataFrameNetwork( network=el )
nd print( nd )
## levelName
## 1 Return
## 2 °--ReturnData
## 3 °--IRS990ScheduleN
## 4 ¦--DispositionOfAssetsDetail
## 5 ¦ ¦--AssetsDistriOrExpnssPaidDesc
## 6 ¦ ¦--BusinessName
## 7 ¦ ¦ ¦--BusinessNameLine1
## 8 ¦ ¦ ¦--BusinessNameLine1Txt
## 9 ¦ ¦ ¦--BusinessNameLine2
## 10 ¦ ¦ °--BusinessNameLine2Txt
## 11 ¦ ¦--DistributionDt
## 12 ¦ ¦--EIN
## 13 ¦ ¦--FairMarketValueOfAssetAmt
## 14 ¦ ¦--ForeignAddress
## 15 ¦ ¦ ¦--AddressLine1
## 16 ¦ ¦ ¦--AddressLine1Txt
## 17 ¦ ¦ ¦--AddressLine2
## 18 ¦ ¦ ¦--AddressLine2Txt
## 19 ¦ ¦ ¦--City
## 20 ¦ ¦ ¦--CityNm
## 21 ¦ ¦ ¦--Country
## 22 ¦ ¦ ¦--CountryCd
## 23 ¦ ¦ ¦--ForeignPostalCd
## 24 ¦ ¦ ¦--PostalCode
## 25 ¦ ¦ ¦--ProvinceOrState
## 26 ¦ ¦ °--ProvinceOrStateNm
## 27 ¦ ¦--IRCSectionTxt
## 28 ¦ ¦--MethodOfFMVDeterminationTxt
## 29 ¦ ¦--PersonNm
## 30 ¦ °--USAddress
## 31 ¦ ¦--AddressLine1
## 32 ¦ ¦--AddressLine1Txt
## 33 ¦ ¦--AddressLine2
## 34 ¦ ¦--AddressLine2Txt
## 35 ¦ ¦--City
## 36 ¦ ¦--CityNm
## 37 ¦ ¦--State
## 38 ¦ ¦--StateAbbreviationCd
## 39 ¦ ¦--ZIPCd
## 40 ¦ °--ZIPCode
## 41 ¦--DispositionTable
## 42 ¦ ¦--AddressForeign
## 43 ¦ ¦ ¦--AddressLine1
## 44 ¦ ¦ ¦--AddressLine2
## 45 ¦ ¦ ¦--City
## 46 ¦ ¦ ¦--Country
## 47 ¦ ¦ ¦--PostalCode
## 48 ¦ ¦ °--ProvinceOrState
## 49 ¦ ¦--AddressUS
## 50 ¦ ¦ ¦--AddressLine1
## 51 ¦ ¦ ¦--AddressLine2
## 52 ¦ ¦ ¦--City
## 53 ¦ ¦ ¦--State
## 54 ¦ ¦ °--ZIPCode
## 55 ¦ ¦--DateOfDistribution
## 56 ¦ ¦--DescriptionOfAsset
## 57 ¦ ¦--EIN
## 58 ¦ ¦--FMVOfAsset
## 59 ¦ ¦--IRCSection
## 60 ¦ ¦--MethodOfFMVDetermination
## 61 ¦ ¦--NameBusiness
## 62 ¦ ¦ ¦--BusinessNameLine1
## 63 ¦ ¦ °--BusinessNameLine2
## 64 ¦ °--NamePerson
## 65 °--Form990ScheduleNPartII
## 66 °--DispositionTable
## 67 ¦--AddressForeign
## 68 ¦ ¦--AddressLine1
## 69 ¦ ¦--AddressLine2
## 70 ¦ ¦--City
## 71 ¦ ¦--Country
## 72 ¦ ¦--PostalCode
## 73 ¦ °--ProvinceOrState
## 74 ¦--AddressUS
## 75 ¦ ¦--AddressLine1
## 76 ¦ ¦--AddressLine2
## 77 ¦ ¦--City
## 78 ¦ ¦--State
## 79 ¦ °--ZIPCode
## 80 ¦--DateOfDistribution
## 81 ¦--DescriptionOfAsset
## 82 ¦--EIN
## 83 ¦--FMVOfAsset
## 84 ¦--IRCSection
## 85 ¦--MethodOfFMVDetermination
## 86 ¦--NameBusiness
## 87 ¦ ¦--BusinessNameLine1
## 88 ¦ °--BusinessNameLine2
## 89 °--NamePerson
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] "//DispositionOfAssetsDetail" "//DispositionTable"
## [3] "//Form990ScheduleNPartII"
# new version
find_table_headers( table.name )
## [1] "//DispositionOfAssetsDetail/AssetsDistriOrExpnssPaidDesc"
## [2] "//DispositionOfAssetsDetail/DistributionDt"
## [3] "//DispositionOfAssetsDetail/FairMarketValueOfAssetAmt"
## [4] "//DispositionOfAssetsDetail/MethodOfFMVDeterminationTxt"
## [5] "//DispositionOfAssetsDetail/EIN"
## [6] "//DispositionOfAssetsDetail/ForeignAddress"
## [7] "//DispositionOfAssetsDetail/USAddress"
## [8] "//DispositionOfAssetsDetail/BusinessName"
## [9] "//DispositionOfAssetsDetail/PersonNm"
## [10] "//DispositionOfAssetsDetail/IRCSectionTxt"
## [11] "//DispositionTable/DispositionTable"
## [12] "//DispositionTable/Form990ScheduleNPartII"
## [13] "//Form990ScheduleNPartII/DispositionTable"
## [14] "//Form990ScheduleNPartII/DirectorOfSuccessor"
## [15] "//Form990ScheduleNPartII/EmployeeOfSuccessor"
## [16] "//Form990ScheduleNPartII/OwnerOfSuccessor"
## [17] "//Form990ScheduleNPartII/ReceiveCompensation"
# 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: SN-P02-T01-DISPOSITION-OF-ASSETS
## [1] "NUMBER OF RETURNS PROCESSED: 1000"
## [1] "TOTAL NUMBER OF TABLE ROWS: 475"
TOTAL RUN TIME:
## Time difference of 21.05689 mins
## Time difference of -0.3509482 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] "SN_02_DOA_ASSET_DIST_DESC" "SN_02_DOA_ASSET_DIST_DATE"
## [9] "SN_02_DOA_ASSET_DIST_FMV" "SN_02_DOA_ASSET_DIST_FMV_METHOD"
## [11] "SN_02_DOA_RECIP_EIN" "SN_02_DOA_RECIP_IRC_SECTION"
## [13] "SN_02_DOA_RECIP_NAME_ORG_L1" "SN_02_DOA_RECIP_ADDR_L1"
## [15] "SN_02_DOA_RECIP_ADDR_CITY." "SN_02_DOA_RECIP_ADDR_STATE"
## [17] "SN_02_DOA_RECIP_ADDR_ZIP" "SN_02_DOA_RECIP_NAME_PERS"
## [19] "SN_02_DOA_RECIP_ADDR_L2" "SN_02_DOA_RECIP_ADDR_CNTR"
## [21] "SN_02_DOA_RECIP_NAME_ORG_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/IRS990ScheduleN/DispositionOfAssetsDetail/BusinessName"
## [3] "/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress"
## [4] "/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/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 °--IRS990ScheduleN
## 4 °--DispositionOfAssetsDetail
## 5 ¦--AssetsDistriOrExpnssPaidDesc
## 6 ¦--BusinessName
## 7 ¦ ¦--BusinessNameLine1Txt
## 8 ¦ °--BusinessNameLine2Txt
## 9 ¦--DistributionDt
## 10 ¦--EIN
## 11 ¦--FairMarketValueOfAssetAmt
## 12 ¦--ForeignAddress
## 13 ¦ ¦--AddressLine1Txt
## 14 ¦ ¦--AddressLine2Txt
## 15 ¦ ¦--CityNm
## 16 ¦ ¦--CountryCd
## 17 ¦ ¦--ForeignPostalCd
## 18 ¦ °--ProvinceOrStateNm
## 19 ¦--IRCSectionTxt
## 20 ¦--MethodOfFMVDeterminationTxt
## 21 ¦--PersonNm
## 22 °--USAddress
## 23 ¦--AddressLine1Txt
## 24 ¦--AddressLine2Txt
## 25 ¦--CityNm
## 26 ¦--StateAbbreviationCd
## 27 °--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/IRS990ScheduleN/DispositionOfAssetsDetail/AssetsDistriOrExpnssPaidDesc | 1 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/BusinessName/BusinessNameLine1 | 2 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/BusinessName/BusinessNameLine1Txt | 3 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/BusinessName/BusinessNameLine2 | 4 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/BusinessName/BusinessNameLine2Txt | 5 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/DistributionDt | 6 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/EIN | 7 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/FairMarketValueOfAssetAmt | 8 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/AddressLine1 | 9 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/AddressLine1Txt | 10 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/AddressLine2 | 11 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/AddressLine2Txt | 12 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/City | 13 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/CityNm | 14 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/Country | 15 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/CountryCd | 16 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/ForeignPostalCd | 17 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/PostalCode | 18 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/ProvinceOrState | 19 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/ForeignAddress/ProvinceOrStateNm | 20 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/IRCSectionTxt | 21 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/MethodOfFMVDeterminationTxt | 22 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/PersonNm | 23 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/AddressLine1 | 24 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/AddressLine1Txt | 25 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/AddressLine2 | 26 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/AddressLine2Txt | 27 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/City | 28 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/CityNm | 29 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/State | 30 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/StateAbbreviationCd | 31 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/ZIPCd | 32 |
/Return/ReturnData/IRS990ScheduleN/DispositionOfAssetsDetail/USAddress/ZIPCode | 33 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressForeign/AddressLine1 | 34 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressForeign/AddressLine2 | 35 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressForeign/City | 36 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressForeign/Country | 37 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressForeign/PostalCode | 38 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressForeign/ProvinceOrState | 39 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressUS/AddressLine1 | 40 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressUS/AddressLine2 | 41 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressUS/City | 42 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressUS/State | 43 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/AddressUS/ZIPCode | 44 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/DateOfDistribution | 45 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/DescriptionOfAsset | 46 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/EIN | 47 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/FMVOfAsset | 48 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/IRCSection | 49 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/MethodOfFMVDetermination | 50 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/NameBusiness/BusinessNameLine1 | 51 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/NameBusiness/BusinessNameLine2 | 52 |
/Return/ReturnData/IRS990ScheduleN/DispositionTable/NamePerson | 53 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressForeign/AddressLine1 | 54 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressForeign/AddressLine2 | 55 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressForeign/City | 56 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressForeign/Country | 57 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressForeign/PostalCode | 58 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressForeign/ProvinceOrState | 59 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressUS/AddressLine1 | 60 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressUS/AddressLine2 | 61 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressUS/City | 62 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressUS/State | 63 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/AddressUS/ZIPCode | 64 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/DateOfDistribution | 65 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/DescriptionOfAsset | 66 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/EIN | 67 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/FMVOfAsset | 68 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/IRCSection | 69 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/MethodOfFMVDetermination | 70 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/NameBusiness/BusinessNameLine1 | 71 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/NameBusiness/BusinessNameLine2 | 72 |
/Return/ReturnData/IRS990ScheduleN/Form990ScheduleNPartII/DispositionTable/NamePerson | 73 |
Identify all unique groups used in xpaths.
if( is.null(table.headers) )
find_table_headers( table.name ) } else
{ table.headers
## [1] "//DispositionOfAssetsDetail/AssetsDistriOrExpnssPaidDesc"
## [2] "//DispositionOfAssetsDetail/DistributionDt"
## [3] "//DispositionOfAssetsDetail/FairMarketValueOfAssetAmt"
## [4] "//DispositionOfAssetsDetail/MethodOfFMVDeterminationTxt"
## [5] "//DispositionOfAssetsDetail/EIN"
## [6] "//DispositionOfAssetsDetail/ForeignAddress"
## [7] "//DispositionOfAssetsDetail/USAddress"
## [8] "//DispositionOfAssetsDetail/BusinessName"
## [9] "//DispositionOfAssetsDetail/PersonNm"
## [10] "//DispositionOfAssetsDetail/IRCSectionTxt"
## [11] "//DispositionTable/DispositionTable"
## [12] "//DispositionTable/Form990ScheduleNPartII"
## [13] "//Form990ScheduleNPartII/DispositionTable"
## [14] "//Form990ScheduleNPartII/DirectorOfSuccessor"
## [15] "//Form990ScheduleNPartII/EmployeeOfSuccessor"
## [16] "//Form990ScheduleNPartII/OwnerOfSuccessor"
## [17] "//Form990ScheduleNPartII/ReceiveCompensation"
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