From 2828f3d410f4a3bc6357e0c87bbc6837068a4b0a Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 11 Nov 2021 19:29:59 +0000 Subject: [PATCH 1/5] Rproj created --- AutomatedEconomicAnalysis.Rproj | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 AutomatedEconomicAnalysis.Rproj diff --git a/AutomatedEconomicAnalysis.Rproj b/AutomatedEconomicAnalysis.Rproj new file mode 100644 index 0000000..8e3c2eb --- /dev/null +++ b/AutomatedEconomicAnalysis.Rproj @@ -0,0 +1,13 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX From 8700a7bad29ba096b801225832ede0a14c39dfb3 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 11 Nov 2021 19:30:08 +0000 Subject: [PATCH 2/5] gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b6a065 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.Rproj.user +.Rhistory +.RData +.Ruserdata From 3e84c537bb005fe7fb0de03fd21181916b66581d Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 11 Nov 2021 20:03:28 +0000 Subject: [PATCH 3/5] code structure - no functional changes --- AutomatedEconomicAnalysisWithR.R | 45 +++++++++++++++----------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/AutomatedEconomicAnalysisWithR.R b/AutomatedEconomicAnalysisWithR.R index bde5a82..8ff6e6e 100644 --- a/AutomatedEconomicAnalysisWithR.R +++ b/AutomatedEconomicAnalysisWithR.R @@ -1,5 +1,7 @@ #!/usr/bin/R +# Startup - Packages -------------------------------------------------------------------------------------------------------- + pkgTest <- function(x){ if (!require(x,character.only = TRUE)) { install.packages(x,dep=TRUE) @@ -26,7 +28,8 @@ pkgTest("COVID19") setwd("~/Documents/R/") -# Test that FRED is online #### +# Startup - Online? -------------------------------------------------------------------------------------------------------- +# Test that FRED is online test.online <- try(getSymbols("GDPC1",src='FRED')) if ((inherits(test.online, "try-error"))) { @@ -36,8 +39,7 @@ if ((inherits(test.online, "try-error"))) { rm(list=ls()) - -# Email setup and credentials ------------------------------------------------------------- +# Startup - Email setup and credentials ------------------------------------------------------------- # replace with your own email info email <- gm_mime() @@ -49,7 +51,7 @@ FRED_API_KEY <- "" # put your own FRED API key here source("Credentials.R") # file where MY credentials for Fred, Twitter, and Gmail are stored fredr_set_key(FRED_API_KEY) -# Data Download ------------------------------------------------------------- +# Data Download - Definitions ------------------------------------------------------------- Data.US <- c("US.GDP.Real"="GDPC1", "US.GDP.PCE"="PCECC96", @@ -204,6 +206,7 @@ Data.US <- c("US.GDP.Real"="GDPC1", ) +# Data Download - Description ------------------------------------------------------------- Data.Description <- data.frame( Mnemonic = names(Data.US), @@ -227,7 +230,7 @@ for ( idx in 1:nrow(Data.Description) ) { } -# Misc. functions --------------------------------------------------------- +# Functions - Misc. --------------------------------------------------------- misc.FREDdowload <- function(series) { @@ -260,7 +263,7 @@ misc.NBER.Recessions <- function(){ } -# Charting functions --------------------------------------------------------- +# Functions - Charting --------------------------------------------------------- misc.GDPExpansionPlot <- function( series ){ @@ -628,10 +631,7 @@ Chart.DoublePanel <- function(series1, series2, periods) { } - - - -# Weekly Update ----------------------------------------------------------- +# EXE - Tweet - Weekly Update ----------------------------------------------------------- # Tuesday: Gas Prices Chart.Duo(series1="US.GasPrices", series2="US.Commodities.Oilprices", @@ -685,7 +685,7 @@ InterestRate.Chart(Data.Rates = Reduce(function(...) merge(...), list( misc.FRED -# GDP Releases ------------------------------------------------------- +# EXE - Tweet - GDP Releases ------------------------------------------------------- if ( ( as.Date( as.character(tail( fredr_release_dates(release_id = 53L) ,1)[,2]) ) == Sys.Date() ) || @@ -720,7 +720,7 @@ if ( ( as.Date( as.character(tail( fredr_release_dates(release_id = 53L) ,1)[,2] } -# Activity Measures ------------------------------------------------------- +# EXE - Tweet - Activity Measures ------------------------------------------------------- Chart.Duo(series1="US.Activity.RetailSales", series2="US.Activity.RetailSalesExAuto", @@ -778,12 +778,7 @@ Chart.Duo(series1="US.Activity.RetailSalesSportsGoods", series2="US.Activity.Ret tweet.text = "Bought a #Peleton During the Pandemic? Sales of #SportingGoods Skyrocketed in 2021. https://bit.ly/3BXLMFM #AdvanceRetailSales #rstats", email=email) - - - - - -# Labor Market ------------------------------------------------------- +# EXE - Tweet - Labor Market ------------------------------------------------------- Chart.Single(series="US.JOLTS.QuitsRate", @@ -841,7 +836,7 @@ Chart.Four(series1 = "US.Unemployment.EmploymentToPopulation", email = email) -# Inflation ------------------------------------------------------- +# EXE - Tweet - Inflation ------------------------------------------------------- Chart.Single(series = "US.CPI.Headline.mm.yy", period = 25, @@ -898,7 +893,7 @@ Chart.Duo(series1="US.CPI.AlcoholicBeverages.mm.yy", series2="US.CPI.AlcoholicBe -# Housing ------------------------------------------------------- +# EXE - Tweet - Housing ------------------------------------------------------- Chart.Single(series="US.Housing.CaseShiller", periods = 25, @@ -922,7 +917,7 @@ Chart.Single(series="US.Survey.Empire", -# Motor Vehicles ------------------------------------------------------- +# EXE - Tweet - Motor Vehicles ------------------------------------------------------- Chart.Duo(series1="US.Auto.Autosales", series2="US.Auto.InventorySalesRatio", periods = 25, @@ -952,7 +947,7 @@ if ( as.Date( as.character(tail( fredr_release_dates(release_id = 93L) ,1)[,2]) } -# Banking Sector ------------------------------------------------------- +# EXE - Tweet - Banking Sector ------------------------------------------------------- Chart.Duo(series1="US.FDIC.NetChargeOffRateTotalLoans", series2="US.FDIC.LoanLossProvisions", periods = 35, @@ -1090,7 +1085,7 @@ if ( Data.Description[Data.Description$Mnemonic == "US.SLOOS.AutoLoansStandards" } -# Transportation ------------------------------------------------------- +# EXE - Tweet - Transportation ------------------------------------------------------- if ( Data.Description[Data.Description$Mnemonic == "US.Transportation.Air",6] == Sys.Date() ) Chart.Four(series1="US.Transportation.Air", @@ -1111,7 +1106,7 @@ if ( Data.Description[Data.Description$Mnemonic == "US.Transportation.Rail",6] = email=email) -# COVID ------------------------------------------------------- +# EXE - Tweet - COVID ------------------------------------------------------- if (weekdays(Sys.Date()) %in% c("Tuesday", "Thursday", "Sunday")) { @@ -1141,4 +1136,6 @@ if (weekdays(Sys.Date()) %in% c("Tuesday", "Thursday", "Sunday")) { } +# EXE - Email ----------------------------------------------------------------------------------------------------------------- + gm_send_message(email) From c31d9a873c920862220f29bd6846ac03719abf8c Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 11 Nov 2021 20:21:50 +0000 Subject: [PATCH 4/5] test.online --- AutomatedEconomicAnalysisWithR.R | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/AutomatedEconomicAnalysisWithR.R b/AutomatedEconomicAnalysisWithR.R index 8ff6e6e..513c74a 100644 --- a/AutomatedEconomicAnalysisWithR.R +++ b/AutomatedEconomicAnalysisWithR.R @@ -29,14 +29,10 @@ pkgTest("COVID19") setwd("~/Documents/R/") # Startup - Online? -------------------------------------------------------------------------------------------------------- -# Test that FRED is online -test.online <- try(getSymbols("GDPC1",src='FRED')) -if ((inherits(test.online, "try-error"))) { - stop("\n\n\n----------\n Not online \n----------\n\n") -} - -rm(list=ls()) +test.online <- !inherits(try(quantmod::getSymbols("GDPC1",src='FRED')), "try-error") # Test that FRED is online +stopifnot(test.online) +rm(list=ls()) # do we need it? replace with: rm(test.online) ? # Startup - Email setup and credentials ------------------------------------------------------------- From 615a9cc7891fdc6dbed2d0aff90f4b2d5f05fe5b Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 11 Nov 2021 20:22:55 +0000 Subject: [PATCH 5/5] cleanup --- AutomatedEconomicAnalysisWithR.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AutomatedEconomicAnalysisWithR.R b/AutomatedEconomicAnalysisWithR.R index 513c74a..f6da504 100644 --- a/AutomatedEconomicAnalysisWithR.R +++ b/AutomatedEconomicAnalysisWithR.R @@ -26,7 +26,6 @@ pkgTest("tm") pkgTest("gmailr") pkgTest("COVID19") -setwd("~/Documents/R/") # Startup - Online? -------------------------------------------------------------------------------------------------------- @@ -37,6 +36,8 @@ rm(list=ls()) # do we need it? replace with: rm(test.online) ? # Startup - Email setup and credentials ------------------------------------------------------------- +setwd("~/Documents/R/") + # replace with your own email info email <- gm_mime() #email <- gm_to(email, toAddress