Skip to content

Commit 58a2c8e

Browse files
pass at style
1 parent 5bb3845 commit 58a2c8e

File tree

1 file changed

+57
-62
lines changed

1 file changed

+57
-62
lines changed

R/mergelist.R

Lines changed: 57 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -257,82 +257,77 @@ mergepair = function(lhs, rhs, on, how, mult, lhs.cols=names(lhs), rhs.cols=name
257257
setDT(out)
258258
}
259259

260-
mergelist = function(l, on, cols, how=c("left","inner","full","right","semi","anti","cross"), mult, copy=TRUE, join.many=getOption("datatable.join.many")) {
260+
mergelist = function(l, on, cols, how=c("left", "inner", "full", "right", "semi", "anti", "cross"), mult, copy=TRUE, join.many=getOption("datatable.join.many")) {
261261
verbose = getOption("datatable.verbose")
262262
if (verbose)
263263
p = proc.time()[[3L]]
264-
{
265-
if (!is.list(l) || is.data.frame(l))
266-
stopf("'l' must be a list")
267-
if (!all(vapply_1b(l, is.data.table)))
268-
stopf("Every element of 'l' list must be data.table objects")
269-
if (!all(lengths(l)))
270-
stopf("Tables in 'l' argument must be non-zero columns tables")
271-
if (any(vapply_1i(l, function(x) anyDuplicated(names(x)))))
272-
stopf("Some of the tables in 'l' have duplicated column names")
273-
} ## l
264+
265+
if (!is.list(l) || is.data.frame(l))
266+
stopf("'%s' must be a list", "l")
267+
if (!all(vapply_1b(l, is.data.table)))
268+
stopf("Every element of 'l' list must be data.table objects")
269+
if (!all(idx <- lengths(l) > 0L))
270+
stopf("Tables in 'l' must all have columns, but these entries have 0: %s", brackify(which(!idx)))
271+
if (any(idx <- vapply_1i(l, function(x) anyDuplicated(names(x))) > 0L))
272+
stopf("Column names in individual 'l' entries must be unique, but these have some duplicates: [%s]", brackify(which(idx)))
273+
274274
if (!isTRUEorFALSE(copy))
275275
stopf("'%s' must be TRUE or FALSE", "copy")
276276
n = length(l)
277-
if (n<2L) {
278-
out = if (!n) as.data.table(l) else l[[1L]]
277+
if (n < 2L) {
278+
out = if (n) l[[1L]] else as.data.table(l)
279279
if (copy) out = copy(out)
280280
if (verbose)
281281
catf("mergelist: merging %d table(s), took %.3fs\n", n, proc.time()[[3L]]-p)
282282
return(out)
283283
}
284-
{
285-
if (!is.list(join.many))
286-
join.many = rep(list(join.many), n-1L)
287-
if (length(join.many)!=n-1L || !all(vapply_1b(join.many, isTRUEorFALSE)))
288-
stopf("'join.many' must be TRUE or FALSE, or a list of such which length must be length(l)-1L")
289-
} ## join.many
290-
{
291-
if (missing(mult))
292-
mult = NULL
293-
if (!is.list(mult))
294-
mult = rep(list(mult), n-1L)
295-
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")))))
296-
stopf("'mult' must be one of [error, all, first, last] or NULL, or a list of such which length must be length(l)-1L")
297-
} ## mult
298-
{
299-
if (missing(how) || is.null(how))
300-
how = match.arg(how)
301-
if (!is.list(how))
302-
how = rep(list(how), n-1L)
303-
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"))))
304-
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")
305-
} ## how
306-
{
307-
if (missing(cols) || is.null(cols)) {
308-
cols = vector("list", n)
309-
} else {
310-
if (!is.list(cols))
311-
stopf("'%s' must be a list", "cols")
312-
if (length(cols) != n)
313-
stopf("'cols' must be same length as 'l'")
314-
skip = vapply_1b(cols, is.null)
315-
if (!all(vapply_1b(cols[!skip], function(x) is.character(x) && !anyNA(x) && !anyDuplicated(x))))
316-
stopf("'cols' must be a list of non-zero length, non-NA, non-duplicated, character vectors, or eventually NULLs (all columns)")
317-
if (any(mapply(function(x, icols) !all(icols %chin% names(x)), l[!skip], cols[!skip])))
318-
stopf("'cols' specify columns not present in corresponding table")
319-
}
320-
} ## cols
321-
{
322-
if (missing(on) || is.null(on)) {
323-
on = vector("list", n-1L)
324-
} else {
325-
if (!is.list(on))
326-
on = rep(list(on), n-1L)
327-
if (length(on)!=n-1L || !all(vapply_1b(on, function(x) is.character(x) && !anyNA(x) && !anyDuplicated(x)))) ## length checked in dtmerge
328-
stopf("'on' must be non-NA, non-duplicated, character vector, or a list of such which length must be length(l)-1L")
329-
}
330-
} ## on
284+
285+
if (!is.list(join.many))
286+
join.many = rep(list(join.many), n - 1L)
287+
if (length(join.many) != n - 1L || !all(vapply_1b(join.many, isTRUEorFALSE)))
288+
stopf("'join.many' must be TRUE or FALSE, or a list of such whose length must be length(l)-1L")
289+
290+
if (missing(mult))
291+
mult = NULL
292+
if (!is.list(mult))
293+
mult = rep(list(mult), n - 1L)
294+
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")))))
295+
stopf("'mult' must be one of [error, all, first, last] or NULL, or a list of such whose length must be length(l)-1L")
296+
297+
if (missing(how) || is.null(how))
298+
how = match.arg(how)
299+
if (!is.list(how))
300+
how = rep(list(how), n-1L)
301+
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"))))
302+
stopf("'how' must be one of [left, inner, full, right, semi, anti, cross], or a list of such whose length must be length(l)-1L")
303+
304+
if (missing(cols) || is.null(cols)) {
305+
cols = vector("list", n)
306+
} else {
307+
if (!is.list(cols))
308+
stopf("'%s' must be a list", "cols")
309+
if (length(cols) != n)
310+
stopf("'cols' must be same length as 'l'")
311+
skip = vapply_1b(cols, is.null)
312+
if (!all(vapply_1b(cols[!skip], function(x) is.character(x) && !anyNA(x) && !anyDuplicated(x))))
313+
stopf("'cols' must be a list of non-zero length, non-NA, non-duplicated, character vectors, or eventually NULLs (all columns)")
314+
if (any(mapply(function(x, icols) !all(icols %chin% names(x)), l[!skip], cols[!skip])))
315+
stopf("'cols' specify columns not present in corresponding table")
316+
}
317+
318+
if (missing(on) || is.null(on)) {
319+
on = vector("list", n - 1L)
320+
} else {
321+
if (!is.list(on))
322+
on = rep(list(on), n - 1L)
323+
if (length(on) != n-1L || !all(vapply_1b(on, function(x) is.character(x) && !anyNA(x) && !anyDuplicated(x)))) ## length checked in dtmerge
324+
stopf("'on' must be non-NA, non-duplicated, character vector, or a list of such which length must be length(l)-1L")
325+
}
331326

332327
l.mem = lapply(l, vapply, address, "")
333328
out = l[[1L]]
334329
out.cols = cols[[1L]]
335-
for (join.i in seq_len(n-1L)) {
330+
for (join.i in seq_len(n - 1L)) {
336331
rhs.i = join.i + 1L
337332
out = mergepair(
338333
lhs = out, rhs = l[[rhs.i]],
@@ -349,7 +344,7 @@ mergelist = function(l, on, cols, how=c("left","inner","full","right","semi","an
349344
if (copy)
350345
.Call(CcopyCols, out, colnamesInt(out, names(out.mem)[out.mem %chin% unique(unlist(l.mem, recursive=FALSE))]))
351346
if (verbose)
352-
catf("mergelist: merging %d tables, took %.3fs\n", n, proc.time()[[3L]]-p)
347+
catf("mergelist: merging %d tables, took %.3fs\n", n, proc.time()[[3L]] - p)
353348
out
354349
}
355350

0 commit comments

Comments
 (0)