|
9 | 9 | #' |
10 | 10 | #' @template general-arg |
11 | 11 | #' @template qualquant-arg |
| 12 | +#' @template dist-arg |
| 13 | +#' @template log-arg |
12 | 14 | # |
13 | | -checks.sample.core <- function(data, names, quantitative = NULL, |
| 15 | +checks.sample.core <- function(data, names, |
| 16 | + size, group, |
| 17 | + quantitative = NULL, |
14 | 18 | qualitative = NULL, |
15 | 19 | dist.mat = NULL, |
16 | | - method, size, group, |
17 | | - log.base = NULL |
18 | | - # selected |
19 | | -) { |
| 20 | + log.base = NULL, |
| 21 | + always.selected = NULL, |
| 22 | + mode = C("alloc", "sel")) { |
20 | 23 |
|
21 | 24 | # Declare nulls ---- |
22 | 25 |
|
@@ -80,7 +83,7 @@ checks.sample.core <- function(data, names, quantitative = NULL, |
80 | 83 | } |
81 | 84 |
|
82 | 85 | # check if 'size' argument is numeric vector of unit length |
83 | | - if (!is.null(size)) { |
| 86 | + if (mode == "alloc") { |
84 | 87 | if (!(is.numeric(size) && length(size) == 1)) { |
85 | 88 | stop('"size" should be a numeric vector of unit length.') |
86 | 89 | } |
@@ -211,22 +214,83 @@ checks.sample.core <- function(data, names, quantitative = NULL, |
211 | 214 | # Size ---- |
212 | 215 |
|
213 | 216 | # check if 'size' is a proportion between 0 and 1 |
214 | | - if (size <= 0 || size >= 1) { |
215 | | - stop('"size" should be a proportion between 0 and 1.') |
| 217 | + if (mode == "alloc") { |
| 218 | + if (size <= 0 || size >= 1) { |
| 219 | + stop('"size" should be a proportion between 0 and 1.') |
| 220 | + } |
216 | 221 | } |
217 | 222 |
|
218 | 223 | # Log base ---- |
219 | 224 |
|
220 | | - if (!is.numeric(log.base) || length(log.base) != 1 || is.na(log.base)) { |
221 | | - stop('"log.base" must be a single numeric value.') |
| 225 | + if (!is.null(log.base)) { |
| 226 | + |
| 227 | + if (!is.numeric(log.base) || length(log.base) != 1 || is.na(log.base)) { |
| 228 | + stop('"log.base" must be a single numeric value.') |
| 229 | + } |
| 230 | + |
| 231 | + if (log.base <= 0) { |
| 232 | + stop('"base" must be positive.') |
| 233 | + } |
| 234 | + |
| 235 | + if (log.base == 1) { |
| 236 | + stop('"log.base" of 1 is undefined.') |
| 237 | + } |
| 238 | + |
222 | 239 | } |
223 | 240 |
|
224 | | - if (log.base <= 0) { |
225 | | - stop('"base" must be positive.') |
| 241 | + # Always selected ---- |
| 242 | + |
| 243 | + if (mode == "sel" & !is.null(always.selected)) { |
| 244 | + # check if 'always.selected' is a character vector |
| 245 | + if (!is.character(always.selected)) { |
| 246 | + stop('"always.selected" should be a character vector.') |
| 247 | + } |
| 248 | + |
| 249 | + # check if always.selected is present in the entire set |
| 250 | + if (any(!(always.selected %in% data[, names]))) { |
| 251 | + alsel_miss <- always.selected[!(always.selected %in% data[, names])] |
| 252 | + stop(paste('The following accession(s) specified in "always.selected" ', |
| 253 | + 'are not present in "data":\n', |
| 254 | + paste(alsel_miss, collapse = ", "), |
| 255 | + sep = "")) |
| 256 | + } |
226 | 257 | } |
227 | 258 |
|
228 | | - if (log.base == 1) { |
229 | | - stop('"log.base" of 1 is undefined.') |
| 259 | + # Allocation vector ---- |
| 260 | + |
| 261 | + if (mode == "sel") { |
| 262 | + |
| 263 | + nm <- names(alloc) |
| 264 | + lv <- levels(data[, group]) |
| 265 | + |
| 266 | + if (!setequal(nm, lv)) { |
| 267 | + |
| 268 | + only_in_alloc <- setdiff(nm, lv) |
| 269 | + only_in_group <- setdiff(lv, nm) |
| 270 | + |
| 271 | + msg <- paste0( |
| 272 | + 'Mismatch between "alloc" names and levels of "group" column in data.\n\n', |
| 273 | + if (length(only_in_alloc) > 0) |
| 274 | + paste0( |
| 275 | + 'Present in "alloc" but not in "group" column levels: ', |
| 276 | + paste(shQuote(only_in_alloc), collapse = ', '), |
| 277 | + '\n' |
| 278 | + ) else '', |
| 279 | + if (length(only_in_group) > 0) |
| 280 | + paste0( |
| 281 | + 'Present in "group" column levels but not in "alloc": ', |
| 282 | + paste(shQuote(only_in_group), collapse = ', '), |
| 283 | + '\n' |
| 284 | + ) else '' |
| 285 | + ) |
| 286 | + |
| 287 | + stop(msg, call. = FALSE) |
| 288 | + |
| 289 | + } |
230 | 290 | } |
231 | 291 |
|
232 | 292 | } |
| 293 | + |
| 294 | + |
| 295 | + |
| 296 | + |
0 commit comments