Skip to content

Commit e9387d2

Browse files
More quality checks: any(!x)->!all(x); use vapply_1{b,c,i}
1 parent 1b363ad commit e9387d2

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

R/mergelist.R

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ hasindex = function(x, by, retGrp=FALSE) {
4141
fdistinct = function(x, on=key(x), mult=c("first","last"), cols=seq_along(x), copy=TRUE) {
4242
if (!perhaps.data.table(x))
4343
stopf("'x' must be data.table")
44-
if (!is.character(on) || !length(on) || anyNA(on) || any(!on%chin%names(x)))
44+
if (!is.character(on) || !length(on) || anyNA(on) || !all(on %chin% names(x)))
4545
stopf("'on' must be character column names of 'x' argument")
4646
mult = match.arg(mult)
4747
if (is.null(cols))
@@ -242,11 +242,11 @@ mergelist = function(l, on, cols, how=c("left","inner","full","right","semi","an
242242
{
243243
if (!is.list(l) || is.data.frame(l))
244244
stopf("'l' must be a list")
245-
if (any(!vapply(l, is.data.table, FALSE)))
245+
if (!all(vapply_1b(l, is.data.table)))
246246
stopf("Every element of 'l' list must be data.table objects")
247-
if (any(!vapply(l, length, 0L)))
247+
if (!all(lengths(l)))
248248
stopf("Tables in 'l' argument must be non-zero columns tables")
249-
if (any(vapply(l, function(x) anyDuplicated(names(x)), 0L)))
249+
if (any(vapply_1i(l, function(x) anyDuplicated(names(x)))))
250250
stopf("Some of the tables in 'l' have duplicated column names")
251251
} ## l
252252
if (!isTRUEorFALSE(copy))
@@ -262,23 +262,23 @@ mergelist = function(l, on, cols, how=c("left","inner","full","right","semi","an
262262
{
263263
if (!is.list(join.many))
264264
join.many = rep(list(join.many), n-1L)
265-
if (length(join.many)!=n-1L || any(!vapply(join.many, isTRUEorFALSE, NA)))
265+
if (length(join.many)!=n-1L || !all(vapply_1b(join.many, isTRUEorFALSE)))
266266
stopf("'join.many' must be TRUE or FALSE, or a list of such which length must be length(l)-1L")
267267
} ## join.many
268268
{
269269
if (missing(mult))
270270
mult = NULL
271271
if (!is.list(mult))
272272
mult = rep(list(mult), n-1L)
273-
if (length(mult)!=n-1L || any(!vapply(mult, function(x) is.null(x) || (is.character(x) && length(x)==1L && !anyNA(x) && x%chin%c("error","all","first","last")), NA)))
273+
if (length(mult)!=n-1L || !all(vapply_1b(mult, function(x) is.null(x) || (is.character(x) && length(x)==1L && !anyNA(x) && x %chin% c("error","all","first","last")))))
274274
stopf("'mult' must be one of [error, all, first, last] or NULL, or a list of such which length must be length(l)-1L")
275275
} ## mult
276276
{
277277
if (missing(how) || is.null(how))
278278
how = match.arg(how)
279279
if (!is.list(how))
280280
how = rep(list(how), n-1L)
281-
if (length(how)!=n-1L || any(!vapply(how, function(x) is.character(x) && length(x)==1L && !anyNA(x) && x%chin%c("left","inner","full","right","semi","anti","cross"), NA)))
281+
if (length(how)!=n-1L || !all(vapply_1b(how, function(x) is.character(x) && length(x)==1L && !anyNA(x) && x %chin% c("left","inner","full","right","semi","anti","cross"))))
282282
stopf("'how' must be one of [left, inner, full, right, semi, anti, cross], or a list of such which length must be length(l)-1L")
283283
} ## how
284284
{
@@ -289,10 +289,10 @@ mergelist = function(l, on, cols, how=c("left","inner","full","right","semi","an
289289
stopf("'%s' must be a list", "cols")
290290
if (length(cols) != n)
291291
stopf("'cols' must be same length as 'l'")
292-
skip = vapply(cols, is.null, FALSE)
293-
if (any(!vapply(cols[!skip], function(x) is.character(x) && !anyNA(x) && !anyDuplicated(x), NA)))
292+
skip = vapply_1b(cols, is.null)
293+
if (!all(vapply_1b(cols[!skip], function(x) is.character(x) && !anyNA(x) && !anyDuplicated(x))))
294294
stopf("'cols' must be a list of non-zero length, non-NA, non-duplicated, character vectors, or eventually NULLs (all columns)")
295-
if (any(mapply(function(x, icols) any(!icols %chin% names(x)), l[!skip], cols[!skip])))
295+
if (any(mapply(function(x, icols) !all(icols %chin% names(x)), l[!skip], cols[!skip])))
296296
stopf("'cols' specify columns not present in corresponding table")
297297
}
298298
} ## cols
@@ -302,7 +302,7 @@ mergelist = function(l, on, cols, how=c("left","inner","full","right","semi","an
302302
} else {
303303
if (!is.list(on))
304304
on = rep(list(on), n-1L)
305-
if (length(on)!=n-1L || any(!vapply(on, function(x) is.character(x) && !anyNA(x) && !anyDuplicated(x), NA))) ## length checked in dtmerge
305+
if (length(on)!=n-1L || !all(vapply_1b(on, function(x) is.character(x) && !anyNA(x) && !anyDuplicated(x)))) ## length checked in dtmerge
306306
stopf("'on' must be non-NA, non-duplicated, character vector, or a list of such which length must be length(l)-1L")
307307
}
308308
} ## on
@@ -323,7 +323,7 @@ mergelist = function(l, on, cols, how=c("left","inner","full","right","semi","an
323323
)
324324
out.cols = copy(names(out))
325325
}
326-
out.mem = vapply(out, address, "")
326+
out.mem = vapply_1c(out, address)
327327
if (copy)
328328
.Call(CcopyCols, out, colnamesInt(out, names(out.mem)[out.mem %chin% unique(unlist(l.mem, recursive=FALSE))]))
329329
if (verbose)

0 commit comments

Comments
 (0)