-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path04_store.R
37 lines (28 loc) · 994 Bytes
/
04_store.R
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
library(tidyverse)
library(glue)
library(here)
library(googledrive)
pins::board_register_local(name = 'conscious_lang', cache = '/tmp')
d <- pins::pin_get('cl_results',board='conscious_lang')
h <- pins::pin_get('cl_hist',board='conscious_lang')
d %>%
mutate(date = Sys.Date()) %>%
relocate(date,.before = url) %>%
bind_rows(h) %>%
distinct(date, url, .keep_all = TRUE) -> h1
h1 %>% pins::pin('cl_hist',board='conscious_lang')
# Push h1 to GDrive as a backup
# Register to GDrive
options(
gargle_oauth_cache = ".secrets",
gargle_oauth_email = TRUE
)
drive_auth(email = TRUE)
# Get the backup dir for this env (or create)
backup_dir <- drive_get(glue("DataBackups/ConsciousLanguage"))
if (nrow(backup_dir) == 0) backup_dir <- drive_mkdir(glue("DataBackups/ConsciousLanguage"))
tmpfile <- tempfile()
on.exit(unlink(tmpfile))
h1 %>% write.csv(tmpfile)
drive_put(media = tmpfile, type = 'spreadsheet',
path = 'DataBackups/ConsciousLanguage', name = 'historical_data.csv')