-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbloomr.download.build.R
66 lines (48 loc) · 1.91 KB
/
bloomr.download.build.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
56
57
58
59
60
61
62
63
64
65
66
### Download 'bloomr.build.R' from Github and ask to build it inside a date-based dir in the cwd
## Intended for fast internal testing - Readme method is the standard way
### Link to this file:
## https://raw.githubusercontent.com/AntonioFasano/BloomR/master/bloomr.download.build.R
## script.path= parent.frame(2)$ofile
loadLib <- function(lib){
if (!lib %in% rownames(installed.packages())){
repo <- getOption("repos")[["CRAN"]]
if(repo=="@CRAN@") repo <- "http://cran.r-project.org"
install.packages(lib, repos=repo)
}
if(!eval(parse(text=paste('require(', lib,')')))){
message("\nUnable to load", lib, "library")
return (FALSE)
}
if(!has_internet()){
message("\nThere is no internet connection.")
return (FALSE)
}
return (TRUE)
}
source_github <- function(u) {
req <- curl_fetch_memory(u)
if(req$status_code >= 400){
message("The download of the build script from GitHub failed with status code ", req$status_code)
return (FALSE)
} else {
script <- rawToChar(req$content)
script <- gsub("\\r", "", script) # remove unix line endings
## message( script )
eval(parse(text = script), envir=.GlobalEnv)
return(TRUE)
}
}
main <- function(){
buildscript <- "https://raw.githubusercontent.com/AntonioFasano/BloomR/master/bloomr.build.R"
## Load curl package
if(!loadLib("curl")) return(1)
## Load build script
if(!(source_github(buildscript))) return(1)
## Create download path
dirname <- format(Sys.time(), "bloomr-%y%m%d-%H%M")
dirpath <- file.path(getwd(), dirname)
## Start download and build
ans <- readline(sprintf("I will create BloomeR in %s . (Y/n)? ", dirpath))
if(tolower(ans)=="y" || ans=="") makeBloomR(dirpath) else print('bye')
}
main()