Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message when 2024 files are passed to process_data() #32

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ BugReports: https://github.com/ketchbrookanalytics/fcall/issues
Depends:
R (>= 3.5.0)
Imports:
cli,
DBI,
dplyr,
glue,
Expand Down
44 changes: 41 additions & 3 deletions R/process_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,50 @@
#'
#' # Access "RCB" metadata
#' processed_data$metadata$RCB
#'
#' }
process_data <- function(dir) {

# Throw an error if the directory doesn't exist (instead of returning an
# empty list object)
if (!dir.exists(dir)) {

glue::glue("Directory {glue::double_quote(dir)} does not exist.") |>
rlang::abort()

}

# If `process_data_all()` throws an error, add a message about the bad 2024
# files from FCA
tryCatch(
expr = process_data_all(dir),
error = function(e) {

cli::cli_h1("A Note about FCA's 2024 Data:")

paste(
"Please note there is an outstanding issue with the 2024 files posted",
"by FCA. If you are trying to process 2024 data, please refer to",
"{.url https://github.com/ketchbrookanalytics/fcall/issues/23}",
"for more information and solutions while FCA works on fixing the",
"files."
) |>
cli::cli_alert_warning()

cli::cli_h1("Error Message:")

# Return the actual error message
return(e)

}
)

}

