This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.R
55 lines (45 loc) · 1.54 KB
/
setup.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Sys.setenv(TZ = "UTC")
suppressPackageStartupMessages({
library(googlesheets4)
library(reticulate)
library(dplyr)
library(readr)
library(janitor)
})
# setwd(dirname(dirname(rstudioapi::getSourceEditorContext()$path)) # uncomment for rstudio
# setwd(system("pwd", intern = TRUE)) # uncomment for Rscript
# read config
source("config.R")
# TODO: add testing for input, now assume config is fine
# clean up config info
config <- lapply(config, function(x) toString(x) %>% trimws("both"))
if (any(sapply(config, function(i) i == ""))) stop("config information not completed")
questions <- lapply(
config[c(
"first_name_question",
"last_name_question",
"username_question"
)],
janitor::make_clean_names
)
# hide warning
options(gargle_oauth_email = config$your_email_address) # for googlesheet
# load py modules
use_condaenv("brats-tool", required = TRUE)
cu <- reticulate::import("challengeutils")
pd <- reticulate::import("pandas")
synapseclient <- reticulate::import("synapseclient")
# log in to synapse
syn <- synapseclient$Synapse()
syn$login(config$username, config$password, silent = TRUE)
# Reading google sheet from response of form
# need to successfully authenticate once in an interactive session
# token will be store automatically; gs4_has_token()
suppressMessages(
response <- remove_empty(
read_sheet(config$google_sheet_url, trim_ws = TRUE),
which = "rows"
) %>%
setNames(janitor::make_clean_names(colnames(.)))
)
if (any(sapply(questions, function(i) !i %in% colnames(response)))) stop("not all questions matched")