Skip to content

Instantly share code, notes, and snippets.

@chris-prener
Created August 19, 2019 17:01
Show Gist options
  • Save chris-prener/775458cb94a93aa420aa2a6e9676f71c to your computer and use it in GitHub Desktop.
Save chris-prener/775458cb94a93aa420aa2a6e9676f71c to your computer and use it in GitHub Desktop.
# dependencies
library(dplyr)
library(googledrive)
library(lubridate)
library(readr)
library(stringr)
# download form data
forms <- drive_find(pattern = "FA19-01")
# generate links
links <- drive_link(forms)
# add file names and links to new tibble
table <- tibble(
name = forms$name,
link = links
)
# create new dates variable and re-order
table <- table %>%
mutate(date_str = word(name, start = 3, end = 5)) %>%
mutate(date = paste(
word(date_str, 3), # year
str_pad(as.character(match(word(date_str, 1), month.name)), 2, pad = "0"), # month
str_pad(str_replace(word(date_str, 2), pattern = ",", ""), 2, pad = "0"), sep = "-")) %>% # day
mutate(date = as_date(date)) %>%
arrange(date, name)
# update link
table <- table %>%
mutate(link = str_sub(link, 1, str_length(link)-17)) %>%
mutate(link = paste0(link,"viewform?usp=sf_link"))
# write csv
write_csv(table, path = "data.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment