Skip to content

Commit

Permalink
Removed googledrive dependency from r/accessing-and-managing-financia…
Browse files Browse the repository at this point in the history
…l-data
  • Loading branch information
christophscheuch committed Feb 13, 2024
1 parent f90fcce commit 5fce497
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 197 deletions.

Large diffs are not rendered by default.

297 changes: 152 additions & 145 deletions docs/r/accessing-and-managing-financial-data.html

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions docs/search.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/sitemap.xml
Expand Up @@ -50,7 +50,7 @@
</url>
<url>
<loc>https://www.tidy-finance.org/r/accessing-and-managing-financial-data.html</loc>
<lastmod>2024-01-08T14:33:15.302Z</lastmod>
<lastmod>2024-02-13T10:52:28.535Z</lastmod>
</url>
<url>
<loc>https://www.tidy-finance.org/r/fixed-effects-and-clustered-standard-errors.html</loc>
Expand Down
22 changes: 8 additions & 14 deletions r/accessing-and-managing-financial-data.qmd
Expand Up @@ -129,30 +129,24 @@ factors_q_monthly <- read_csv(factors_q_monthly_link) |>

## Macroeconomic Predictors

Our next data source is a set of macroeconomic variables often used as predictors for the equity premium. @Goyal2008 comprehensively reexamine the performance of variables suggested by the academic literature to be good predictors of the equity premium. The authors host the data updated to 2022 on [Amit Goyal's website.](https://sites.google.com/view/agoyal145) Since the data is an XLSX-file stored on a public Google drive location, we need additional packages to access the data directly from our R session. Therefore, we load `readxl` to read the XLSX-file [@readxl] and `googledrive` for the Google drive connection [@googledrive].\index{Data!Macro predictors}
Our next data source is a set of macroeconomic variables often used as predictors for the equity premium. @Goyal2008 comprehensively reexamine the performance of variables suggested by the academic literature to be good predictors of the equity premium. The authors host the data updated to 2022 on [Amit Goyal's website.](https://sites.google.com/view/agoyal145) Since the data is an XLSX-file stored on a public Google drive location, we need to first download the data to access the data directly from our R session. Therefore, we load `readxl` to read the XLSX-file [@readxl].\index{Data!Macro predictors}

```{r}
#| message: false
library(readxl)
library(googledrive)
```

Usually, you need to authenticate if you interact with Google drive directly in R. Since the data is stored via a public link, we can proceed without any authentication.\index{Google Drive}

```{r}
drive_deauth()
```

The `drive_download()` function from the `googledrive` package allows us to download the data and store it locally.
We use the basic `download.file()` function to download the XLSX-file.^[Note that the `mode = "wb"` argument is used to ensure that the file is written in binary mode, which is important for non-text files like XLSX.]

```{r}
#| message: false
macro_predictors_link <-
"https://docs.google.com/spreadsheets/d/1g4LOaRj4TvwJr9RIaA_nwrXXWTOy46bP"
macro_predictors_url <-
"https://docs.google.com/spreadsheets/d/1g4LOaRj4TvwJr9RIaA_nwrXXWTOy46bP/export?format=xlsx"
drive_download(
macro_predictors_link,
path = "macro_predictors.xlsx"
download.file(
url = macro_predictors_url,
destfile = "macro_predictors.xlsx",
mode = "wb"
)
```

Expand Down
29 changes: 2 additions & 27 deletions renv.lock
@@ -1,6 +1,6 @@
{
"R": {
"Version": "4.3.1",
"Version": "4.3.2",
"Repositories": [
{
"Name": "CRAN",
Expand All @@ -9,7 +9,7 @@
]
},
"Python": {
"Version": "3.10.11",
"Version": "3.10.13",
"Type": "virtualenv",
"Name": "./renv/python/virtualenvs/renv-python-3.10"
},
Expand Down Expand Up @@ -1354,31 +1354,6 @@
],
"Hash": "4f2596dfb05dac67b9dc558e5c6fba2e"
},
"googledrive": {
"Package": "googledrive",
"Version": "2.1.0",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"R",
"cli",
"gargle",
"glue",
"httr",
"jsonlite",
"lifecycle",
"magrittr",
"pillar",
"purrr",
"rlang",
"tibble",
"utils",
"uuid",
"vctrs",
"withr"
],
"Hash": "e88ba642951bc8d1898ba0d12581850b"
},
"googlesheets4": {
"Package": "googlesheets4",
"Version": "1.1.0",
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Expand Up @@ -41,7 +41,7 @@ ipython==8.16.1
ipython-genutils==0.2.0
ipywidgets==8.1.1
isoduration==20.11.0
jedi==0.18.2
jedi==0.19.1
Jinja2==3.1.2
joblib==1.3.2
json5==0.9.14
Expand Down Expand Up @@ -111,7 +111,7 @@ pyzmq==25.1.1
qtconsole==5.4.4
QtPy==2.4.0
referencing==0.30.2
regtabletotext==0.0.11
regtabletotext==0.0.12
requests==2.31.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
Expand Down

0 comments on commit 5fce497

Please sign in to comment.