|
6 | 6 | #' @param filename file path to config file |
7 | 7 | #' |
8 | 8 | #' @seealso \url{https://pepkit.github.io/} |
9 | | -.loadConfig = function(filename = NULL, sp = NULL) { |
| 9 | +.loadConfig = function(filename=NULL, sp=NULL) { |
10 | 10 | if (!file.exists(filename)) { |
11 | 11 | stop("No config file found") |
12 | 12 | } |
|
17 | 17 | cfg = methods::new("Config", config_file) |
18 | 18 |
|
19 | 19 | if (is.null(cfg)) { |
20 | | - cat("Config file not loaded.", fill = T) |
| 20 | + message("Config file not loaded.") |
21 | 21 | return() |
22 | 22 | } |
23 | 23 |
|
24 | | - cat("Loaded config file: ", filename, fill = T) |
| 24 | + message("Loaded config file: ", filename) |
25 | 25 |
|
26 | 26 | # Show available subprojects |
27 | 27 | .listSubprojects(cfg) |
|
34 | 34 | mdn = names(cfg$metadata) |
35 | 35 |
|
36 | 36 | cfg$metadata = .makeMetadataSectionAbsolute(cfg, parent = dirname(filename)) |
37 | | - |
| 37 | + # make data_sources section absolute |
| 38 | + if(!is.null(cfg$data_sources)) |
| 39 | + cfg$data_sources = lapply(cfg$data_sources, .expandPath) |
| 40 | + # make bioconductor$read_fun_path value absolute, used in BiocProject |
| 41 | + if(!is.null(cfg$bioconductor$read_fun_path)){ |
| 42 | + path = gsub("\\./","",cfg$bioconductor$read_fun_path) |
| 43 | + cfg$bioconductor$read_fun_path = .makeAbsPath(path, parent=dirname(filename)) |
| 44 | + } |
38 | 45 | # Infer default project name |
39 | 46 |
|
40 | 47 | if (is.null(cfg$name)) { |
|
47 | 54 | } |
48 | 55 | cfg$name = maybeProjectName |
49 | 56 | } |
50 | | - |
51 | 57 | return(cfg) |
52 | 58 | } |
53 | 59 |
|
54 | 60 | .updateSubconfig = function(cfg, sp = NULL) { |
55 | 61 | if (!is.null(sp)) { |
56 | 62 | if (is.null(cfg$subprojects[[sp]])) { |
57 | | - cat("Subproject not found: ", sp, fill = T) |
58 | | - return() |
| 63 | + warning("Subproject not found: ", sp) |
| 64 | + message("Subproject was not activated") |
| 65 | + return(cfg) |
59 | 66 | } |
60 | 67 | cfg = utils::modifyList(cfg, cfg$subprojects[[sp]]) |
61 | | - cat("Loading subproject: ", sp, fill = T) |
| 68 | + message("Loading subproject: ", sp) |
62 | 69 | } |
63 | 70 | return(cfg) |
64 | 71 | } |
65 | 72 |
|
66 | 73 |
|
67 | 74 |
|
68 | | -.listSubprojects = function(cfg) { |
| 75 | +.listSubprojects = function(cfg, style="message") { |
| 76 | + # this function can be used in object show method, where cat is preferred |
| 77 | + # or for user information when the Project is created, where message |
| 78 | + # is preferred |
| 79 | + if(!style == "message"){ |
| 80 | + printFun = pryr::partial(cat, fill = T) |
| 81 | + }else{ |
| 82 | + printFun = message |
| 83 | + } |
69 | 84 | # make sure the extracted config is of proper class |
70 | 85 | if(!methods::is(cfg,"Config")) |
71 | 86 | stop("The Project object does not contain a vaild config") |
72 | 87 |
|
73 | 88 | if (length(names(cfg$subprojects)) > 0) { |
74 | 89 | # If there are any show a cat and return if needed |
75 | | - cat(" subprojects: ", paste0(names(cfg$subprojects), |
76 | | - collapse = ","), fill = T) |
| 90 | + printFun(" subprojects: ", paste0(names(cfg$subprojects), |
| 91 | + collapse = ",")) |
77 | 92 | invisible(names(cfg$subprojects)) |
78 | 93 | } else{ |
79 | 94 | # Otherwise return NULL for testing purposes |
|
139 | 154 | } |
140 | 155 |
|
141 | 156 | # if it's a path, make it absolute |
142 | | - path = path.expand(path) |
| 157 | + path = normalizePath(path.expand(path),mustWork = FALSE) |
143 | 158 | # search for env vars, both bracketed and not |
144 | 159 | matchesBracket = gregexpr("\\$\\{\\w+\\}", path, perl = T) |
145 | 160 | matches = gregexpr("\\$\\w+", path, perl = T) |
|
148 | 163 | # this way both bracketed and not bracketed ones will be replaced |
149 | 164 | if(all(attr(matchesBracket[[1]], "match.length") != -1)) path = replaceEnvVars(path, matchesBracket) |
150 | 165 | if(all(attr(matches[[1]], "match.length") != -1)) path = replaceEnvVars(path, matches) |
151 | | - |
152 | 166 | return(path) |
153 | 167 | } |
154 | 168 |
|
|
165 | 179 | #' @param exclude character vector of args that should be excluded from |
166 | 180 | #' the interpolation. The elements in the vector should match the names of the |
167 | 181 | #' elements in the \code{args} list |
| 182 | +#' @param parent a directory that will be used to make the path absolute |
168 | 183 | #' @export |
169 | 184 | #' @examples |
170 | 185 | #' .strformat("~/{VAR1}{VAR2}_file", list(VAR1="hi", VAR2="hello")) |
171 | 186 | #' .strformat("$HOME/{VAR1}{VAR2}_file", list(VAR1="hi", VAR2="hello")) |
172 | | -.strformat = function(string, args, exclude) { |
| 187 | +.strformat = function(string, args, exclude, parent=NULL) { |
173 | 188 | result = c() |
174 | | - x = .expandPath(string) |
| 189 | + # if parent provided, make the path absolute and expand it. |
| 190 | + # Otherwise, just expand it |
| 191 | + x = ifelse(is.null(parent),.expandPath(string),.makeAbsPath(string, parent)) |
175 | 192 | # str_interp requires variables encoded like ${var}, so we substitute |
176 | 193 | # the {var} syntax here. |
177 | 194 | x = stringr::str_replace_all(x, "\\{", "${") |
|
230 | 247 | } |
231 | 248 | absoluteMetadata[[metadataAttribute]] = values |
232 | 249 | } |
| 250 | + |
| 251 | + |
233 | 252 | return(absoluteMetadata) |
234 | 253 | } |
0 commit comments