Skip to content

Commit 9a51230

Browse files
Update to stopf() error style
1 parent d579af4 commit 9a51230

File tree

4 files changed

+33
-39
lines changed

4 files changed

+33
-39
lines changed

R/data.table.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ replace_dot_alias = function(e) {
199199
}
200200
return(x)
201201
}
202-
if (!mult %chin% c("first","last","all","error")) stop("mult argument can only be 'first', 'last', 'all' or 'error'")
202+
if (!mult %chin% c("first", "last", "all", "error")) stopf("mult argument can only be 'first', 'last', 'all' or 'error'")
203203
missingroll = missing(roll)
204204
if (length(roll)!=1L || is.na(roll)) stopf("roll must be a single TRUE, FALSE, positive/negative integer/double including +Inf and -Inf or 'nearest'")
205205
if (is.character(roll)) {
@@ -527,9 +527,9 @@ replace_dot_alias = function(e) {
527527
!join.many))
528528
as.logical(anyDuplicated(f__, incomparables = c(0L, NA_integer_)))
529529
limit = if (!is.null(anyDups) && anyDups) { # #742. If 'i' has no duplicates, ignore
530-
if (!join.many) stop("Joining resulted in many-to-many join. Perform quality check on your data, use mult!='all', or set 'datatable.join.many' option to TRUE to allow rows explosion.")
530+
if (!join.many) stopf("Joining resulted in many-to-many join. Perform quality check on your data, use mult!='all', or set 'datatable.join.many' option to TRUE to allow rows explosion.")
531531
else if (!allow.cartesian && !notjoin) as.double(nrow(x)+nrow(i))
532-
else stop("internal error: checking allow.cartesian and join.many, unexpected else branch reached, please report to issue tracker") # nocov
532+
else internal_error("checking allow.cartesian and join.many, unexpected else branch reached") # nocov
533533
}
534534
vecseq(f__, len__, limit)
535535
} # rows in i might not match to x so old max(nrow(x),nrow(i)) wasn't enough. But this limit now only applies when there are duplicates present so the reason now for nrow(x)+nrow(i) is just to nail it down and be bigger than max(nrow(x),nrow(i)).

