-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsetup.R
47 lines (40 loc) · 1.19 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
if(!library('rnbn', logical.return=TRUE)){
install.packages("rnbn")
}
# These are super-useful:
install.packages("ggplot2")
install.packages("ggmap")
install.packages("dplyr")
library(rnbn)
if(file.exists('NBN_Details.R')){
source("NBN_Details.R")
}else{
create <- readline("NBN_Details.R doesn't exist. Do you want to create it?\nCreate file (y/n)? ")
retry <- tolower(create) == "y"
if(!retry){
writeLines("You'll need to call nbnLogin() yourself before you do anything else\n")
writeLines("Please be careful to keep your account details out of your repository!\n")
}
while(retry){
user <- readline("NBN username: ")
password <- readline("NBN password: ")
retry <- tryCatch(
{
rnbn::nbnLogin(user,password);
sink("NBN_Details.R");
writeLines(paste0("NBN_USER <- '", gsub("'", "\\'", user), "';"));
writeLines(paste0("NBN_PASSWORD <- '", gsub("'", "\\'", password), "';"));
sink();
source("NBN_Details.R")
FALSE
},
error = function(e){
choice<- readline("Login failed. Try again (y/n)? ")
tolower(choice) == 'y'
},
finally=function(){
sink()
}
)
}
}