-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.R
94 lines (85 loc) 路 2.9 KB
/
utils.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
raw2clean <- function(x){
temp <- splitstackshape::cSplit(x, "to", "; ", "long")
clean <- splitstackshape::cSplit(temp, "from", "; ", "long")
return(clean)
}
checkRelease <- function(x){
x <- tolower(x) # norm
if (x %in% db$name && length(x) == 1) {
release <- db[db$name == x, "uri"]
return(release)
} else if(!x %in% db$name && length(x) == 1) {
msg <- paste0(db$name, collapse = ", ")
stop(paste0("Wrong release, can be one of: ", msg), call. = FALSE)
} else if (length(x) > 1){
stop("Can only pass one release", call. = FALSE)
}
}
OStoURI <- function(x){
if(x == "Windows"){
uri <- "ftp://ftp.foolabs.com/pub/xpdf/xpdfbin-win-3.04.zip"
ext <- ".zip"
} else if (x == "Linux"){
uri <- "ftp://ftp.foolabs.com/pub/xpdf/xpdfbin-linux-3.04.tar.gz"
ext <- ".tar.gz"
} else if(x == "Darwin") {
uri <- "ftp://ftp.foolabs.com/pub/xpdf/xpdfbin-mac-3.04.tar.gz"
ext <- ".tar.gz"
} else {
stop(paste0("Unrecognised operating system, download manually from \n",
"http://www.foolabs.com/xpdf/download.html"), call. = FALSE)
}
lst <- list(uri = uri, ext = ext)
return(lst)
}
decompress_fun <- function(temp_zip){
if(length(temp_zip[grep("tar.gz", temp_zip)])){
return(untar)
} else if(length(temp_zip[grep("zip", temp_zip)])){
return(unzip)
}
}
OS2folder <- function(x){
if(x == "Windows"){
folder <- "win"
} else if (x == "Linux"){
folder <- "linux"
} else if(x == "Darwin") {
folder <- "mac"
}
folder <- paste0("/xpdfbin-", folder, "-3.04/bin64/")
return(folder)
}
checkOS <- function(os, dest){
dest <- substr(dest, 1, 3)
if(os == "Windows" && !dest %in% "C:/"){
x <- ""
while(!tolower(x) %in% c("y", "n")){
x <- readline(prompt = paste("You are on Windows and installing in",
dest, "drive. It is adviced to install it in",
"C:/ (even on 64 bit) \nProceed anyway? [y/n]\n"))
}
if(tolower(x) != "y") stop("Change dest directory", call. = FALSE)
}
if(os == "mac"){
x <- ""
while(!tolower(x) %in% c("y", "n")){
x <- readline(prompt = paste0("You are running ", os, ".\n",
"get_xpdf has not been tested on your OS, would you like to continue anyway?"))
}
if(tolower(x) != "y") stop("Change dest directory", call. = FALSE)
}
}
lin_warn <- function(){
os <- Sys.info()['sysname'] # get os
if(os == "Linux"){
x <- ""
while(!tolower(x) %in% c("y", "n")){
x <- readline(prompt = paste0("You are running ", os, ".\n",
"get_emails makes use of the tmp folder which by defaults requires root access, ",
"if so extarction will likely fail.",
"\nWould you like to continue anyway?"))
}
if(tolower(x) != "y") stop("Download manually", call. = FALSE)
}
}