Skip to content

Commit 214f93a

Browse files
committed
introduced teh changes
1 parent ac9d594 commit 214f93a

File tree

2 files changed

+24
-32
lines changed

2 files changed

+24
-32
lines changed

R/merge.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ merge.data.table = function(x, y, by = NULL, by.x = NULL, by.y = NULL, all = FAL
1717
if (x0 && y0)
1818
warningf("Neither of the input data.tables to join have columns.")
1919
else if (x0)
20-
warningf("Input data.table '%s' has no columns.", "x")
20+
warningf("Input data.table x has no columns.")
2121
else
22-
warningf("Input data.table '%s' has no columns.", "y")
22+
warningf("Input data.table y has no columns.")
2323
}
2424
check_duplicate_names(x)
2525
check_duplicate_names(y)
@@ -29,20 +29,20 @@ merge.data.table = function(x, y, by = NULL, by.x = NULL, by.y = NULL, all = FAL
2929

3030
## set up 'by'/'by.x'/'by.y'
3131
if ( (!is.null(by.x) || !is.null(by.y)) && length(by.x)!=length(by.y) )
32-
stopf("`by.x` and `by.y` must be of same length.")
32+
stopf("by.x and by.y must be of same length.")
3333
if (!missing(by) && !missing(by.x))
34-
warningf("Supplied both `by` and `by.x/by.y`. `by` argument will be ignored.")
34+
warningf("Supplied both by and by.x/by.y. by argument will be ignored.")
3535
if (!is.null(by.x)) {
3636
if (length(by.x)==0L || !is.character(by.x) || !is.character(by.y))
37-
stopf("A non-empty vector of column names is required for `by.x` and `by.y`.")
37+
stopf("A non-empty vector of column names is required for by.x and by.y.")
3838
if (!all(by.x %chin% nm_x)) {
3939
missing_in_x <- setdiff(by.x, nm_x)
40-
stopf("The following columns listed in `by.x` are missing from `x`: %s",
40+
stopf("The following columns listed in by.x are missing from x: %s",
4141
toString(missing_in_x))
4242
}
4343
if (!all(by.y %chin% nm_y)) {
4444
missing_in_y <- setdiff(by.y, nm_y)
45-
stopf("The following columns listed in `by.y` are missing from `y`: %s",
45+
stopf("The following columns listed in by.y are missing from y: %s",
4646
toString(missing_in_y))
4747
}
4848
by = by.x
@@ -55,13 +55,13 @@ merge.data.table = function(x, y, by = NULL, by.x = NULL, by.y = NULL, all = FAL
5555
if (!length(by))
5656
by = intersect(nm_x, nm_y)
5757
if (length(by) == 0L || !is.character(by))
58-
stopf("A non-empty vector of column names for `by` is required.")
58+
stopf("A non-empty vector of column names for by is required.")
5959
missing_in_x <- setdiff(by, nm_x)
6060
missing_in_y <- setdiff(by, nm_y)
6161
if (length(missing_in_x) > 0 || length(missing_in_y) > 0) {
62-
stopf("The following columns are missing:\n%s%s",
63-
if (length(missing_in_x) > 0) sprintf(" - From `x`: %s\n", toString(missing_in_x)) else "",
64-
if (length(missing_in_y) > 0) sprintf(" - From `y`: %s\n", toString(missing_in_y)) else "")
62+
stopf("The following columns are missing:%s%s",
63+
if (length(missing_in_x) > 0) sprintf(" - From x: %s", toString(missing_in_x)) else "",
64+
if (length(missing_in_y) > 0) sprintf(" - From y: %s", toString(missing_in_y)) else "")
6565
}
6666
by = unname(by)
6767
by.x = by.y = by

inst/tests/tests.Rraw

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8569,18 +8569,18 @@ test(1601.1, merge(DT1, DT1, by="a"), data.table(a=1, key="a"))
85698569

85708570
# Test 1601.2: Merge DT1 with DT0 on column 'a'
85718571
test(1601.2, merge(DT1, DT0, by="a"),
8572-
warning="Input data.table 'y' has no columns.",
8573-
error="The following columns are missing:\n - From `y`: a")
8572+
warning="Input data.table y has no columns.",
8573+
error="The following columns are missing: - From y: a")
85748574

85758575
# Test 1601.3: Merge DT0 with DT1 on column 'a'
85768576
test(1601.3, merge(DT0, DT1, by="a"),
8577-
warning="Input data.table 'x' has no columns.",
8578-
error="The following columns are missing:\n - From `x`: a")
8577+
warning="Input data.table x has no columns.",
8578+
error="The following columns are missing: - From x: a")
85798579

85808580
# Test 1601.4: Merge DT0 with DT0 on column 'a'
85818581
test(1601.4, merge(DT0, DT0, by="a"),
85828582
warning="Neither of the input data.tables to join have columns.",
8583-
error="The following columns are missing:\n - From `x`: a\n - From `y`: a")
8583+
error="The following columns are missing: - From x: a - From y: a")
85848584

85858585
# fix for #1549
85868586
d1 <- data.table(v1=1:2,x=x)
@@ -13528,20 +13528,12 @@ test(1962.016, merge(DT1, DT2, by.x = 'a', by.y = c('a', 'V')),
1352813528
test(1962.017, merge(DT1, DT2, by = 'V', by.x = 'a', by.y = 'a'),
1352913529
data.table(a = 2:3, V.x = c("a", "a"), V.y = c("b", "b"), key = 'a'),
1353013530
warning = 'Supplied both.*argument will be ignored')
13531-
test(1962.018, {
13532-
if (!"z" %in% colnames(DT1)) {
13533-
stop("Elements listed in `by.x` are missing from x: z")
13534-
}
13535-
merge(DT1, DT2, by.x = 'z', by.y = 'a')
13536-
}, error = 'Elements listed in `by.x` are missing from x: z')
13537-
13538-
test(1962.019, {
13539-
if (!"z" %in% colnames(DT2)) {
13540-
stop("Elements listed in `by.y` are missing from y: z")
13541-
}
13542-
merge(DT1, DT2, by.x = 'a', by.y = 'z')
13543-
}, error = 'Elements listed in `by.y` are missing from y: z')
13544-
13531+
test(1962.018,
13532+
merge(DT1, DT2, by.x = 'z', by.y = 'a'),
13533+
error = 'The following columns listed in by.x are missing from x: z')
13534+
test(1962.019,
13535+
merge(DT1, DT2, by.x = 'a', by.y = 'z'),
13536+
error = 'The following columns listed in by.y are missing from y: z')
1354513537
test(1962.0201, merge(DT1, DT2, by=character(0L)), ans) # was error before PR#5183
1354613538
test(1962.0202, merge(DT1, DT2, by=NULL), ans) # test explicit NULL too as missing() could be used inside merge()
1354713539
test(1962.021, {
@@ -16927,7 +16919,7 @@ test(2144, rbind(DT,list(c=4L,a=7L)), error="Column 1 ['c'] of item 2 is missing
1692716919
A = data.table(A='a')
1692816920
B = data.table(B='b')
1692916921
test(2145.1, A[B, on=character(0)], error = "'on' argument should be a named atomic vector")
16930-
test(2145.2, merge(A, B, by=character(0) ), error = "non-empty vector of column names for `by` is required.")
16922+
test(2145.2, merge(A, B, by=character(0) ), error = "A non-empty vector of column names for by is required.")
1693116923
test(2145.3, merge(A, B, by.x=character(0), by.y=character(0)), error = "non-empty vector of column names is required")
1693216924
# Also shouldn't crash when using internal functions
1693316925
test(2145.4, bmerge(A, B, integer(), integer(), 0, c(FALSE, TRUE), NA, 'all', integer(), FALSE), error = 'icols and xcols must be non-empty')
@@ -18010,7 +18002,7 @@ test(2230.4, setDF(merge(DT, y, by="k2", incomparables=c(1, NA, 4, 5))), merge(x
1801018002
test(2230.5, setDF(merge(DT, y, by="k2", incomparables=c(NA, 3, 4, 5))), merge(x, y, by="k2", incomparables=c(NA,3,4,5)))
1801118003
test(2230.6, merge(DT, y, by="k2", unk=1), merge(DT, y, by="k2"), warning="Unknown argument 'unk' has been passed.")
1801218004
test(2230.7, merge(DT, y, by="k2", NULL, NULL, FALSE, FALSE, FALSE, TRUE, c(".x", ".y"), TRUE, getOption("datatable.allow.cartesian"), NULL, 1L),
18013-
merge(DT, y, by="k2"), warning=c("Supplied both `by` and `by.x/by.y`. `by` argument will be ignored.", "Passed 1 unknown and unnamed arguments."))
18005+
merge(DT, y, by="k2"), warning=c("Supplied both by and by.x/by.y. by argument will be ignored.", "Passed 1 unknown and unnamed arguments."))
1801418006

1801518007
# weighted.mean GForce optimized, #3977
1801618008
old = options(datatable.optimize=1L)

0 commit comments

Comments
 (0)