~hrbrmstr/markdowntemplates

markdowntemplates/inst/rmarkdown/templates/gdriveupload/skeleton/skeleton.Rmd -rw-r--r-- 1.3 KiB View raw
29b3c199hrbrmstr google drive auto-upload template 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
title: ""
author: ""
date: ""
params:
  gdrive_folder_url: "https://drive.google.com/drive/u/0/folders/FIXME"
output:
  html_document:
    keep_md: true
    theme: simplex
    highlight: monochrome
---
```{r init, include=FALSE}
knitr::opts_chunk$set(
  message = FALSE,
  warning = FALSE, dev = c("png", "cairo_pdf"),
  echo = FALSE,
  fig.retina = 2,
  fig.width = 10,
  fig.height = 6,
  fig.path = "prod/charts/"
)
```

```{r boilerplate-libraries, cache=FALSE}
library(gt)
library(stringi)
library(hrbrthemes)
library(googledrive)
library(tidyverse)

# ensure fonts are available
extrafont::loadfonts("postscript", quiet = TRUE)
extrafont::loadfonts("pdf", quiet = TRUE)
```

# analysis code goes here -------------------------------------------------


# Upload to production ----------------------------------------------------

```{r prod-upload, echo = TRUE, message = TRUE, warning = TRUE}
googledrive::drive_auth()

# locate the folder
gdrive_prod_folder <- googledrive::as_id(params$gdrive_folder_url)

# clean it out
gdrls <- googledrive::drive_ls(gdrive_prod_folder)
if (nrow(gdrls) > 0) {
  dplyr::pull(gdrls, id) %>%
    purrr::walk(~googledrive::drive_rm(googledrive::as_id(.x)))
}

# upload new
list.files(here::here("prod/charts"), recursive = TRUE, full.names = TRUE) %>%
  purrr::walk(googledrive::drive_upload, path = gdrive_prod_folder)
```