Skip to content

Commit 6913d5c

Browse files
push logic into helper to tidy up merge body
1 parent 514d963 commit 6913d5c

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

R/merge.R

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,8 @@ merge.data.table = function(x, y, by = NULL, by.x = NULL, by.y = NULL, all = FAL
6363
}
6464

6565
# warn about unused arguments #2587
66-
# TODO(R >= 3.5.0): use ...length()
67-
if (n_dots <- length(dots <- list(...))) {
68-
if (is.null(nm <- names(dots))) {
69-
warningf(ngettext(n_dots, "merge.data.table() received %d unnamed argument in '...' which will be ignored.",
70-
"merge.data.table() received %d unnamed arguments in '...' which will be ignored."),
71-
n_dots)
72-
} else {
73-
named_idx = nzchar(nm)
74-
if (all(named_idx)) {
75-
warningf(ngettext(n_dots, "merge.data.table() received %d unknown keyword argument which will be ignored: %s",
76-
"merge.data.table() received %d unknown keyword arguments which will be ignored: %s"),
77-
n_dots, brackify(nm))
78-
} else {
79-
n_named <- sum(named_idx)
80-
unnamed_clause <- sprintf(ngettext(n_dots - n_named, "%d unnamed argument in '...'", "%d unnamed arguments in '...'"), n_dots - n_named)
81-
named_clause <- sprintf(ngettext(n_named, "%d unknown keyword argument", "%d unknown keyword arguments"), n_named)
82-
warningf("merge.data.table() received %s and %s, all of which will be ignored: %s", unnamed_clause, named_clause, brackify(nm[named_idx]))
83-
}
84-
}
85-
}
66+
.maybe_warn_merge_dots(...)
67+
8668
# with i. prefix in v1.9.3, this goes away. Left here for now ...
8769
## sidestep the auto-increment column number feature-leading-to-bug by
8870
## ensuring no names end in ".1", see unit test
@@ -138,3 +120,28 @@ merge.data.table = function(x, y, by = NULL, by.x = NULL, by.y = NULL, all = FAL
138120
setattr(dt, "class", class_x)
139121
dt
140122
}
123+
124+
.maybe_warn_merge_dots <- function(...) {
125+
# TODO(R >= 3.5.0): use ...length()
126+
n_dots <- length(dots <- list(...))
127+
if (!n_dots) return(invisible())
128+
129+
nm <- names(dots)
130+
if (is.null(nm)) {
131+
warningf(ngettext(n_dots, "merge.data.table() received %d unnamed argument in '...' which will be ignored.",
132+
"merge.data.table() received %d unnamed arguments in '...' which will be ignored."),
133+
n_dots)
134+
} else {
135+
named_idx = nzchar(nm)
136+
if (all(named_idx)) {
137+
warningf(ngettext(n_dots, "merge.data.table() received %d unknown keyword argument which will be ignored: %s",
138+
"merge.data.table() received %d unknown keyword arguments which will be ignored: %s"),
139+
n_dots, brackify(nm))
140+
} else {
141+
n_named <- sum(named_idx)
142+
unnamed_clause <- sprintf(ngettext(n_dots - n_named, "%d unnamed argument in '...'", "%d unnamed arguments in '...'"), n_dots - n_named)
143+
named_clause <- sprintf(ngettext(n_named, "%d unknown keyword argument", "%d unknown keyword arguments"), n_named)
144+
warningf("merge.data.table() received %s and %s, all of which will be ignored: %s", unnamed_clause, named_clause, brackify(nm[named_idx]))
145+
}
146+
}
147+
}

0 commit comments

Comments
 (0)