R/mergelist.R

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ hasindex = function(x, by, retGrp=FALSE) {
4040
# it may not copy when copy=FALSE and x is unique by 'on'
4141
fdistinct = function(x, on=key(x), mult=c("first","last"), cols=seq_along(x), copy=TRUE) {
4242
if (!perhaps.data.table(x))
43-
stop("'x' must be data.table type object")
43+
stopf("'x' must be data.table")
4444
if (!is.character(on) || !length(on) || anyNA(on) || any(!on%chin%names(x)))
45-
stop("'on' must be character column names of 'x' argument")
45+
stopf("'on' must be character column names of 'x' argument")
4646
mult = match.arg(mult)
4747
if (is.null(cols))
4848
cols = seq_along(x)
4949
else if (!(is.character(cols) || is.integer(cols)) || !length(cols) || anyNA(cols))
50-
stop("'cols' must be non-zero length, non-NA, integer or character columns of 'x' argument")
50+
stopf("'cols' must be non-zero length, non-NA, integer or character columns of 'x' argument")
5151
if (!isTRUEorFALSE(copy))
52-
stop("'copy' must be TRUE or FALSE")
52+
stopf("'%s' must be TRUE or FALSE", "copy")
5353
## do not compute sort=F for mult="first" if index (sort=T) already available, sort=T is needed only for mult="last"
5454
## this short circuit will work after #4386 because it requires retGrp=T
5555
#### sort = mult!="first" || hasindex(x, by=on, retGrp=TRUE)
@@ -62,7 +62,7 @@ fdistinct = function(x, on=key(x), mult=c("first","last"), cols=seq_along(x), co
6262
}
6363
f = attr(o, "starts", exact=TRUE)
6464
if (mult=="last") {
65-
if (!sort) stop("internal error: sort must be TRUE when computing mult='last'") # nocov
65+
if (!sort) internal_error("sort must be TRUE when computing mult='last'") # nocov
6666
f = c(f[-1L]-1L, nrow(x)) ## last of each group
6767
}
6868
if (length(o)) f = o[f]
@@ -78,18 +78,18 @@ dtmerge = function(x, i, on, how, mult, join.many, void=FALSE, verbose) {
7878
if (is.null(mult))
7979
mult = switch(how, "semi"=, "anti"= "last", "cross"= "all", "inner"=, "left"=, "right"=, "full"= "error")
8080
if (void && mult!="error")
81-
stop("internal error: void must be used with mult='error'") # nocov
81+
internal_error("void must be used with mult='error'") # nocov
8282
if (how=="cross") { ## short-circuit bmerge results only for cross join
8383
if (length(on) || mult!="all" || !join.many)
84-
stop("cross join must be used with zero-length on, mult='all', join.many=TRUE")
84+
stopf("cross join must be used with zero-length on, mult='all', join.many=TRUE")
8585
if (void)
86-
stop("internal error: cross join must be used with void=FALSE") # nocov
86+
internal_error("cross join must be used with void=FALSE") # nocov
8787
ans = list(allLen1=FALSE, starts=rep.int(1L, nrow(i)), lens=rep.int(nrow(x), nrow(i)), xo=integer())
8888
} else {
8989
if (!length(on))
90-
stop("'on' must be non-zero length character vector")
90+
stopf("'on' must be non-zero length character vector")
9191
if (mult=="all" && (how=="semi" || how=="anti"))
92-
stop("semi and anti joins must be used with mult!='all'")
92+
stopf("semi and anti joins must be used with mult!='all'")
9393
icols = colnamesInt(i, on, check_dups=TRUE)
9494
xcols = colnamesInt(x, on, check_dups=TRUE)
9595
ans = bmerge(i, x, icols, xcols, roll=0, rollends=c(FALSE, TRUE), nomatch=nomatch, mult=mult, ops=rep.int(1L, length(on)), verbose=verbose)
@@ -103,7 +103,7 @@ dtmerge = function(x, i, on, how, mult, join.many, void=FALSE, verbose) {
103103
!(length(ans$starts)==1L && ans$lens==nrow(x)) && ## special case of scalar i match to const duplicated x, not handled by anyDuplicate: data.table(x=c(1L,1L))[data.table(x=1L), on="x"]
104104
anyDuplicated(ans$starts, incomparables=c(0L,NA_integer_))
105105
)
106-
stop("Joining resulted in many-to-many join. Perform quality check on your data, use mult!='all', or set 'datatable.join.many' option to TRUE to allow rows explosion.")
106+
stopf("Joining resulted in many-to-many join. Perform quality check on your data, use mult!='all', or set 'datatable.join.many' option to TRUE to allow rows explosion.")
107107
}
108108

109109
## xrows, join-to
@@ -120,7 +120,7 @@ dtmerge = function(x, i, on, how, mult, join.many, void=FALSE, verbose) {
120120
len.x = length(xrows)
121121

122122
if (len.i!=len.x)
123-
stop("internal error: dtmerge out len.i != len.x") # nocov
123+
internal_error("dtmerge out len.i != len.x") # nocov
124124

125125
return(list(ans=ans, irows=irows, xrows=xrows))
126126
}
@@ -136,12 +136,12 @@ mergepair = function(lhs, rhs, on, how, mult, lhs.cols=names(lhs), rhs.cols=name
136136
else if (how=="right") on = key(lhs)
137137
else if (innerfull) on = onkeys(key(lhs), key(rhs))
138138
if (is.null(on))
139-
stop("'on' is missing and necessary key is not present")
139+
stopf("'on' is missing and necessary key is not present")
140140
}
141141
if (any(bad.on <- !on %chin% names(lhs)))
142-
stop(sprintf("'on' argument specify columns to join [%s] that are not present in LHS table [%s]", paste(on[bad.on], collapse=", "), paste(names(lhs), collapse=", ")))
142+
stopf("'on' argument specify columns to join [%s] that are not present in LHS table [%s]", brackify(on[bad.on]), brackify(names(lhs)))
143143
if (any(bad.on <- !on %chin% names(rhs)))
144-
stop(sprintf("'on' argument specify columns to join [%s] that are not present in RHS table [%s]", paste(on[bad.on], collapse=", "), paste(names(rhs), collapse=", ")))
144+
stopf("'on' argument specify columns to join [%s] that are not present in RHS table [%s]", brackify(on[bad.on]), brackify(names(rhs)))
145145
} else if (is.null(on)) {
146146
on = character() ## cross join only
147147
}
@@ -178,13 +178,13 @@ mergepair = function(lhs, rhs, on, how, mult, lhs.cols=names(lhs), rhs.cols=name
178178
out.x = list(); cp.x = TRUE
179179
} else {
180180
out.x = if (is.null(ans$xrows)) ## as of now xrows cannot be NULL #4409 thus nocov below
181-
stop("internal error: dtmerge()$xrows returned NULL, #4409 been resolved but related code has not been updated? please report to issue tracker") #.shallow(jnto, cols=someCols(jnto, to.cols, drop=on), retain.key=TRUE) # nocov ## as of now nocov does not make difference r-lib/covr#279
181+
internal_error("dtmerge()$xrows returned NULL, #4409 been resolved but related code has not been updated?") #.shallow(jnto, cols=someCols(jnto, to.cols, drop=on), retain.key=TRUE) # nocov ## as of now nocov does not make difference r-lib/covr#279
182182
else
183183
.Call(CsubsetDT, jnto, ans$xrows, someCols(jnto, to.cols, drop=on))
184184
cp.x = !is.null(ans$xrows)
185185
## ensure no duplicated column names in merge results
186186
if (any(dup.i<-names(out.i) %chin% names(out.x)))
187-
stop("merge result has duplicated column names, use 'cols' argument or rename columns in 'l' tables, duplicated column(s): ", paste(names(out.i)[dup.i], collapse=", "))
187+
stopf("merge result has duplicated column names, use 'cols' argument or rename columns in 'l' tables, duplicated column(s): %s", brackify(names(out.i)[dup.i]))
188188
}
189189

190190
## stack i and x
@@ -241,16 +241,16 @@ mergelist = function(l, on, cols, how=c("left","inner","full","right","semi","an
241241
p = proc.time()[[3L]]
242242
{
243243
if (!is.list(l) || is.data.frame(l))
244-
stop("'l' must be a list")
244+
stopf("'l' must be a list")
245245
if (any(!vapply(l, is.data.table, FALSE)))
246-
stop("Every element of 'l' list must be data.table objects")
246+
stopf("Every element of 'l' list must be data.table objects")
247247
if (any(!vapply(l, length, 0L)))
248-
stop("Tables in 'l' argument must be non-zero columns tables")
248+
stopf("Tables in 'l' argument must be non-zero columns tables")
249249
if (any(vapply(l, function(x) anyDuplicated(names(x)), 0L)))
250-
stop("Some of the tables in 'l' have duplicated column names")
250+
stopf("Some of the tables in 'l' have duplicated column names")
251251
} ## l
252252
if (!isTRUEorFALSE(copy))
253-
stop("'copy' must be TRUE or FALSE")
253+
stopf("'%s' must be TRUE or FALSE", "copy")
254254
n = length(l)
255255
if (n<2L) {
256256
out = if (!n) as.data.table(l) else l[[1L]]
@@ -263,37 +263,37 @@ mergelist = function(l, on, cols, how=c("left","inner","full","right","semi","an
263263
if (!is.list(join.many))
264264
join.many = rep(list(join.many), n-1L)
265265
if (length(join.many)!=n-1L || any(!vapply(join.many, isTRUEorFALSE, NA)))
266-
stop("'join.many' must be TRUE or FALSE, or a list of such which length must be length(l)-1L")
266+
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)
273273
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)))
274-
stop("'mult' must be one of [error, all, first, last] or NULL, or a list of such which length must be length(l)-1L")
274+
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)
281281
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)))
282-
stop("'how' must be one of [left, inner, full, right, semi, anti, cross], or a list of such which length must be length(l)-1L")
282+
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
{
285285
if (missing(cols) || is.null(cols)) {
286286
cols = vector("list", n)
287287
} else {
288288
if (!is.list(cols))
289-
stop("'cols' must be a list")
289+
stopf("'%s' must be a list", "cols")
290290
if (length(cols) != n)
291-
stop("'cols' must be same length as 'l'")
291+
stopf("'cols' must be same length as 'l'")
292292
skip = vapply(cols, is.null, FALSE)
293293
if (any(!vapply(cols[!skip], function(x) is.character(x) && !anyNA(x) && !anyDuplicated(x), NA)))
294-
stop("'cols' must be a list of non-zero length, non-NA, non-duplicated, character vectors, or eventually NULLs (all columns)")
294+
stopf("'cols' must be a list of non-zero length, non-NA, non-duplicated, character vectors, or eventually NULLs (all columns)")
295295
if (any(mapply(function(x, icols) any(!icols %chin% names(x)), l[!skip], cols[!skip])))
296-
stop("'cols' specify columns not present in corresponding table")
296+
stopf("'cols' specify columns not present in corresponding table")
297297
}
298298
} ## cols
299299
{
@@ -303,7 +303,7 @@ mergelist = function(l, on, cols, how=c("left","inner","full","right","semi","an
303303
if (!is.list(on))
304304
on = rep(list(on), n-1L)
305305
if (length(on)!=n-1L || any(!vapply(on, function(x) is.character(x) && !anyNA(x) && !anyDuplicated(x), NA))) ## length checked in dtmerge
306-
stop("'on' must be non-NA, non-duplicated, character vector, or a list of such which length must be length(l)-1L")
306+
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
309309

src/data.table.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ SEXP coerceAs(SEXP x, SEXP as, SEXP copyArg);
262262
int NROW(SEXP x);
263263
int NCOL(SEXP x);
264264
bool isDataTable(SEXP x);
265-
bool isDataFrame(SEXP x);
266265
bool isDataList(SEXP x);
267266
bool perhapsDataTable(SEXP x);
268267
SEXP perhapsDataTableR(SEXP x);

src/utils.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,6 @@ bool isDataTable(SEXP x) {
489489
return INHERITS(x, char_datatable);
490490
}
491491

492-
// inherits(x, "data.frame")
493-
bool isDataFrame(SEXP x) {
494-
return INHERITS(x, char_dataframe);
495-
}
496-
497492
// if (length(x)>1L) length(unique(vapply(x, length, 0L)))==1L else TRUE
498493
static inline bool equalLens(SEXP x) {
499494
int n = LENGTH(x);

0 commit comments

Comments
 (0)