#' Main function for processing files into a list of R data frames.
#' Used by `process_data()`.
#' @noRd
process_data_all <- function(dir) {

# List all files in folder
files <- list.files(dir)

Expand Down Expand Up @@ -206,8 +246,6 @@ process_metadata_file <- function(file) {

}



#' Process a data file using metadata and codes dictionary
#'
#' `process_data_file()` reads a data file, applies the provided metadata and codes dictionary,
Expand Down
1 change: 0 additions & 1 deletion man/process_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions tests/testthat/bad_data/D_INST.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FILE LAYOUT FOR INSTITUTION INFORMATION
DATA DELIMITED BY COMMAS
ALPHANUMERIC VALUES ARE ENCLOSED IN DOUBLE QUOTES


VARIABLE FIELD DEC.
NAME TYPE POS. VARIABLE DESCRIPTION
--------------- ------- ---- --------------------------------------
SYSTEM Numeric 0 System Code
DIST Numeric 0 District Code
ASSOC Numeric 0 Association Code
MONTH Numeric 0 Month of Report
YEAR Numeric 0 Year of Report
UNINUM Numeric 0 System, district, and Association
codes concatenated
SHORTNAME Alphanum. 0 Institution short name
MAIL_ADDR Alphanum. 0 Mailing address
STREET_ADDR Alphanum. 0 Street address
CITY Alphanum. 0 City name
STATE Alphanum. 0 State name
ZIP Alphanum. 0 Zip code
95 changes: 95 additions & 0 deletions tests/testthat/bad_data/D_RC.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
FILE LAYOUT FOR SCHEDULE RC-BALANCE SHEET
DATA DELIMITED BY COMMA


VARIABLE FIELD DEC.
NAME TYPE POS. VARIABLE DESCRIPTION
-------------- ------- ---- --------------------
SYSTEM Numeric 0 System Code
DIST Numeric 0 District Code
ASSOC Numeric 0 Association Code
MONTH Numeric 0 Month of Report
YEAR Numeric 0 Year of Report
UNINUM Numeric 0 System, District, and Association
codes concatenated
CASH Numeric 0 Cash
ACTREC Numeric 0 Accounts Receivable
ACRLNS Numeric 0 Accrual Loans and Leases net of
unearned income and unapplied
loan payments
NTRECOFCI Numeric 0 Loans, notes, sales, contracts, and
leases: Notes receivable from other
FCS institutions
ONTREC Numeric 0 Loans, notes, sales, contracts, and
leases: Other notes receivable
ACRSCON Numeric 0 Loans, notes, sales, contracts, and
leases: Accrual Sales Contracts
NONACR Numeric 0 Loans, notes, sales, contracts, and
leases: Nonaccrual Loans
ALLNLOSS Numeric 0 Loans, notes, sales, contracts, and
leases: Allowance for credit losses on loans, etc.
NETLOANS Numeric 0 Loans, notes, sales, contracts, and
leases: Net Loans
AIRLOANS Numeric 0 Accrued Interest Receivable on Loans
and Leases
AIRNTRECOFCI Numeric 0 Accrued Interest Receivable on Notes
receivable from other FCS Institutions
AIRONTREC Numeric 0 Accrued Interest Receivable on Other
Notes receivable
AIRSCON Numeric 0 Accrued Interest Receivable on Sales
Contracts
AIRMKTIN Numeric 0 Accrued Interest Receivable on
Securities
AIREC Numeric 0 Total Accrued Interest Receivable
NAQPROP Numeric 0 Other Property Owned
FIXASSET Numeric 0 Premises and Other Fixed Assets
OASSETS Numeric 0 Other Assets
ASSETS Numeric 0 Total Assets
SYSNTBDSOS Numeric 0 Interest bearing liabilities:
Systemwide notes and bonds outstanding
NTPAYOFCI Numeric 0 Interest bearing liabilities:
Notes payable to other FCS
OINTBEARDT Numeric 0 Interest bearing liabilities:
Other interest-bearing debt
ACTPAY Numeric 0 Accounts Payable
AIPSYSNTBDSOS Numeric 0 Accrued interest payable on: Systemwide
notes and bonds outstanding
AIPNTPAYOFCI Numeric 0 Accrued interest payable on: Notes
payable to other FCS institutions
AIPOINTBEARDT Numeric 0 Accrued Interest Payable on Other
interest-bearing debt
AIPAY Numeric 0 Total Accrued Interest Payable
OLIABS Numeric 0 Other Liabilities
LIABS Numeric 0 Total Liabilities
NETWRTH Numeric 0 Total Net Worth
TOTLICAP Numeric 0 Total Liabilities and Net Worth
ACNOCOMINC Numeric 0 Accumulated other comprehensive income (net)
LNADJFVAL Numeric 0 Loans, notes, sales, contracts, and
leases: Loan adjustment for fair value
DTADJFVAL Numeric 0 Interest bearing liabilities:
Debt adjustment for fair value
TOTINTBEARLIAB Numeric 0 Interest bearing liabilities:
Total interest bearing liabilities
AIRDERIVATIVE Numeric 0 Accrued interest receivable: Derivatives
IBLSUBNOTEBOND Numeric 0 Interest bearing liabilities:
Subordinated notes and bonds
AIPSUBNOTEBOND Numeric 0 Accrued interest payable on:
Subordinated notes and bonds
AIPDERIVATIVE Numeric 0 Accrued interest payable on: Derivatives
LoanLeaseHeld Numeric 0 Loans and leases held for sale
CreditLossReserve Numeric 0 Reserve for credit losses on off-balance
sheet exposures
TERMPERFSTK Numeric 0 Interest bearing liabilities:
Limited-life (term) preferred stock
AccrdIntPayTermPrefStk Numeric 0 Accrued interest payable on:
Limited-life (term) preferred stock
CapStock Numeric 0 Capital stock
PerpetualPrefStk Numeric 0 Perpetual Preferred stock
PAIDIN Numeric 0 Paid-in capital
AllocSurplus Numeric 0 Allocated Surplus
UNRETERN Numeric 0 Unallocated retained earnings
TotInvDebtSecurities Numeric 0 Debt securities, net of allowance for credit losses
TotInvEquityFCSI Numeric 0 Equity investments in System institutions
and Farmer Mac
TotInvEquityNonFCSI Numeric 0 Equity investments in non-System institutions
TotInvestments Numeric 0 Total Investments
91 changes: 91 additions & 0 deletions tests/testthat/bad_data/D_RC1.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
FILE LAYOUT FOR SCHEDULE RC.1 MEMORANDA
DATA DELIMITED BY COMMAS



VARIABLE FIELD DEC.
NAME TYPE POS. VARIABLE DESCRIPTION
------------- ------ ---- ---------------------
SYSTEM Numeric 0 System Code
DIST Numeric 0 District Code
ASSOC Numeric 0 Association Code
MONTH Numeric 0 Month of Report
YEAR Numeric 0 Year of Report
UNINUM Numeric 0 System, District, and association
codes concatenated
TYPRE Numeric 0 Loans - Production agriculture Real
estate mortgages
TYPPROINT Numeric 0 Loans - Production agriculture Production
and intermediate term
TYPCOOP Numeric 0 Loans - Agibusiness - Loans to cooperatives
TYPPROCMKT Numeric 0 Loans - Agibusiness - Processing and Marketing
TYPFARMREL Numeric 0 Loans - Agibusiness - Farm related business
TYPCOMM Numeric 0 Loans - Communications
TYPENERG Numeric 0 Loans - Energy
TYPWATW Numeric 0 Loans - Water/waste disposal
TYPRURRE Numeric 0 Loans - Rural residence real estate
TYPINTNL Numeric 0 Loans - International
TYPLESREC Numeric 0 Loans - Lease receivables
DLNASSOC Numeric 0 Direct loans to associations
OFIAMTLN Numeric 0 Discounted loans to OFIs
TYPTOTAL Numeric 0 Total
FINLEASES Numeric 0 Finance leases
OPLEASES Numeric 0 Operating receivables leases
OPLEASESASST Numeric 0 Operating assets leases
LNSYN Numeric 0 Loan syndications to eligible borrowers
(excluding similiar entity transactions)
GUARFED Numeric 0 Guarantees: Federal
GUARSTATLOC Numeric 0 Guarantees: State and local
GUARFAMC Numeric 0 Guarantees: Farmer Mac
GUAROTHER Numeric 0 Guarantees: Other

OFINUM Numeric 0 Number of Other Financial Institutions
(OFIs)
OFINUMLN Numeric 0 Number of loans to OFIs
LSANUMOS Numeric 0 Association loans outsite its chartered
territory: Number of loans outstanding
LSANUMNEW Numeric 0 Association loans outsite its chartered
territory: Number of loans made
LSAAMTOS Numeric 0 Association loans outsite its chartered
territory: Amount of loans outstanding
LSAAMTNEW Numeric 0 Association loans outsite its chartered
territory: Amount of loans made

AMTLNBKRUPTCY Numeric 0 Total amount of loans in bankruptcy
AMTLNFORECLOSUR Numeric 0 Total amount of loans in foreclosure
TAMTBANKFORE Numeric 0 Total amount of loans in both
bankruptcy and foreclosure
FCIBONDS Numeric 0 Farm Credit investment bonds
outstanding
INVFARMNOTE Numeric 0 Investments in farmers' notes
NPDIRLNTBK Numeric 0 Notes payable/direct loan to district
bank
FCSICPREMPAY Numeric 0 Farm Credit System Insurance
Corporation premium payable
TYPOTH Numeric 0 Other loans
LMPRIN90 Numeric 0 Deprecated
LMAMT Numeric 0 Deprecated
LMNO Numeric 0 Deprecated
TYPPROCMKT12 Numeric 0 Processing and Marketing Loans:
Loans made under 613.3010(a)(1) and (a)(2)
TYPPROCMKT3 Numeric 0 Processing and Marketing Loans:
Loans made under 613.3010(a)(3)
TYPPROCMKT4 Numeric 0 Processing and Marketing Loans:
Loans made under 613.3010(a)(4)
TYPPROCMKT5 Numeric 0 Processing and Marketing Loans:
Loans made under 613.3010(a)(5)
TOP10LOANS Numeric 0 Aggregate amount of institution’s
10 largest loan commitments
NUMLOANSFRMFDIC Numeric 0 Number of loans outstanding pur
chased from the FDIC
AMTLOANSFRMFDIC Numeric 0 Amount of loans outstanding purchased
from the FDIC
LLLIMITBASE Numeric 0 Lending and Leasing Limit Base (Stops collecting as of March 2022)
LoanLeaseHeldAmortizedCost Numeric 0 Loans and Leases Held for Sale: Amortized cost
LoanLeaseHeldFairValue Numeric 0 Loans and Leases Held for Sale: Fair value
TotRegCap Numeric 0 Lending and Leasing Limit Base:
Total regulatory capital (Sch. RC-R.1, item 5b.)
Excess3rdPartyCap Numeric 0 Lending and Leasing Limit Base:
Eligible excess third-party capital above regulatory capital limits
LendLeaseLimitBaseTRC Numeric 0 Lending and Leasing Limit Base:
Lending and Leasing Limit Base (sum of items 5a. and 5b.)
78 changes: 78 additions & 0 deletions tests/testthat/bad_data/D_RCB.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
FILE LAYOUT FOR SCHEDULE RC-B Debt Securities
(excluding investments in FC institutions and
diversified investment funds)


VARIABLE FIELD DEC.
NAME TYPE POS. VARIABLE DESCRIPTION
------------- ------- ---- ---------------------
SYSTEM Numeric 0 System Code
DIST Numeric 0 District Code
ASSOC Numeric 0 Association Code
MONTH Numeric 0 Month of Report
YEAR Numeric 0 Year of Report
UNINUM Numeric 0 System, District, and Association
codes concatenated
** INV_CODE Numeric 0 Investment Code for Marketable
Investments:
10 U.S. Treasury securities
15 SBA securities
17 Other U.S. Gov’t securities and Agency(excluding MBS)

25 Securities fully and unconditionally guaranteed by a
GSE (excluding MBS and Farmer Mac securities)
29 Municipal securities
35 International and multilateral development
bank obligations

40 Money market instruments:Federal funds sold
41 Money market instruments:Negotiable certificates of
Deposit
60 Money market instruments:Banker acceptances
52 Money market instruments:Commercial paper

50 Money market instruments:Reverse repurchase agreements
51 Money market instruments:Other

62 RMBS fully and unconditionally guaranteed by U.S.
government or its agencies
68 RMBS fully and unconditionally guaranteed by GSE
64 Non-Agency RMBS
69 Other RMBS

71 CMBS(excl. Farmer Mac sec.):CMBS fully and unconditionally
guaranteed by U.S. government
72 CMBS(excl. Farmer Mac sec.):CMBS fully and unconditionally
guaranteed by GSE
73 CMBS(excl. Farmer Mac sec.):Non-Agency CMBS
65 CMBS(excl. Farmer Mac sec.):Other CMBS

86 Farmer Mac guaranteed sec.:Farm and ranch securities (i.e., AMBS)
87 Farmer Mac guaranteed sec.:Rural utility securities
88 Farmer Mac guaranteed sec.:USDA securities
66 Farmer Mac guaranteed sec.:Other Farmer Mac debt securities

141 ABS(excl. Farmer Mac securities):Credit card receivables
142 ABS(excl. Farmer Mac securities):Home equity loans
143 ABS(excl. Farmer Mac securities):Auto Loans
144 ABS(excl. Farmer Mac securities):Student Loans
145 ABS(excl. Farmer Mac securities):Equipment loans
146 ABS(excl. Farmer Mac securities):Manufactured housing loans
95 ABS(excl. Farmer Mac securities):Other ABS

81 Other types of debt securities:Domestic debt securities
82 Other types of debt securities:Foreign debt securities

180 Allowance for Credit Losses on Debt Securities(start collecting on March 2023)

99 Total Debt Securities


** BKVAL Numeric 0 Amortized cost of Marketable Investments
** MKTVAL Numeric 0 Fair Value of Marketable Investments
** BKVALFORSALE Numeric 0 Available for Sale - Amortized cost
** MKTVALFORSALE Numeric 0 Available for Sale - Fair Value


** NOTE: THE RECORD CONTAINS MULTIPLE OCCURANCES OF THESE
VARIABLES. THERE IS ONE OCCURENCE FOR EACH INV_CODE VALUE.
Loading
Loading