|
4 | 4 | # - assert_read_function |
5 | 5 | # - assert_copy_function |
6 | 6 | # |
7 | | -#' @title Collection of assertions for copy_functions |
8 | | -#' @description Collection of assertions used in standard copy_functions. |
9 | | -#' |
10 | | -#' @details All copy functions have the same arguments and the |
11 | | -#' assertion can be standardized. The assertion of \code{filname} is |
12 | | -#' constructed to handle both character and list input. |
13 | | -#' |
14 | | -#' The assertion is based on removing ending "\\" and "/" from |
15 | | -#' \code{from_path} and \code{to_path} before the assertion is performed. |
16 | | -#' |
17 | | -#' @param filename Argument to the copy-function to be asserted. |
18 | | -#' @param from_path Argument to the copy-function to be asserted. Ending |
19 | | -#' "\\" and "/" should have been removed before the assertion is performed. |
20 | | -#' @param to_path Argument to the copy-function to be asserted. Ending |
21 | | -#' "\\" and "/" should have been removed before the assertion is performed. |
22 | | -#' |
23 | | -#' @return \code{TRUE} if none of the assertions failed. If any of the assertions |
24 | | -#' failed, one or more error messages are returned. |
25 | | -#' |
26 | | -#' @author Petter Hopp Petter.Hopp@@vetinst.no |
27 | | -#' @keywords internal |
28 | | -#' |
29 | | -#' |
30 | | -assert_copy_function <- function(filename, |
31 | | - from_path, |
32 | | - to_path) { |
33 | | - |
34 | | - # ARGUMENT CHECKING ---- |
35 | | - # Object to store check-results |
36 | | - checks <- checkmate::makeAssertCollection() |
37 | | - |
38 | | - # Perform checks |
39 | | - ## filename |
40 | | - checkmate::assert(checkmate::check_character(filename, |
41 | | - min.chars = 1, |
42 | | - len = 1), |
43 | | - checkmate::check_list(filename, min.len = 1), |
44 | | - combine = "or", |
45 | | - add = checks) |
46 | | - |
47 | | - # checkmate::assert_list(filename, len = 2, add = checks) |
48 | | - # # from_path |
49 | | - # checkmate::assert_character(from_path, len = 1, min.chars = 1, add = checks) |
50 | | - # if (endsWith(from_path, "/")) { |
51 | | - # checkmate::assert_directory_exists(substr(from_path, 1, nchar(from_path) - 1), access = "r", add = checks) |
52 | | - # } else { |
53 | | - # checkmate::assert_directory_exists(from_path, access = "r", add = checks) |
54 | | - # } |
55 | | - |
56 | | - ## from_path / filename |
57 | | - for (i in c(1:length(filename))) { |
58 | | - checkmate::assert_file_exists(file.path(from_path, filename[[i]]), access = "r", add = checks) |
59 | | - } |
60 | | - ## to_path |
61 | | - checkmate::assert_directory_exists(to_path, access = "r", add = checks) |
62 | | - |
63 | | - # Report check-results |
64 | | - checkmate::reportAssertions(checks) |
65 | | -} |
| 7 | +# #' @title Collection of assertions for copy_functions |
| 8 | +# #' @description Collection of assertions used in standard copy_functions. |
| 9 | +# #' |
| 10 | +# #' @details All copy functions have the same arguments and the |
| 11 | +# #' assertion can be standardized. The assertion of \code{filname} is |
| 12 | +# #' constructed to handle both character and list input. |
| 13 | +# #' |
| 14 | +# #' The assertion is based on removing ending "\\" and "/" from |
| 15 | +# #' \code{from_path} and \code{to_path} before the assertion is performed. |
| 16 | +# #' |
| 17 | +# #' @param filename Argument to the copy-function to be asserted. |
| 18 | +# #' @param from_path Argument to the copy-function to be asserted. Ending |
| 19 | +# #' "\\" and "/" should have been removed before the assertion is performed. |
| 20 | +# #' @param to_path Argument to the copy-function to be asserted. Ending |
| 21 | +# #' "\\" and "/" should have been removed before the assertion is performed. |
| 22 | +# #' |
| 23 | +# #' @return \code{TRUE} if none of the assertions failed. If any of the assertions |
| 24 | +# #' failed, one or more error messages are returned. |
| 25 | +# #' |
| 26 | +# #' @author Petter Hopp Petter.Hopp@@vetinst.no |
| 27 | +# #' @keywords internal |
| 28 | +# #' |
| 29 | +# #' |
| 30 | +# assert_copy_function <- function(filename, |
| 31 | +# from_path, |
| 32 | +# to_path) { |
| 33 | +# |
| 34 | +# # ARGUMENT CHECKING ---- |
| 35 | +# # Object to store check-results |
| 36 | +# checks <- checkmate::makeAssertCollection() |
| 37 | +# |
| 38 | +# # Perform checks |
| 39 | +# ## filename |
| 40 | +# checkmate::assert(checkmate::check_character(filename, |
| 41 | +# min.chars = 1, |
| 42 | +# len = 1), |
| 43 | +# checkmate::check_list(filename, min.len = 1), |
| 44 | +# combine = "or", |
| 45 | +# add = checks) |
| 46 | +# |
| 47 | +# # checkmate::assert_list(filename, len = 2, add = checks) |
| 48 | +# # # from_path |
| 49 | +# # checkmate::assert_character(from_path, len = 1, min.chars = 1, add = checks) |
| 50 | +# # if (endsWith(from_path, "/")) { |
| 51 | +# # checkmate::assert_directory_exists(substr(from_path, 1, nchar(from_path) - 1), access = "r", add = checks) |
| 52 | +# # } else { |
| 53 | +# # checkmate::assert_directory_exists(from_path, access = "r", add = checks) |
| 54 | +# # } |
| 55 | +# |
| 56 | +# ## from_path / filename |
| 57 | +# for (i in c(1:length(filename))) { |
| 58 | +# checkmate::assert_file_exists(file.path(from_path, filename[[i]]), access = "r", add = checks) |
| 59 | +# } |
| 60 | +# ## to_path |
| 61 | +# checkmate::assert_directory_exists(to_path, access = "r", add = checks) |
| 62 | +# |
| 63 | +# # Report check-results |
| 64 | +# checkmate::reportAssertions(checks) |
| 65 | +# } |
66 | 66 |
|
67 | 67 | # #' @title Collection of assertions for add_functions |
68 | 68 | # #' @description Collection of assertions used in standard add_functions. |
@@ -162,64 +162,64 @@ assert_copy_function <- function(filename, |
162 | 162 | # } |
163 | 163 |
|
164 | 164 |
|
165 | | -#' @title Collection of assertions for read_functions |
166 | | -#' @description Collection of assertions used in standard read_functions. |
167 | | -#' |
168 | | -#' @details All read functions include the same arguments and the |
169 | | -#' assertion can be standardized. The assertion of \code{filname} is |
170 | | -#' constructed to handle both character and list input. |
171 | | -#' |
172 | | -#' The assertion is based on removing ending "\\" and "/" from |
173 | | -#' \code{from_path} before the assertion is performed. |
174 | | - |
175 | | -#' The assertCollection must be set up separately and is used as input argument, see example. |
176 | | -#' |
177 | | -#' @param filename Argument to the function to be asserted. |
178 | | -#' @param from_path Argument to the function to be asserted. Ending |
179 | | -#' "\\" and "/" must have been removed before the assertion is performed. |
180 | | -#' @param add assertCollection. |
181 | | -#' |
182 | | -#' @return An assertCollection that have been updated with the results of assertions for \code{filename} and \code{from_path}. |
183 | | -#' |
184 | | -#' @author Petter Hopp Petter.Hopp@@vetinst.no |
185 | | -#' @keywords internal |
186 | | -#' @export |
187 | | -#' |
188 | | -#' @examples |
189 | | -#' # Attach package and make temporary directory |
190 | | -#' library(NVIdb) |
191 | | -#' td <- tempdir() |
192 | | -#' write.csv2(NVIdb::PJS_levels, file = file.path(td, "PJS_levels.csv")) |
193 | | -#' |
194 | | -#' # ARGUMENT CHECKING |
195 | | -#' # Object to store check-results |
196 | | -#' checks <- checkmate::makeAssertCollection() |
197 | | -#' # Perform checks |
198 | | -#' checks <- assert_read_functions(filename = "PJS_levels.csv", |
199 | | -#' from_path = td, |
200 | | -#' add = checks) |
201 | | -#' # Report check-results |
202 | | -#' checkmate::reportAssertions(checks) |
203 | | -assert_read_functions <- function(filename, |
204 | | - from_path, |
205 | | - add) { |
206 | | - |
207 | | - checkmate::assert_class(x = add, classes = "AssertCollection") |
208 | | - |
209 | | - # Perform checks ---- |
210 | | - |
211 | | - ## filename |
212 | | - checkmate::assert(checkmate::check_character(filename, |
213 | | - min.chars = 1, len = 1, |
214 | | - any.missing = FALSE), |
215 | | - checkmate::check_list(filename, |
216 | | - min.len = 1, |
217 | | - any.missing = FALSE), |
218 | | - combine = "or", |
219 | | - add = add) |
220 | | - ## from_path / filename |
221 | | - for (i in c(1:length(filename))) { |
222 | | - checkmate::assert_file_exists(file.path(from_path, filename[[i]]), access = "r", add = add) |
223 | | - } |
224 | | - return(add) |
225 | | -} |
| 165 | +# #' @title Collection of assertions for read_functions |
| 166 | +# #' @description Collection of assertions used in standard read_functions. |
| 167 | +# #' |
| 168 | +# #' @details All read functions include the same arguments and the |
| 169 | +# #' assertion can be standardized. The assertion of \code{filname} is |
| 170 | +# #' constructed to handle both character and list input. |
| 171 | +# #' |
| 172 | +# #' The assertion is based on removing ending "\\" and "/" from |
| 173 | +# #' \code{from_path} before the assertion is performed. |
| 174 | +# |
| 175 | +# #' The assertCollection must be set up separately and is used as input argument, see example. |
| 176 | +# #' |
| 177 | +# #' @param filename Argument to the function to be asserted. |
| 178 | +# #' @param from_path Argument to the function to be asserted. Ending |
| 179 | +# #' "\\" and "/" must have been removed before the assertion is performed. |
| 180 | +# #' @param add assertCollection. |
| 181 | +# #' |
| 182 | +# #' @return An assertCollection that have been updated with the results of assertions for \code{filename} and \code{from_path}. |
| 183 | +# #' |
| 184 | +# #' @author Petter Hopp Petter.Hopp@@vetinst.no |
| 185 | +# #' @keywords internal |
| 186 | +# #' @export |
| 187 | +# #' |
| 188 | +# #' @examples |
| 189 | +# #' # Attach package and make temporary directory |
| 190 | +# #' library(NVIdb) |
| 191 | +# #' td <- tempdir() |
| 192 | +# #' write.csv2(NVIdb::PJS_levels, file = file.path(td, "PJS_levels.csv")) |
| 193 | +# #' |
| 194 | +# #' # ARGUMENT CHECKING |
| 195 | +# #' # Object to store check-results |
| 196 | +# #' checks <- checkmate::makeAssertCollection() |
| 197 | +# #' # Perform checks |
| 198 | +# #' checks <- assert_read_functions(filename = "PJS_levels.csv", |
| 199 | +# #' from_path = td, |
| 200 | +# #' add = checks) |
| 201 | +# #' # Report check-results |
| 202 | +# #' checkmate::reportAssertions(checks) |
| 203 | +# assert_read_functions <- function(filename, |
| 204 | +# from_path, |
| 205 | +# add) { |
| 206 | +# |
| 207 | +# checkmate::assert_class(x = add, classes = "AssertCollection") |
| 208 | +# |
| 209 | +# # Perform checks ---- |
| 210 | +# |
| 211 | +# ## filename |
| 212 | +# checkmate::assert(checkmate::check_character(filename, |
| 213 | +# min.chars = 1, len = 1, |
| 214 | +# any.missing = FALSE), |
| 215 | +# checkmate::check_list(filename, |
| 216 | +# min.len = 1, |
| 217 | +# any.missing = FALSE), |
| 218 | +# combine = "or", |
| 219 | +# add = add) |
| 220 | +# ## from_path / filename |
| 221 | +# for (i in c(1:length(filename))) { |
| 222 | +# checkmate::assert_file_exists(file.path(from_path, filename[[i]]), access = "r", add = add) |
| 223 | +# } |
| 224 | +# return(add) |
| 225 | +# } |
0 commit comments