diff --git a/inst/tests/nafill.Rraw b/inst/tests/nafill.Rraw index 1e5107fb71..e8ea3d7eec 100644 --- a/inst/tests/nafill.Rraw +++ b/inst/tests/nafill.Rraw @@ -132,15 +132,15 @@ test(4.03, colnamesInt(dt, 1), 1L) test(4.04, colnamesInt(dt, c("a","d")), c(1L, 3L)) test(4.05, colnamesInt(dt, c(1L, 3L)), c(1L, 3L)) test(4.06, colnamesInt(dt, c(1, 3)), c(1L, 3L)) -test(4.07, colnamesInt(dt, c("a", "e")), error="specify non existing column*.*e") -test(4.08, colnamesInt(dt, c(1L, 4L)), error="specify non existing column*.*4") -test(4.09, colnamesInt(dt, c(1, 4)), error="specify non existing column*.*4") -test(4.10, colnamesInt(dt, c("a", NA)), error="specify non existing column*.*NA") -test(4.11, colnamesInt(dt, c(1L, NA)), error="specify non existing column") -test(4.12, colnamesInt(dt, c(1, NA)), error="specify non existing column") -test(4.13, colnamesInt(dt, c("a","d","a"), check_dups=TRUE), error="specify duplicated column") -test(4.14, colnamesInt(dt, c(1L, 3L, 1L), check_dups=TRUE), error="specify duplicated column") -test(4.15, colnamesInt(dt, c(1, 3, 1), check_dups=TRUE), error="specify duplicated column") +test(4.07, colnamesInt(dt, c("a", "e")), error="received non-existing column*.*e") +test(4.08, colnamesInt(dt, c(1L, 4L)), error="received non-existing column*.*4") +test(4.09, colnamesInt(dt, c(1, 4)), error="received non-existing column*.*4") +test(4.10, colnamesInt(dt, c("a", NA)), error="received non-existing column*.*NA") +test(4.11, colnamesInt(dt, c(1L, NA)), error="received non-existing column") +test(4.12, colnamesInt(dt, c(1, NA)), error="received non-existing column") +test(4.13, colnamesInt(dt, c("a","d","a"), check_dups=TRUE), error="received duplicate column(s)") +test(4.14, colnamesInt(dt, c(1L, 3L, 1L), check_dups=TRUE), error="received duplicate column(s)") +test(4.15, colnamesInt(dt, c(1, 3, 1), check_dups=TRUE), error="received duplicate column(s)") test(4.16, colnamesInt(dt, list("a")), error="must be character or numeric") test(4.17, colnamesInt(dt, NA), error="must be character or numeric") test(4.18, colnamesInt(dt, character()), integer()) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 86c5c95f63..a9eb68ab09 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -1529,11 +1529,11 @@ DT = data.table(a=1:2,b=3:4,c=5:6) test(495.1, setcolorder(DT,c(2,1,3)), data.table(b=3:4,a=1:2,c=5:6)) test(495.2, setcolorder(DT,c(2,1,3)), data.table(a=1:2,b=3:4,c=5:6)) test(496, setcolorder(DT,c("c","a","b")), data.table(c=5:6,a=1:2,b=3:4)) -test(497.01, setcolorder(DT,c("d","a","b")), error="specify non existing column*.*d") +test(497.01, setcolorder(DT,c("d","a","b")), error="received non-existing column*.*d") DT = data.table(a = 1:3, b = 2:4, c = 3:5) test(497.02, names(setcolorder(DT, "b")), c("b", "a", "c")) test(497.03, names(setcolorder(DT, c(2, 3))), c("a", "c", "b")) -test(497.04, setcolorder(DT, 1:4), error = "specify non existing column*.*4") +test(497.04, setcolorder(DT, 1:4), error = "received non-existing column*.*4") # Test where neworder=NULL, thus ordered by key and index columns DT = data.table(a = 1:3, b = 2:4, c = 3:5, d = 4:6, key="b") test(497.05, names(setcolorder(DT)), c("b", "a", "c", "d")) @@ -2867,10 +2867,10 @@ test(988, unique(dt, by='B'), dt[!duplicated(df[, 'B'])]) test(989, unique(dt, by='C'), dt[!duplicated(df[, 'C'])]) test(990, unique(dt, by=c('B', 'C')), dt[!duplicated(df[, c('B', 'C')])]) test(991, unique(dt, by=NULL), dt[!duplicated(df)]) -test(991.1, unique(dt, by=4), error="specify non existing column*.*4") +test(991.1, unique(dt, by=4), error="received non-existing column*.*4") test(991.2, unique(dt, by=c(1,3.1)), error="is type 'double' and one or more items in it are not whole integers") test(991.3, unique(dt, by=2:3), dt[!duplicated(df[,c('B','C')])]) -test(991.4, unique(dt, by=c('C','D','E')), error="specify non existing column*.*D") +test(991.4, unique(dt, by=c('C','D','E')), error="received non-existing column*.*D") # :=NULL on factor column in empty data.table, #114 DT = data.table(A = integer(), B = factor()) @@ -2916,7 +2916,7 @@ test(996.07, CJ(1:2, list(1:2, 3), 4:5, sorted = FALSE), data.table(V1 = rep(1:2, each = 4L), V2 = rep(rep(list(1:2, 3), each = 2L), 2L), V3 = rep(4:5, 4L))) test(996.08, CJ(expression(1)), error = "element 1 is non-atomic") -test(996.09, CJ(expression(2), 3, sorted = FALSE), error = "Type 'expression' not supported") +test(996.09, CJ(expression(2), 3, sorted = FALSE), error = "Type 'expression' is not supported") ## complex input support (can't handle sorted yet) test(996.10, CJ(z = 0:1 + (0:1)*1i, b = 1:3, sorted = FALSE), data.table(z = rep(0:1, each=3L) + rep(0:1, each=3L)*1i, b = rep(1:3, 2))) @@ -4285,7 +4285,7 @@ setNumericRounding(old_rounding) DT = data.table(id=INT(1,2,1), val1=3:1, val2=3:1, val3=list(2:3,4:6,7:10)) # 5380 test(1199.1, DT[, sum(.SD), by=id, .SDcols=2:3], data.table(id=1:2, V1=INT(8,4))) #875 made the .SD case work test(1199.2, DT[, sum(.SD), by=id], error="data.*frame.*numeric") # this is R's error message so use flexible string pattern to insulate from minor changes in R, #4769 -test(1199.3, DT[, sum(val3), by=id], error="Type 'list' not supported by GForce sum [(]gsum[)]. Either.*or turn off") +test(1199.3, DT[, sum(val3), by=id], error="Type 'list' is not supported by GForce sum [(]gsum[)]. Either.*or turn off") # Selection of columns, copy column to maintain the same as R <= 3.0.2, in Rdevel, for now # Otherwise e.g. setkey changes the original columns too. TO DO: could allow shallow copy, perhaps. @@ -5571,7 +5571,7 @@ setDF(Y) test(1364.18, setdiff_(X, Y), error = 'x and y must both be data.tables') setDT(Y) test(1364.19, setdiff_(X[0L], Y), X[0L]) -test(1364.20, setdiff_(X, Y, by.x = 'f'), error = 'specify non existing column*.*f') +test(1364.20, setdiff_(X, Y, by.x = 'f'), error = 'received non-existing column*.*f') #test(1364.21, setdiff_(X, Y, by.x = c('f', 'g')), error = 'by.x values [f, g] not present') # now only first no existing column is printed for efficiency test(1364.22, setdiff_(X, Y[0L], by.x = 'a'), data.table(a = c(1, 3, 2), b = factor(c(1L, 3L, 2L)), @@ -6669,13 +6669,13 @@ test(1464.03, rleidv(DT, "b"), c(1L, 1L, 2L, 2L, 3L, 3L, 3L, 4L, 5L, 5L)) test(1464.04, rleid(DT$b), c(1L, 1L, 2L, 2L, 3L, 3L, 3L, 4L, 5L, 5L)) test(1464.05, rleidv(DT, "c"), c(1L, 1L, 2L, 2L, 3L, 3L, 3L, 4L, 5L, 5L)) test(1464.06, rleid(DT$c), c(1L, 1L, 2L, 2L, 3L, 3L, 3L, 4L, 5L, 5L)) -test(1464.07, rleid(as.raw(c(3L, 1L, 2L))), error="Type 'raw' not supported") -test(1464.08, rleidv(DT, 0), error="specify non existing column*.*0") -test(1464.09, rleidv(DT, 5), error="specify non existing column*.*5") +test(1464.07, rleid(as.raw(c(3L, 1L, 2L))), error="Type 'raw' is not supported") +test(1464.08, rleidv(DT, 0), error="received non-existing column*.*0") +test(1464.09, rleidv(DT, 5), error="received non-existing column*.*5") test(1464.10, rleidv(DT, 1:4), 1:nrow(DT)) set.seed(1) DT = data.table( sample(1:2,20,replace=TRUE), sample(1:2,20,replace=TRUE), sample(1:2,20, replace=TRUE)) -test(1464.11, rleidv(DT, 1:4), error="specify non existing column*.*4") +test(1464.11, rleidv(DT, 1:4), error="received non-existing column*.*4") test(1464.12, rleidv(DT, 1:2), ans<-INT(1,2,3,4,5,6,6,6,7,8,8,9,10,11,12,13,14,15,16,17)) test(1464.13, rleidv(DT, 2:1), ans) test(1464.14, rleidv(DT, c(3,1)), INT(1,1,2,2,3,4,5,5,6,7,8,9,10,11,12,13,14,15,16,17)) @@ -8038,8 +8038,8 @@ test(1574.4, X["bar", on="c"], X[2L]) # missed previously # fix for #1376 X = data.table(a=1:3,b=4:6,c=c("foo","bar","baz")) Y = data.table(A=2:4, B=5:7) -test(1575.1, X[Y, on=c(A="a")], error="specify non existing column*.*A") # does not report 'x' or 'i' anymore after switch to colnamesInt -test(1575.2, X[Y, on=c(a="a")], error="specify non existing column*.*a") +test(1575.1, X[Y, on=c(A="a")], error="received non-existing column*.*A") # does not report 'x' or 'i' anymore after switch to colnamesInt +test(1575.2, X[Y, on=c(a="a")], error="received non-existing column*.*a") # work around for issue introduced in v1.9.4, #1396 X = data.table(x=5:1, y=6:10) @@ -13491,10 +13491,11 @@ DT = data.table(x = c(1, 1, 3, 2), key = 'x') test(1962.003, duplicated(DT, fromLast = NA), error = 'must be TRUE or FALSE') test(1962.004, duplicated(DT, by = -1L), - error = 'specify non existing column*.*-1') + error = 'received non-existing column*.*-1') test(1962.005, duplicated(DT, by = 'y'), - error = 'specify non existing column*.*y') -test(1962.006, duplicated(data.table(NULL)), logical(0L)) + error = 'received non-existing column*.*y') +test(1962.0061, duplicated(data.table(NULL)), logical(0L)) +test(1962.0062, duplicated(data.table(a = 1L), by = character()), FALSE) test(1962.007, unique(DT, incomparables = TRUE), error = 'not used (yet)') @@ -13763,7 +13764,7 @@ test(1963.07, shift(DT, -1:1), c(NA, 10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L))) ## some coverage tests for good measure test(1963.08, shift(DT$x, type = 'some_other_type'), error='should be one of.*lag.*lead') -test(1963.09, shift(as.raw(0:1)), error = 'Unsupported type') +test(1963.09, shift(as.raw(0:1)), error = "Type 'raw' is not supported") test(1963.10, shift(DT, -1:1, type="shift", give.names = TRUE), # new type="shift" #3223 ans <- list(`x_shift_-1` = c(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, NA), x_shift_0 = 1:10, @@ -13961,7 +13962,7 @@ test(1967.621, setnames(x, 1:2, c("a","a")), data.table(a=1:5, a=6:10)) test(1967.622, setnames(x, 1:2, c("a",NA)), error = "NA in 'new' at positions [2]") test(1967.63, setcolorder(x, c(1, 1)), error = 'Item 2 of order (1) is either NA, out of range [1,2], or is duplicated. The new order must be a strict permutation of 1:n') test(1967.64, setcolorder(x, 1+3i), error = 'must be character or numeric') -test(1967.65, setcolorder(x, 300), error = 'specify non existing column*.*300') +test(1967.65, setcolorder(x, 300), error = 'received non-existing column*.*300') test(1967.66, rbindlist(list(x), idcol = FALSE), rbindlist(list(x))) test(1967.67, rbindlist(list(x), idcol = 1+3i), error = 'idcol must be a logical') @@ -14196,7 +14197,7 @@ dimnames(DT) <- list(NULL, 1:5) test(1984.21, names(DT), paste0(1:5)) DT = data.table(a = 1:10) test(1984.22, na.omit(DT, invert = 'a'), error="'invert' must be logical") -test(1984.23, na.omit(DT, cols = 'b'), error="specify non existing column*.*b") +test(1984.23, na.omit(DT, cols = 'b'), error="received non-existing column*.*b") #test(1984.24, na.omit(DT, cols = c('b', 'c')), error="Columns [b, c] don't") # only first non-existing col is now reported for efficiency test(1984.242, na.omit(data.table(A=c(1,NA,2)), cols=character()), data.table(A=c(1,NA,2))) #2514 ### idcol = TRUE behavior of rbindlist @@ -14732,15 +14733,15 @@ if (test_bit64) { test(2019, DT[2:6, sum(v), id], data.table(id=1:2, V1=bit64::as.integer64(c(5L,15L)))) # gather, case of int64 and irows } DT = data.table(id = c(1L,1L,2L), v = as.raw(0:2)) -test(2020.01, DT[, min(v), by=id], error="'raw' not supported by GForce min/max") -test(2020.02, DT[, max(v), by=id], error="'raw' not supported by GForce min/max") -test(2020.03, DT[, median(v), by=id], error="'raw' not supported by GForce median") -test(2020.04, DT[, head(v, 1), by=id], error="'raw' not supported by GForce head/tail/first/last/`[`") -test(2020.05, DT[, tail(v, 1), by=id], error="'raw' not supported by GForce head/tail/first/last/`[`") -test(2020.06, DT[, v[1], by=id], error="'raw' not supported by GForce head/tail/first/last/`[`") -test(2020.07, DT[, sd(v), by=id], error="'raw' not supported by GForce sd") -test(2020.08, DT[, var(v), by=id], error="'raw' not supported by GForce var") -test(2020.09, DT[, prod(v), by=id], error="'raw' not supported by GForce prod") +test(2020.01, DT[, min(v), by=id], error="'raw' is not supported by GForce min") +test(2020.02, DT[, max(v), by=id], error="'raw' is not supported by GForce max") +test(2020.03, DT[, median(v), by=id], error="'raw' is not supported by GForce median") +test(2020.04, DT[, head(v, 1), by=id], error="'raw' is not supported by GForce head/tail/first/last/`[`") +test(2020.05, DT[, tail(v, 1), by=id], error="'raw' is not supported by GForce head/tail/first/last/`[`") +test(2020.06, DT[, v[1], by=id], error="'raw' is not supported by GForce head/tail/first/last/`[`") +test(2020.07, DT[, sd(v), by=id], error="'raw' is not supported by GForce sd") +test(2020.08, DT[, var(v), by=id], error="'raw' is not supported by GForce var") +test(2020.09, DT[, prod(v), by=id], error="'raw' is not supported by GForce prod") DT = data.table(id = c(1L,1L,2L,2L), v = c(1L, 2L, NA, NA)) test(2020.10, DT[, median(v), id], data.table(id=1:2, V1=c(1.5, NA))) # median whole group has NAs @@ -15722,7 +15723,7 @@ test(2060.208, fcoalesce(fkt, 'b'), error='Item 1 is a factor but item 2 is not test(2060.209, fcoalesce(str, factor('b')), error='Item 2 is a factor but item 1 is not a factor. When factors are involved, all items must be factor') test(2060.212, fcoalesce(list(1), list(2)), error="The first argument is a list, data.table or data.frame. In this case there should be no other arguments provided.") test(2060.213, fcoalesce(bool, c(TRUE, FALSE)), error="Item 2 is length 2 but the first item is length 3. Only singletons are recycled") -test(2060.214, fcoalesce(as.raw(0), as.raw(1)), error="Unsupported type: raw") +test(2060.214, fcoalesce(as.raw(0), as.raw(1)), error="Type 'raw' is not supported") test(2060.215, fcoalesce(bool, list()), bool) test(2060.216, fcoalesce(structure(c(1:2,NA,4L), class=c("a")), c(NA,NA,3L,4L)),, error="Item 2 has a different class than item 1") # different classes of x arg #3660 @@ -15949,7 +15950,7 @@ DT1 = data.table(a = sample(3L, 15L, TRUE) + .1, b=sample(c(TRUE, FALSE, NA), 15 DT2 = data.table(a = sample(3L, 6L, TRUE) + .1, b=sample(c(TRUE, FALSE, NA), 6L, TRUE)) test(2069.32, DT1[DT2, .(y = sum(b, na.rm=TRUE)), by=.EACHI, on=c(a = 'a', b="b")]$y, rep(0L, 6L)) DT = data.table(z = 1i) -test(2069.33, DT[DT, on = 'z'], error = "Type 'complex' not supported for joining/merging") +test(2069.33, DT[DT, on = 'z'], error = "Type 'complex' is not supported for joining/merging") # forder verbose message when !isReallyReal Date, #1738 DT = data.table(d=sample(seq(as.Date("2015-01-01"), as.Date("2015-01-05"), by="days"), 20, replace=TRUE)) @@ -16019,7 +16020,7 @@ test(2072.036, fifelse(test_vec_na, 1+0i, 0+0i), as.complex(out_vec_na)) test(2072.037, fifelse(test_vec_na, rep(1+0i,12L), 0+0i), as.complex(out_vec_na)) test(2072.038, fifelse(test_vec_na, rep(1+0i,12L), rep(0+0i,12L)), as.complex(out_vec_na)) test(2072.039, fifelse(test_vec_na, 1+0i, rep(0+0i,12L)), as.complex(out_vec_na)) -test(2072.040, fifelse(test_vec, as.raw(0), as.raw(1)), error="Type raw is not supported.") +test(2072.040, fifelse(test_vec, as.raw(0), as.raw(1)), error="Type 'raw' is not supported") test(2072.041, fifelse(TRUE,1,as.Date("2019-07-07")), error="'yes' has different class than 'no'. Please") test(2072.042, fifelse(TRUE,1L,factor(letters[1])), error="'yes' has different class than 'no'. Please") test(2072.043, fifelse(TRUE, list(1:5), list(5:1)), list(1:5)) @@ -16958,7 +16959,7 @@ test(2127.13, fcase(test_vec1, 1+0i, test_vec2, 0+0i, default=2+0i), as.complex( test(2127.14, fcase(test_vec1, list(1), test_vec2, list(0),default=list(2)), list(1,1,1,1,1, 2, 0, 0, 0, 0, 0)) test(2127.15, fcase(test_vec1, as.Date("2019-10-11"), test_vec2, as.Date("2019-10-14"),default=as.Date("2019-10-15")), c(rep(as.Date("2019-10-11"),5),as.Date("2019-10-15"),rep(as.Date("2019-10-14"),5))) test(2127.16, fcase(test_vec1, factor("a", levels=letters[1:3]), test_vec2, factor("b", levels=letters[1:3]),default=factor("c", levels=letters[1:3])), factor(c(rep("a",5),"c",rep("b",5)), levels=letters[1:3])) -test(2127.17, fcase(test_vec1, as.raw(1), test_vec2, as.raw(0)), error="Type raw is not supported.") +test(2127.17, fcase(test_vec1, as.raw(1), test_vec2, as.raw(0)), error="Type 'raw' is not supported") test(2127.18, fcase(test_vec1, factor("a", levels=letters[1]), test_vec2, factor("b", levels=letters[1:3])), error="Argument #2 and argument #4 are both factor but their levels are different.") test(2127.19, fcase(test_vec1, factor("a", levels=letters[1:2]), test_vec2, factor("b", levels=letters[1:2]),default=factor("c", levels=letters[1:3])), error="Resulting value and 'default' are both type factor but their levels are different.") test(2127.20, fcase(test_vec1, 1L:10L, test_vec2, 3L:12L, test_vec2), error="Received 5 inputs; please supply an even number of arguments in ..., consisting of logical condition, resulting value pairs (in that order). Note that the default argument must be named explicitly, e.g., default=0") @@ -17659,7 +17660,7 @@ test(2182.6, melt(DT.wide, measure.vars=list(b=c("b1","b2"))), data.table(a2=2, measurev = function(cols)cols # user-defined function for computing measure.vars, same name as data.table::measure but user-defined version should be used. test(2183.00001, melt(DT.wide, measure.vars=measurev()), data.table(variable=factor(c("a2","b1","b2")), value=c(2,1,2))) measurev = list("foo", "bar")#measurev below should not use this since it is not a function. -test(2183.00002, melt(DTid, measure.vars=measurev(list(value.name=NULL, num=as.complex), pattern="([ab])([12])")), error="Type 'complex' not supported for joining/merging") +test(2183.00002, melt(DTid, measure.vars=measurev(list(value.name=NULL, num=as.complex), pattern="([ab])([12])")), error="Type 'complex' is not supported for joining/merging") test(2183.00004, melt(DTid, measure.vars=measurev(list(value.name=NULL, istr=NULL), pattern="([ab])([12])"))[order(b)], data.table(id=1, istr=paste(c(1,2)), a=c(NA, 2), b=c(1,2))) test(2183.00005, melt(DTid, measure.vars=measurev(list(column=NULL, istr=NULL), pattern="([ab])([12])", multiple.keyword="column"))[order(b)], data.table(id=1, istr=paste(c(1,2)), a=c(NA, 2), b=c(1,2)))#same computation but different multiple.keyword iris.dt = data.table(datasets::iris) @@ -17682,7 +17683,7 @@ test(2183.00060, melt(DTid, measure.vars=measurev(list(letter=myfac, value.name= measure = function(cols)cols # user-defined function for computing measure.vars, same name as data.table::measure but user-defined version should be used. test(2183.01, melt(DT.wide, measure.vars=measure()), data.table(variable=factor(c("a2","b1","b2")), value=c(2,1,2))) measure = list("foo", "bar")#measure below should not use this since it is not a function. -test(2183.02, melt(DTid, measure.vars=measure(value.name, num=as.complex, pattern="([ab])([12])")), error="Type 'complex' not supported for joining/merging") +test(2183.02, melt(DTid, measure.vars=measure(value.name, num=as.complex, pattern="([ab])([12])")), error="Type 'complex' is not supported for joining/merging") test(2183.03, melt(DTid, measure.vars=structure(list(a=c(NA,"a2"),b=c("b1","b2")), variable_table=data.table(number=as.complex(1:2)))), error="variable_table does not support column type 'complex' for column 'number'") test(2183.04, melt(DTid, measure.vars=measure(value.name, istr, pattern="([ab])([12])"))[order(b)], data.table(id=1, istr=paste(c(1,2)), a=c(NA, 2), b=c(1,2))) test(2183.05, melt(DTid, measure.vars=measure(column, istr, pattern="([ab])([12])", multiple.keyword="column"))[order(b)], data.table(id=1, istr=paste(c(1,2)), a=c(NA, 2), b=c(1,2)))#same computation but different multiple.keyword diff --git a/src/assign.c b/src/assign.c index c84ca276a5..d0faf337c8 100644 --- a/src/assign.c +++ b/src/assign.c @@ -121,9 +121,9 @@ static int _selfrefok(SEXP x, Rboolean checkNames, Rboolean verbose) { if (verbose) Rprintf(_(".internal.selfref ptr is NULL. This is expected and normal for a data.table loaded from disk. Please remember to always setDT() immediately after loading to prevent unexpected behavior. If this table was not loaded from disk or you've already run setDT(), please report to data.table issue tracker.\n")); return -1; } - if (!isNull(p)) error(_("Internal error: .internal.selfref ptr is not NULL or R_NilValue")); // # nocov + if (!isNull(p)) error(_("Internal error: .internal.selfref ptr is neither NULL nor R_NilValue")); // # nocov tag = R_ExternalPtrTag(v); - if (!(isNull(tag) || isString(tag))) error(_("Internal error: .internal.selfref tag isn't NULL or a character vector")); // # nocov + if (!(isNull(tag) || isString(tag))) error(_("Internal error: .internal.selfref tag is neither NULL nor a character vector")); // # nocov names = getAttrib(x, R_NamesSymbol); if (names!=tag && isString(names) && !ALTREP(names)) // !ALTREP for #4734 SET_TRUELENGTH(names, LENGTH(names)); @@ -246,7 +246,8 @@ int checkOverAlloc(SEXP x) } SEXP alloccolwrapper(SEXP dt, SEXP overAllocArg, SEXP verbose) { - if (!isLogical(verbose) || length(verbose)!=1) error(_("verbose must be TRUE or FALSE")); + if (!IS_TRUE_OR_FALSE(verbose)) + error(_("%s must be TRUE or FALSE"), "verbose"); int overAlloc = checkOverAlloc(overAllocArg); SEXP ans = PROTECT(alloccol(dt, length(dt)+overAlloc, LOGICAL(verbose)[0])); @@ -311,7 +312,7 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values) SEXP names = PROTECT(getAttrib(dt, R_NamesSymbol)); protecti++; if (isNull(names)) error(_("dt passed to assign has no names")); if (length(names)!=oldncol) - error(_("Internal error in assign: length of names (%d) is not length of dt (%d)"),length(names),oldncol); // # nocov + error(_("Internal error: length of names (%d) is not length of dt (%d)"), length(names), oldncol); // # nocov if (isNull(dt)) { error(_("data.table is NULL; malformed. A null data.table should be an empty list. typeof() should always return 'list' for data.table.")); // # nocov // Not possible to test because R won't permit attributes be attached to NULL (which is good and we like); warning from R 3.4.0+ tested by 944.5 @@ -336,7 +337,7 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values) const int *rowsd = INTEGER(rows); for (int i=0; inrow) - error(_("i[%d] is %d which is out of range [1,nrow=%d]."),i+1,rowsd[i],nrow); // set() reaches here (test 2005.2); := reaches the same error in subset.c first + error(_("i[%d] is %d which is out of range [1,nrow=%d]"), i+1, rowsd[i], nrow); // set() reaches here (test 2005.2); := reaches the same error in subset.c first if (rowsd[i]>=1) numToDo++; } if (verbose) Rprintf(_("Assigning to %d row subset of %d rows\n"), numToDo, nrow); diff --git a/src/between.c b/src/between.c index 899ea1d94e..818fa0cbb4 100644 --- a/src/between.c +++ b/src/between.c @@ -12,14 +12,14 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, S error(_("Incompatible vector lengths: length(x)==%d length(lower)==%d length(upper)==%d. Each should be either length 1 or the length of the longest."), nx, nl, nu); } const int longestBound = MAX(nl, nu); // just for when check=TRUE - if (!isLogical(incbounds) || LOGICAL(incbounds)[0]==NA_LOGICAL) - error(_("incbounds must be TRUE or FALSE")); + if (!IS_TRUE_OR_FALSE(incbounds)) + error(_("%s must be TRUE or FALSE"), "incbounds"); const bool open = !LOGICAL(incbounds)[0]; if (!isLogical(NAboundsArg) || LOGICAL(NAboundsArg)[0]==FALSE) error(_("NAbounds must be TRUE or NA")); const bool NAbounds = LOGICAL(NAboundsArg)[0]==TRUE; - if (!isLogical(checkArg) || LOGICAL(checkArg)[0]==NA_LOGICAL) - error(_("check must be TRUE or FALSE")); + if (!IS_TRUE_OR_FALSE(checkArg)) + error(_("%s must be TRUE or FALSE"), "check"); const bool check = LOGICAL(checkArg)[0]; const bool verbose = GetVerbose(); diff --git a/src/bmerge.c b/src/bmerge.c index fac7ee281f..44ac7b569c 100644 --- a/src/bmerge.c +++ b/src/bmerge.c @@ -67,7 +67,7 @@ SEXP bmerge(SEXP idt, SEXP xdt, SEXP icolsArg, SEXP xcolsArg, SEXP isorted, SEXP int xt = TYPEOF(VECTOR_ELT(xdt, xcols[col]-1)); if (iN && it!=xt) error(_("typeof x.%s (%s) != typeof i.%s (%s)"), CHAR(STRING_ELT(getAttrib(xdt,R_NamesSymbol),xcols[col]-1)), type2char(xt), CHAR(STRING_ELT(getAttrib(idt,R_NamesSymbol),icols[col]-1)), type2char(it)); if (iN && it!=LGLSXP && it!=INTSXP && it!=REALSXP && it!=STRSXP) - error(_("Type '%s' not supported for joining/merging"), type2char(it)); + error(_("Type '%s' is not supported for joining/merging"), type2char(it)); } // rollArg, rollendsArg @@ -368,6 +368,8 @@ void bmerge_r(int xlowIn, int xuppIn, int ilowIn, int iuppIn, int col, int thisg } break; // supported types were checked up front to avoid handling an error here in (future) parallel region + default: + error(_("Type '%s' is not supported for joining/merging"), type2char(TYPEOF(xc))); } if (xlowleach = (int *)R_alloc(data->lvalues, sizeof(int)); data->isidentical = (int *)R_alloc(data->lvalues, sizeof(int)); data->isfactor = (int *)R_alloc(data->lvalues, sizeof(int)); diff --git a/src/forder.c b/src/forder.c index e7676386e7..a2ddf022a6 100644 --- a/src/forder.c +++ b/src/forder.c @@ -455,11 +455,11 @@ SEXP forder(SEXP DT, SEXP by, SEXP retGrpArg, SEXP sortGroupsArg, SEXP ascArg, S STOP(_("Column %d is length %d which differs from length of column 1 (%d), are you attempting to order by a list column?\n"), INTEGER(by)[i], length(VECTOR_ELT(DT, INTEGER(by)[i]-1)), nrow); if (TYPEOF(VECTOR_ELT(DT, by_i-1)) == CPLXSXP) n_cplx++; } - if (!isLogical(retGrpArg) || LENGTH(retGrpArg)!=1 || INTEGER(retGrpArg)[0]==NA_LOGICAL) - STOP(_("retGrp must be TRUE or FALSE")); + if (!IS_TRUE_OR_FALSE(retGrpArg)) + STOP(_("%s must be TRUE or FALSE"), "retGrp"); retgrp = LOGICAL(retGrpArg)[0]==TRUE; - if (!isLogical(sortGroupsArg) || LENGTH(sortGroupsArg)!=1 || INTEGER(sortGroupsArg)[0]==NA_LOGICAL ) - STOP(_("sort must be TRUE or FALSE")); + if (!IS_TRUE_OR_FALSE(sortGroupsArg)) + STOP(_("%s must be TRUE or FALSE"), "sort"); sortType = LOGICAL(sortGroupsArg)[0]==TRUE; // if sortType is 1, it is later flipped between +1/-1 according to ascArg. Otherwise ascArg is ignored when sortType==0 if (!retgrp && !sortType) STOP(_("At least one of retGrp= or sort= must be TRUE")); diff --git a/src/frank.c b/src/frank.c index e8445998b3..7148bdd387 100644 --- a/src/frank.c +++ b/src/frank.c @@ -6,8 +6,8 @@ SEXP dt_na(SEXP x, SEXP cols) { int n=0, elem; - if (!isNewList(x)) error(_("Internal error. Argument 'x' to Cdt_na is type '%s' not 'list'"), type2char(TYPEOF(x))); // # nocov - if (!isInteger(cols)) error(_("Internal error. Argument 'cols' to Cdt_na is type '%s' not 'integer'"), type2char(TYPEOF(cols))); // # nocov + if (!isNewList(x)) error(_("Internal error. Argument '%s' to %s is type '%s' not '%s'"), "x", "Cdt_na", type2char(TYPEOF(x)), "list"); // # nocov + if (!isInteger(cols)) error(_("Internal error. Argument '%s' to %s is type '%s' not '%s'"), "cols", "Cdt_na", type2char(TYPEOF(cols)), "integer"); // # nocov for (int i=0; iLENGTH(x)) @@ -184,8 +184,8 @@ SEXP frank(SEXP xorderArg, SEXP xstartArg, SEXP xlenArg, SEXP ties_method) { // internal version of anyNA for data.tables SEXP anyNA(SEXP x, SEXP cols) { int n=0; - if (!isNewList(x)) error(_("Internal error. Argument 'x' to CanyNA is type '%s' not 'list'"), type2char(TYPEOF(x))); // #nocov - if (!isInteger(cols)) error(_("Internal error. Argument 'cols' to CanyNA is type '%s' not 'integer'"), type2char(TYPEOF(cols))); // # nocov + if (!isNewList(x)) error(_("Internal error. Argument '%s' to %s is type '%s' not '%s'"), "x", "CanyNA", type2char(TYPEOF(x)), "list"); // #nocov + if (!isInteger(cols)) error(_("Internal error. Argument '%s' to %s is type '%s' not '%s'"), "cols", "CanyNA", type2char(TYPEOF(cols)), "integer"); // # nocov for (int i=0; iLENGTH(x)) diff --git a/src/fread.c b/src/fread.c index 70597a8f8d..7c7836250a 100644 --- a/src/fread.c +++ b/src/fread.c @@ -1355,7 +1355,7 @@ int freadMain(freadMainArgs _args) { const char* fnam = args.filename; #ifndef WIN32 int fd = open(fnam, O_RDONLY); - if (fd==-1) STOP(_("file not found: %s"),fnam); + if (fd==-1) STOP(_("File not found: %s"),fnam); struct stat stat_buf; if (fstat(fd, &stat_buf) == -1) { close(fd); // # nocov diff --git a/src/frollR.c b/src/frollR.c index 8a1b0ef295..644b863439 100644 --- a/src/frollR.c +++ b/src/frollR.c @@ -36,8 +36,8 @@ SEXP frollfunR(SEXP fun, SEXP obj, SEXP k, SEXP fill, SEXP algo, SEXP align, SEX if (xlength(k) == 0) // check that window is non zero length error(_("n must be non 0 length")); - if (!isLogical(adaptive) || length(adaptive) != 1 || LOGICAL(adaptive)[0] == NA_LOGICAL) - error(_("adaptive must be TRUE or FALSE")); + if (!IS_TRUE_OR_FALSE(adaptive)) + error(_("%s must be TRUE or FALSE"), "adaptive"); bool badaptive = LOGICAL(adaptive)[0]; R_len_t nk = 0; // number of rolling windows, for adaptive might be atomic to be wrapped into list, 0 for clang -Wall @@ -91,7 +91,7 @@ SEXP frollfunR(SEXP fun, SEXP obj, SEXP k, SEXP fill, SEXP algo, SEXP align, SEX } if (!IS_TRUE_OR_FALSE(narm)) - error(_("na.rm must be TRUE or FALSE")); + error(_("%s must be TRUE or FALSE"), "na.rm"); if (!isLogical(hasna) || length(hasna)!=1) error(_("hasNA must be TRUE, FALSE or NA")); @@ -106,7 +106,7 @@ SEXP frollfunR(SEXP fun, SEXP obj, SEXP k, SEXP fill, SEXP algo, SEXP align, SEX else if (!strcmp(CHAR(STRING_ELT(align, 0)), "left")) ialign = -1; else - error(_("Internal error: invalid align argument in rolling function, should have been caught before. please report to data.table issue tracker.")); // # nocov + error(_("Internal error: invalid %s argument in %s function should have been caught earlier. Please report to the data.table issue tracker."), "align", "rolling"); // # nocov if (badaptive && ialign!=1) error(_("using adaptive TRUE and align argument different than 'right' is not implemented")); @@ -138,7 +138,7 @@ SEXP frollfunR(SEXP fun, SEXP obj, SEXP k, SEXP fill, SEXP algo, SEXP align, SEX } else if (!strcmp(CHAR(STRING_ELT(fun, 0)), "sum")) { sfun = SUM; } else { - error(_("Internal error: invalid fun argument in rolling function, should have been caught before. please report to data.table issue tracker.")); // # nocov + error(_("Internal error: invalid %s argument in %s function should have been caught earlier. Please report to the data.table issue tracker."), "fun", "rolling"); // # nocov } if (length(fill) != 1) @@ -160,7 +160,7 @@ SEXP frollfunR(SEXP fun, SEXP obj, SEXP k, SEXP fill, SEXP algo, SEXP align, SEX else if (!strcmp(CHAR(STRING_ELT(algo, 0)), "exact")) ialgo = 1; // exact = 1 else - error(_("Internal error: invalid algo argument in rolling function, should have been caught before. please report to data.table issue tracker.")); // # nocov + error(_("Internal error: invalid %s argument in %s function should have been caught earlier. Please report to the data.table issue tracker."), "algo", "rolling"); // # nocov int* iik = NULL; if (!badaptive) { @@ -250,7 +250,7 @@ SEXP frollapplyR(SEXP fun, SEXP obj, SEXP k, SEXP fill, SEXP align, SEXP rho) { } else if (!strcmp(CHAR(STRING_ELT(align, 0)), "left")) { ialign = -1; } else { - error(_("Internal error: invalid align argument in rolling function, should have been caught before. please report to data.table issue tracker.")); // # nocov + error(_("Internal error: invalid %s argument in %s function should have been caught earlier. Please report to the data.table issue tracker."), "align", "rolling"); // # nocov } if (length(fill) != 1) diff --git a/src/fsort.c b/src/fsort.c index c50f8bc3eb..6dbb85d550 100644 --- a/src/fsort.c +++ b/src/fsort.c @@ -101,10 +101,10 @@ int qsort_cmp(const void *a, const void *b) { SEXP fsort(SEXP x, SEXP verboseArg) { double t[10]; t[0] = wallclock(); - if (!isLogical(verboseArg) || LENGTH(verboseArg)!=1 || LOGICAL(verboseArg)[0]==NA_LOGICAL) - error(_("verbose must be TRUE or FALSE")); + if (!IS_TRUE_OR_FALSE(verboseArg)) + error(_("%s must be TRUE or FALSE"), "verbose"); Rboolean verbose = LOGICAL(verboseArg)[0]; - if (!isNumeric(x)) error(_("x must be a vector of type 'double' currently")); + if (!isNumeric(x)) error(_("x must be a vector of type double currently")); // TODO: not only detect if already sorted, but if it is, just return x to save the duplicate SEXP ansVec = PROTECT(allocVector(REALSXP, xlength(x))); diff --git a/src/gsumm.c b/src/gsumm.c index 7470f9f527..be3b0f7855 100644 --- a/src/gsumm.c +++ b/src/gsumm.c @@ -41,7 +41,7 @@ SEXP gforce(SEXP env, SEXP jsub, SEXP o, SEXP f, SEXP l, SEXP irowsArg) { double started = wallclock(); const bool verbose = GetVerbose(); if (TYPEOF(env) != ENVSXP) error(_("env is not an environment")); - // The type of jsub is pretty flexbile in R, so leave checking to eval() below. + // The type of jsub is pretty flexible in R, so leave checking to eval() below. if (!isInteger(o)) error(_("%s is not an integer vector"), "o"); if (!isInteger(f)) error(_("%s is not an integer vector"), "f"); if (!isInteger(l)) error(_("%s is not an integer vector"), "l"); @@ -339,14 +339,17 @@ void *gather(SEXP x, bool *anyNA) SEXP gsum(SEXP x, SEXP narmArg) { - if (!isLogical(narmArg) || LENGTH(narmArg)!=1 || LOGICAL(narmArg)[0]==NA_LOGICAL) error(_("na.rm must be TRUE or FALSE")); + if (!IS_TRUE_OR_FALSE(narmArg)) + error(_("%s must be TRUE or FALSE"), "na.rm"); const bool narm = LOGICAL(narmArg)[0]; - if (inherits(x, "factor")) error(_("sum is not meaningful for factors.")); + if (inherits(x, "factor")) + error(_("%s is not meaningful for factors."), "sum"); const int n = (irowslen == -1) ? length(x) : irowslen; double started = wallclock(); const bool verbose=GetVerbose(); - if (verbose) Rprintf(_("This gsum took (narm=%s) ... "), narm?"TRUE":"FALSE"); - if (nrow != n) error(_("nrow [%d] != length(x) [%d] in %s"), nrow, n, "gsum"); + if (verbose) Rprintf(_("This gsum (narm=%s) took ... "), narm?"TRUE":"FALSE"); + if (nrow != n) + error(_("nrow [%d] != length(x) [%d] in %s"), nrow, n, "gsum"); bool anyNA=false; SEXP ans; switch(TYPEOF(x)) { @@ -561,7 +564,7 @@ SEXP gsum(SEXP x, SEXP narmArg) } } break; default: - error(_("Type '%s' not supported by GForce sum (gsum). Either add the prefix base::sum(.) or turn off GForce optimization using options(datatable.optimize=1)"), type2char(TYPEOF(x))); + error(_("Type '%s' is not supported by GForce %s. Either add the prefix %s or turn off GForce optimization using options(datatable.optimize=1)"), type2char(TYPEOF(x)), "sum (gsum)", "base::sum(.)"); } copyMostAttrib(x, ans); if (verbose) { Rprintf(_("%.3fs\n"), wallclock()-started); } @@ -571,8 +574,10 @@ SEXP gsum(SEXP x, SEXP narmArg) SEXP gmean(SEXP x, SEXP narmArg) { - if (inherits(x, "factor")) error(_("mean is not meaningful for factors.")); - if (!isLogical(narmArg) || LENGTH(narmArg)!=1 || LOGICAL(narmArg)[0]==NA_LOGICAL) error(_("na.rm must be TRUE or FALSE")); + if (inherits(x, "factor")) + error(_("%s is not meaningful for factors."), "mean"); + if (!IS_TRUE_OR_FALSE(narmArg)) + error(_("%s must be TRUE or FALSE"), "na.rm"); const bool narm = LOGICAL(narmArg)[0]; const int n = (irowslen == -1) ? length(x) : irowslen; double started = wallclock(); @@ -715,15 +720,18 @@ SEXP gmean(SEXP x, SEXP narmArg) static SEXP gminmax(SEXP x, SEXP narm, const bool min) { - if (!isLogical(narm) || LENGTH(narm)!=1 || LOGICAL(narm)[0]==NA_LOGICAL) error(_("na.rm must be TRUE or FALSE")); + if (!IS_TRUE_OR_FALSE(narm)) + error(_("%s must be TRUE or FALSE"), "na.rm"); if (!isVectorAtomic(x)) error(_("GForce min/max can only be applied to columns, not .SD or similar. To find min/max of all items in a list such as .SD, either add the prefix base::min(.SD) or turn off GForce optimization using options(datatable.optimize=1). More likely, you may be looking for 'DT[,lapply(.SD,min),by=,.SDcols=]'")); - if (inherits(x, "factor") && !inherits(x, "ordered")) error(_("min/max is not meaningful for factors.")); - const int n = (irowslen == -1) ? length(x) : irowslen; + if (inherits(x, "factor") && !inherits(x, "ordered")) + error(_("%s is not meaningful for factors."), min?"min":"max"); + const bool nosubset = irowslen==-1; + const int n = nosubset ? length(x) : irowslen; //clock_t start = clock(); SEXP ans; - if (nrow != n) error(_("nrow [%d] != length(x) [%d] in %s"), nrow, n, "gmin"); + if (nrow != n) + error(_("nrow [%d] != length(x) [%d] in %s"), nrow, n, "gminmax"); // GForce guarantees each group has at least one value; i.e. we don't need to consider length-0 per group here - const bool nosubset = irowslen==-1; switch(TYPEOF(x)) { case LGLSXP: case INTSXP: { ans = PROTECT(allocVector(INTSXP, ngrp)); @@ -829,7 +837,8 @@ static SEXP gminmax(SEXP x, SEXP narm, const bool min) error(_("Type 'complex' has no well-defined min/max")); break; default: - error(_("Type '%s' not supported by GForce min/max. Either add the prefix base::min(.) or turn off GForce optimization using options(datatable.optimize=1)"), type2char(TYPEOF(x))); + error(_("Type '%s' is not supported by GForce %s. Either add the prefix %s or turn off GForce optimization using options(datatable.optimize=1)"), + type2char(TYPEOF(x)), min?"min (gmin)":"max (gmax)", min?"base::min(.)":"base::max(.)"); } copyMostAttrib(x, ans); // all but names,dim and dimnames. And if so, we want a copy here, not keepattr's SET_ATTRIB. UNPROTECT(1); // ans @@ -849,12 +858,15 @@ SEXP gmax(SEXP x, SEXP narm) // gmedian, always returns numeric type (to avoid as.numeric() wrap..) SEXP gmedian(SEXP x, SEXP narmArg) { - if (!isLogical(narmArg) || LENGTH(narmArg)!=1 || LOGICAL(narmArg)[0]==NA_LOGICAL) error(_("na.rm must be TRUE or FALSE")); + if (!IS_TRUE_OR_FALSE(narmArg)) + error(_("%s must be TRUE or FALSE"), "na.rm"); if (!isVectorAtomic(x)) error(_("GForce median can only be applied to columns, not .SD or similar. To find median of all items in a list such as .SD, either add the prefix stats::median(.SD) or turn off GForce optimization using options(datatable.optimize=1). More likely, you may be looking for 'DT[,lapply(.SD,median),by=,.SDcols=]'")); - if (inherits(x, "factor")) error(_("median is not meaningful for factors.")); + if (inherits(x, "factor")) + error(_("%s is not meaningful for factors."), "median"); const bool isInt64 = INHERITS(x, char_integer64), narm = LOGICAL(narmArg)[0]; const int n = (irowslen == -1) ? length(x) : irowslen; - if (nrow != n) error(_("nrow [%d] != length(x) [%d] in %s"), nrow, n, "gmedian"); + if (nrow != n) + error(_("nrow [%d] != length(x) [%d] in %s"), nrow, n, "gmedian"); SEXP ans = PROTECT(allocVector(REALSXP, ngrp)); double *ansd = REAL(ans); const bool nosubset = irowslen==-1; @@ -892,7 +904,7 @@ SEXP gmedian(SEXP x, SEXP narmArg) { }} break; default: - error(_("Type '%s' not supported by GForce median (gmedian). Either add the prefix stats::median(.) or turn off GForce optimization using options(datatable.optimize=1)"), type2char(TYPEOF(x))); + error(_("Type '%s' is not supported by GForce %s. Either add the prefix %s or turn off GForce optimization using options(datatable.optimize=1)"), type2char(TYPEOF(x)), "median (gmedian)", "stats::median(.)"); } if (!isInt64) copyMostAttrib(x, ans); // else the integer64 class needs to be dropped since double is always returned by gmedian @@ -967,7 +979,7 @@ static SEXP gfirstlast(SEXP x, const bool first, const int w, const bool headw) case STRSXP: DO(SEXP, STRING_PTR, NA_STRING, SET_STRING_ELT(ans,ansi++,val)) break; case VECSXP: DO(SEXP, SEXPPTR_RO, ScalarLogical(NA_LOGICAL), SET_VECTOR_ELT(ans,ansi++,val)) break; default: - error(_("Type '%s' not supported by GForce head/tail/first/last/`[`. Either add the prefix utils::head(.) or turn off GForce optimization using options(datatable.optimize=1)"), type2char(TYPEOF(x))); + error(_("Type '%s' is not supported by GForce head/tail/first/last/`[`. Either add the namespace prefix (e.g. utils::head(.)) or turn off GForce optimization using options(datatable.optimize=1)"), type2char(TYPEOF(x))); } copyMostAttrib(x, ans); UNPROTECT(1); @@ -1003,11 +1015,14 @@ SEXP gnthvalue(SEXP x, SEXP nArg) { // implemented this similar to gmedian to balance well between speed and memory usage. There's one extra allocation on maximum groups and that's it.. and that helps speed things up extremely since we don't have to collect x's values for each group for each step (mean, residuals, mean again and then variance). static SEXP gvarsd1(SEXP x, SEXP narmArg, bool isSD) { - if (!isLogical(narmArg) || LENGTH(narmArg)!=1 || LOGICAL(narmArg)[0]==NA_LOGICAL) error(_("na.rm must be TRUE or FALSE")); + if (!IS_TRUE_OR_FALSE(narmArg)) + error(_("%s must be TRUE or FALSE"), "na.rm"); if (!isVectorAtomic(x)) error(_("GForce var/sd can only be applied to columns, not .SD or similar. For the full covariance matrix of all items in a list such as .SD, either add the prefix stats::var(.SD) (or stats::sd(.SD)) or turn off GForce optimization using options(datatable.optimize=1). Alternatively, if you only need the diagonal elements, 'DT[,lapply(.SD,var),by=,.SDcols=]' is the optimized way to do this.")); - if (inherits(x, "factor")) error(_("var/sd is not meaningful for factors.")); + if (inherits(x, "factor")) + error(_("%s is not meaningful for factors."), isSD ? "sd" : "var"); const int n = (irowslen == -1) ? length(x) : irowslen; - if (nrow != n) error(_("nrow [%d] != length(x) [%d] in %s"), nrow, n, "gvar"); + if (nrow != n) + error(_("nrow [%d] != length(x) [%d] in %s"), nrow, n, "gvar"); SEXP sub, ans = PROTECT(allocVector(REALSXP, ngrp)); double *ansd = REAL(ans); const bool nosubset = irowslen==-1; @@ -1076,8 +1091,8 @@ static SEXP gvarsd1(SEXP x, SEXP narmArg, bool isSD) }} break; default: - error(_("Type '%s' not supported by GForce %s. Either add the prefix stats::var(.) or turn off GForce optimization using options(datatable.optimize=1)"), - type2char(TYPEOF(x)), isSD?"sd (gsd)":"var (gvar)"); + error(_("Type '%s' is not supported by GForce %s. Either add the prefix %s or turn off GForce optimization using options(datatable.optimize=1)"), + type2char(TYPEOF(x)), isSD?"sd (gsd)":"var (gvar)", isSD?"stats::sd(.)":"stats::var(.)"); } // no copyMostAttrib(x, ans) since class (e.g. Date) unlikely applicable to sd/var UNPROTECT(2); // ans,sub @@ -1093,15 +1108,19 @@ SEXP gsd(SEXP x, SEXP narm) { } SEXP gprod(SEXP x, SEXP narmArg) { - if (!isLogical(narmArg) || LENGTH(narmArg)!=1 || LOGICAL(narmArg)[0]==NA_LOGICAL) error(_("na.rm must be TRUE or FALSE")); + if (!IS_TRUE_OR_FALSE(narmArg)) + error(_("%s must be TRUE or FALSE"), "na.rm"); const bool narm=LOGICAL(narmArg)[0]; - if (!isVectorAtomic(x)) error(_("GForce prod can only be applied to columns, not .SD or similar. To multiply all items in a list such as .SD, either add the prefix base::prod(.SD) or turn off GForce optimization using options(datatable.optimize=1). More likely, you may be looking for 'DT[,lapply(.SD,prod),by=,.SDcols=]'")); - if (inherits(x, "factor")) error(_("prod is not meaningful for factors.")); + if (!isVectorAtomic(x)) + error(_("GForce prod can only be applied to columns, not .SD or similar. To multiply all items in a list such as .SD, either add the prefix base::prod(.SD) or turn off GForce optimization using options(datatable.optimize=1). More likely, you may be looking for 'DT[,lapply(.SD,prod),by=,.SDcols=]'")); + if (inherits(x, "factor")) + error(_("%s is not meaningful for factors."), "prod"); const bool nosubset = irowslen==-1; const int n = nosubset ? length(x) : irowslen; //clock_t start = clock(); SEXP ans; - if (nrow != n) error(_("nrow [%d] != length(x) [%d] in %s"), nrow, n, "gprod"); + if (nrow != n) + error(_("nrow [%d] != length(x) [%d] in %s"), nrow, n, "gprod"); long double *s = malloc(ngrp * sizeof(long double)); if (!s) error(_("Unable to allocate %d * %d bytes for gprod"), ngrp, sizeof(long double)); for (int i=0; i DBL_MAX) ansd[i] = R_PosInf; diff --git a/src/init.c b/src/init.c index eda1c607c4..56bf66d419 100644 --- a/src/init.c +++ b/src/init.c @@ -258,22 +258,22 @@ void attribute_visible R_init_data_table(DllInfo *info) R_registerRoutines(info, NULL, callMethods, NULL, externalMethods); R_useDynamicSymbols(info, FALSE); setSizes(); - const char *msg = "... failed. Please forward this message to maintainer('data.table')."; + const char *msg = _("... failed. Please forward this message to maintainer('data.table')."); if ((int)NA_INTEGER != (int)INT_MIN) error(_("Checking NA_INTEGER [%d] == INT_MIN [%d] %s"), NA_INTEGER, INT_MIN, msg); if ((int)NA_INTEGER != (int)NA_LOGICAL) error(_("Checking NA_INTEGER [%d] == NA_LOGICAL [%d] %s"), NA_INTEGER, NA_LOGICAL, msg); - if (sizeof(int) != 4) error(_("Checking sizeof(int) [%d] is 4 %s"), sizeof(int), msg); - if (sizeof(double) != 8) error(_("Checking sizeof(double) [%d] is 8 %s"), sizeof(double), msg); // 8 on both 32bit and 64bit + if (sizeof(int) != 4) error(_("Checking sizeof(%s) [%d] is %d %s"), "int", sizeof(int), 4, msg); + if (sizeof(double) != 8) error(_("Checking sizeof(%s) [%d] is %d %s"), "double", sizeof(double), 8, msg); // 8 on both 32bit and 64bit // alignof not available in C99: if (alignof(double) != 8) error(_("Checking alignof(double) [%d] is 8 %s"), alignof(double), msg); // 8 on both 32bit and 64bit - if (sizeof(long long) != 8) error(_("Checking sizeof(long long) [%d] is 8 %s"), sizeof(long long), msg); + if (sizeof(long long) != 8) error(_("Checking sizeof(%s) [%d] is %d %s"), "long long", sizeof(long long), 8, msg); if (sizeof(char *) != 4 && sizeof(char *) != 8) error(_("Checking sizeof(pointer) [%d] is 4 or 8 %s"), sizeof(char *), msg); if (sizeof(SEXP) != sizeof(char *)) error(_("Checking sizeof(SEXP) [%d] == sizeof(pointer) [%d] %s"), sizeof(SEXP), sizeof(char *), msg); - if (sizeof(uint64_t) != 8) error(_("Checking sizeof(uint64_t) [%d] is 8 %s"), sizeof(uint64_t), msg); - if (sizeof(int64_t) != 8) error(_("Checking sizeof(int64_t) [%d] is 8 %s"), sizeof(int64_t), msg); - if (sizeof(signed char) != 1) error(_("Checking sizeof(signed char) [%d] is 1 %s"), sizeof(signed char), msg); - if (sizeof(int8_t) != 1) error(_("Checking sizeof(int8_t) [%d] is 1 %s"), sizeof(int8_t), msg); - if (sizeof(uint8_t) != 1) error(_("Checking sizeof(uint8_t) [%d] is 1 %s"), sizeof(uint8_t), msg); - if (sizeof(int16_t) != 2) error(_("Checking sizeof(int16_t) [%d] is 2 %s"), sizeof(int16_t), msg); - if (sizeof(uint16_t) != 2) error(_("Checking sizeof(uint16_t) [%d] is 2 %s"), sizeof(uint16_t), msg); + if (sizeof(uint64_t) != 8) error(_("Checking sizeof(%s) [%d] is %d %s"), "uint64_t", sizeof(uint64_t), 8, msg); + if (sizeof(int64_t) != 8) error(_("Checking sizeof(%s) [%d] is %d %s"), "int64_t", sizeof(int64_t), 8, msg); + if (sizeof(signed char) != 1) error(_("Checking sizeof(%s) [%d] is %d %s"), "signed char", sizeof(signed char), 1, msg); + if (sizeof(int8_t) != 1) error(_("Checking sizeof(%s) [%d] is %d %s"), "int8_t", sizeof(int8_t), 1, msg); + if (sizeof(uint8_t) != 1) error(_("Checking sizeof(%s) [%d] is %d %s"), "uint8_t", sizeof(uint8_t), 1, msg); + if (sizeof(int16_t) != 2) error(_("Checking sizeof(%s) [%d] is %d %s"), "int16_t", sizeof(int16_t), 2, msg); + if (sizeof(uint16_t) != 2) error(_("Checking sizeof(%s) [%d] is %d %s"), "uint16_t", sizeof(uint16_t), 2 ,msg); SEXP tmp = PROTECT(allocVector(INTSXP,2)); if (LENGTH(tmp)!=2) error(_("Checking LENGTH(allocVector(INTSXP,2)) [%d] is 2 %s"), LENGTH(tmp), msg); diff --git a/src/nafill.c b/src/nafill.c index b393db1c16..03aa6d091b 100644 --- a/src/nafill.c +++ b/src/nafill.c @@ -167,7 +167,7 @@ SEXP nafillR(SEXP obj, SEXP type, SEXP fill, SEXP nan_is_na_arg, SEXP inplace, S else if (!strcmp(CHAR(STRING_ELT(type, 0)), "nocb")) itype = 2; else - error(_("Internal error: invalid type argument in nafillR function, should have been caught before. Please report to data.table issue tracker.")); // # nocov + error(_("Internal error: invalid %s argument in %s function should have been caught earlier. Please report to the data.table issue tracker."), "type", "nafillR"); // # nocov bool hasFill = !isLogical(fill) || LOGICAL(fill)[0]!=NA_LOGICAL; bool *isInt64 = (bool *)R_alloc(nx, sizeof(bool)); diff --git a/src/openmp-utils.c b/src/openmp-utils.c index 22e562506d..c9003ee07b 100644 --- a/src/openmp-utils.c +++ b/src/openmp-utils.c @@ -75,7 +75,8 @@ static const char *mygetenv(const char *name, const char *unset) { } SEXP getDTthreads_R(SEXP verbose) { - if (!isLogical(verbose) || LENGTH(verbose)!=1 || INTEGER(verbose)[0]==NA_LOGICAL) error(_("'verbose' must be TRUE or FALSE")); + if(!IS_TRUE_OR_FALSE(verbose)) + error(_("%s must be TRUE or FALSE"), "verbose"); if (LOGICAL(verbose)[0]) { #ifndef _OPENMP Rprintf(_("This installation of data.table has not been compiled with OpenMP support.\n")); diff --git a/src/shift.c b/src/shift.c index f70fcf5c1f..9ff0449628 100644 --- a/src/shift.c +++ b/src/shift.c @@ -167,7 +167,7 @@ SEXP shift(SEXP obj, SEXP k, SEXP fill, SEXP type) } break; default : - error(_("Unsupported type '%s'"), type2char(TYPEOF(elem))); + error(_("Type '%s' is not supported"), type2char(TYPEOF(elem))); } } diff --git a/src/subset.c b/src/subset.c index a04fcc9ecb..2158451798 100644 --- a/src/subset.c +++ b/src/subset.c @@ -107,7 +107,7 @@ const char *check_idx(SEXP idx, int max, bool *anyNA_out, bool *orderedSubset_ou // error if any negatives, zeros or >max since they should have been dealt with by convertNegAndZeroIdx() called ealier at R level. // single cache efficient sweep with prefetch, so very low priority to go parallel { - if (!isInteger(idx)) error(_("Internal error. 'idx' is type '%s' not 'integer'"), type2char(TYPEOF(idx))); // # nocov + if (!isInteger(idx)) error(_("Internal error. Argument '%s' to %s is type '%s' not '%s'"), "idx", "check_idx", type2char(TYPEOF(idx)), "integer"); // # nocov bool anyLess=false, anyNA=false; int last = INT32_MIN; int *idxp = INTEGER(idx), n=LENGTH(idx); @@ -271,7 +271,7 @@ static void checkCol(SEXP col, int colNum, int nrow, SEXP x) SEXP subsetDT(SEXP x, SEXP rows, SEXP cols) { // API change needs update NEWS.md and man/cdt.Rd int nprotect=0; - if (!isNewList(x)) error(_("Internal error. Argument 'x' to CsubsetDT is type '%s' not 'list'"), type2char(TYPEOF(rows))); // # nocov + if (!isNewList(x)) error(_("Internal error. Argument '%s' to %s is type '%s' not '%s'"), "x", "CsubsetDT", type2char(TYPEOF(rows)), "list"); // # nocov if (!length(x)) return(x); // return empty list const int nrow = length(VECTOR_ELT(x,0)); @@ -284,10 +284,10 @@ SEXP subsetDT(SEXP x, SEXP rows, SEXP cols) { // API change needs update NEWS.md if (err!=NULL) error(err); } - if (!isInteger(cols)) error(_("Internal error. Argument 'cols' to Csubset is type '%s' not 'integer'"), type2char(TYPEOF(cols))); // # nocov + if (!isInteger(cols)) error(_("Internal error. Argument '%s' to %s is type '%s' not '%s'"), "cols", "Csubset", type2char(TYPEOF(cols)), "integer"); // # nocov for (int i=0; iLENGTH(x)) error(_("Item %d of 'cols' is %d which is outside 1-based range [1,ncol(x)=%d]"), i+1, this, LENGTH(x)); + if (this<1 || this>LENGTH(x)) error(_("Item %d of cols is %d which is outside the range [1,ncol(x)=%d]"), i+1, this, LENGTH(x)); } int overAlloc = checkOverAlloc(GetOption(install("datatable.alloccol"), R_NilValue)); diff --git a/src/uniqlist.c b/src/uniqlist.c index d79f7587e0..48da706a2c 100644 --- a/src/uniqlist.c +++ b/src/uniqlist.c @@ -95,7 +95,7 @@ SEXP uniqlist(SEXP l, SEXP order) } } break; default : - error(_("Type '%s' not supported"), type2char(TYPEOF(v))); // # nocov + error(_("Type '%s' is not supported"), type2char(TYPEOF(v))); // # nocov } } else { // ncol>1 @@ -127,7 +127,7 @@ SEXP uniqlist(SEXP l, SEXP order) } break; default : - error(_("Type '%s' not supported"), type2char(TYPEOF(v))); // # nocov + error(_("Type '%s' is not supported"), type2char(TYPEOF(v))); // # nocov } } if (!b) { @@ -171,7 +171,7 @@ SEXP rleid(SEXP l, SEXP cols) { int *icols = INTEGER(cols); for (int i=0; incol) error(_("Item %d of cols is %d which is outside range of l [1,length(l)=%d]"), i+1, elem, ncol); + if (elem<1 || elem>ncol) error(_("Item %d of cols is %d which is outside the range [1,length(l)=%d]"), i+1, elem, ncol); } for (int i=1; i0 but ngrps==0"), nrows); // # nocov R_len_t resetctr=0, rlen = length(resetvals) ? INTEGER(resetvals)[0] : 0; - if (!isInteger(cols) || ncols == 0) error(_("cols must be an integer vector of positive length")); + if (!isInteger(cols) || ncols == 0) error(_("cols must be an integer vector with length >= 1")); // mult arg enum {ALL, FIRST, LAST} mult = ALL; if (!strcmp(CHAR(STRING_ELT(multArg, 0)), "all")) mult = ALL; @@ -318,7 +318,7 @@ SEXP nestedid(SEXP l, SEXP cols, SEXP order, SEXP grps, SEXP resetvals, SEXP mul dtwiddle(xd[thisi]) >= dtwiddle(xd[previ]); } break; default: - error(_("Type '%s' not supported"), type2char(TYPEOF(v))); // # nocov + error(_("Type '%s' is not supported"), type2char(TYPEOF(v))); // # nocov } } if (b) break; @@ -350,7 +350,8 @@ SEXP nestedid(SEXP l, SEXP cols, SEXP order, SEXP grps, SEXP resetvals, SEXP mul SEXP uniqueNlogical(SEXP x, SEXP narmArg) { // single pass; short-circuit and return as soon as all 3 values are found if (!isLogical(x)) error(_("x is not a logical vector")); - if (!isLogical(narmArg) || length(narmArg)!=1 || INTEGER(narmArg)[0]==NA_INTEGER) error(_("na.rm must be TRUE or FALSE")); + if (!IS_TRUE_OR_FALSE(narmArg)) + error(_("%s must be TRUE or FALSE"), "na.rm"); bool narm = LOGICAL(narmArg)[0]==1; const R_xlen_t n = xlength(x); if (n==0) diff --git a/src/utils.c b/src/utils.c index 312f554f8f..e499aced06 100644 --- a/src/utils.c +++ b/src/utils.c @@ -92,7 +92,7 @@ SEXP colnamesInt(SEXP x, SEXP cols, SEXP check_dups) { if (!isNewList(x)) error(_("'x' argument must be data.table compatible")); if (!IS_TRUE_OR_FALSE(check_dups)) - error(_("'check_dups' argument must be TRUE or FALSE")); + error(_("%s must be TRUE or FALSE"), "check_dups"); int protecti = 0; R_len_t nx = length(x); R_len_t nc = length(cols); @@ -114,7 +114,7 @@ SEXP colnamesInt(SEXP x, SEXP cols, SEXP check_dups) { int *icols = INTEGER(ricols); for (int i=0; inx) || (icols[i]<1)) - error(_("argument specifying columns specify non existing column(s): cols[%d]=%d"), i+1, icols[i]); // handles NAs also + error(_("argument specifying columns received non-existing column(s): cols[%d]=%d"), i+1, icols[i]); // handles NAs also } } else if (isString(cols)) { SEXP xnames = PROTECT(getAttrib(x, R_NamesSymbol)); protecti++; @@ -124,13 +124,13 @@ SEXP colnamesInt(SEXP x, SEXP cols, SEXP check_dups) { int *icols = INTEGER(ricols); for (int i=0; i