-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.r
119 lines (111 loc) · 2.93 KB
/
functions.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# doorsign
# functions
# fn_version
fn_version <- function() {
return("v2.1")
}
# validation
fn_validate <- function(input, message1, message2, message3) {
if (missing(message1)) message1 <- "Input is missing."
gcheck <- length(grep("Argument \\'\\w+\\' missing", message1))
if (gcheck == 1) {
m1 <- sub("Argument ", "", message1)
m1 <- sub(" missing.", "", m1)
}
if (all(is.null(input))) {
if (missing(message1)) message1 <- "Input is missing."
print(message1)
} else if (is.numeric(input) | is.list(input)) {
if (all(is.na(input))) {
if (missing(message2)) {
if (gcheck == 1) message2 <- paste0("Argument ", m1, " is NA.", sep = "")
if (gcheck != 1) message2 <- "Input is NA."
}
print(message2)
}
} else if (is.character(input)) {
if (all(nchar(input) == 0)) {
if (missing(message3)) {
if (gcheck == 1) message3 <- paste0("Argument ", m1, " is empty.", sep = "")
if (gcheck != 1) message3 <- "Input is empty."
}
print(message3)
}
} else {
NULL
}
}
fn_validate_range <- function(value, min, max, label = NULL) {
if (!is.numeric(value)) {
return(paste0("The input '", label, "' must be a number."))
} else {
if (value < min || value > max) {
return(paste0("The input '", label, "' must be between ", min, " and ", max, "."))
} else {
NULL
}
}
}
# validate image input
fn_validate_im <- function(x) {
if (!is.null(x)) {
y <- tolower(sub("^.+[.]", "", basename(x$datapath)))
if (!y %in% c("jpg", "png", "jpeg", "gif")) {
return("Image must be one of JPG/JPEG, PNG or GIF formats.")
}
if ((x$size / 1024 / 1024) > 1) {
return("Image must be less than 1MB in size.")
}
}
}
sample_data_1 <- list(
"person-1" = list(
"name" = "Ingrid Bergqvist",
"content" =
"**Manager, NBIS** \\
Dept. of Cell and Molecular Biology (ICM) \\
Uppsala University \\
ingrid.bergqvist@nbis.se \\
0862634824"
)
)
sample_data_5 <- list(
"person-1" = list(
"name" = "Jimmy Bodin",
"content" =
"**Systems Developer, NBIS** \\
Dept. of Cell and Molecular Biology (ICM) \\
jimmy.bodin@nbis.se"
),
"person-2" = list(
"name" = "Sonja Andersson",
"content" =
"**Bioinformatician, NBIS** \\
Dept. of Med. Biochem & Microb (IMBIM) \\
sonja.andersson@nbis.se"
),
"person-3" = list(
"name" = "Fredrik Holmberg",
"content" =
"**Bioinformatician, NBIS** \\
Dept. of Med. Biochem & Microb (IMBIM) \\
fredrik.holmberg@nbis.se"
),
"person-4" = list(
"name" = "Ellinor Berglund",
"content" =
"**Bioinformatician, NBIS** \\
Dept. of Imm., Genetics & Pathology (IGP) \\
ellinor.berglund@nbis.se"
),
"person-5" = list(
"name" = "Inga Magnusson",
"content" =
"**Bioinformatician, NBIS** \\
Dept. of Imm., Genetics & Pathology (IGP) \\
inga.magnusson@nbis.se"
)
)
fname <- function() {
return(paste0("door-sign-", fn_version(), ".pdf"))
}