-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget_config.R
63 lines (62 loc) · 2.11 KB
/
get_config.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
# DIZtools - Utilities for 'DIZ' R Package Development
# Copyright (C) 2020-2023 Universitätsklinikum Erlangen, Germany
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#' @title Reads a config yaml file and return the value for a given key.
#'
#' @description Reads a config yaml file and return the value for a given key.
#'
#' @param config_file A character string. The path to the config.yml-file
#' containing the database configuration.
#' @param config_key A character string. The name of the corresponding
#' database. This string must be conform with the corresponding config
#' section in the config.yml-file.
#'
#' @return If successful it returns the value, Null otherwise.
#' @examples
#' \donttest{
#' utils_path <- tempdir()
#' config <- get_config(
#' config_file = paste0(utils_path, "/MISC/email.yml"),
#' config_key = "email"
#' )}
#'
#' @export
#'
get_config <-
function(config_file,
config_key) {
res <- tryCatch({
config::get(value = config_key, file = config_file)
},
error = function(cond) {
cond <- paste(unlist(cond), collapse = " ")
DIZtools::feedback(
print_this = paste0("Cannot access config_file. ", cond),
type = "Error",
findme = "e3e1b9c5f9"
)
return(NULL)
},
warning = function(cond) {
cond <- paste(unlist(cond), collapse = " ")
DIZtools::feedback(
print_this = paste0("Cannot access config_file. ", cond),
type = "Warning",
findme = "718e0f3d88"
)
return(NULL)
})
return(res)
}