Skip to content

Commit 014c82f

Browse files
Activate + apply some linters (#6124)
* Activate + apply some linters * Updated paste_linter in dev version of lintr * trailing whitespace missed last time * Different error message from rep_len() * one more * Also knock out '<<-' usage
1 parent ca815ba commit 014c82f

File tree

10 files changed

+25
-28
lines changed

10 files changed

+25
-28
lines changed

.ci/.lintr.R

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ linters = c(dt_linters, all_linters(
2525
# par = NULL,
2626
# setwd = NULL
2727
# )),
28-
undesirable_operator_linter(modify_defaults(
29-
default_undesirable_operators,
30-
`<<-` = NULL
31-
)),
28+
undesirable_operator_linter(),
3229
# TODO(lintr#2441): Use upstream implementation.
3330
assignment_linter = NULL,
3431
absolute_path_linter = NULL, # too many false positives
@@ -57,7 +54,7 @@ linters = c(dt_linters, all_linters(
5754
strings_as_factors_linter = NULL,
5855
# TODO(lintr->3.2.0): Fix on a valid TODO style, enforce it, and re-activate.
5956
todo_comment_linter = NULL,
60-
# TODO(michaelchirico): Enforce these and re-activate them one-by-one. Also stop using '<<-'.
57+
# TODO(michaelchirico): Enforce these and re-activate them one-by-one.
6158
brace_linter = NULL,
6259
condition_call_linter = NULL,
6360
conjunct_test_linter = NULL,
@@ -74,12 +71,9 @@ linters = c(dt_linters, all_linters(
7471
object_overwrite_linter = NULL,
7572
paren_body_linter = NULL,
7673
redundant_equals_linter = NULL,
77-
rep_len_linter = NULL,
78-
repeat_linter = NULL,
7974
return_linter = NULL,
8075
sample_int_linter = NULL,
8176
scalar_in_linter = NULL,
82-
seq_linter = NULL,
8377
undesirable_function_linter = NULL,
8478
unnecessary_concatenation_linter = NULL,
8579
unnecessary_lambda_linter = NULL,
@@ -116,7 +110,9 @@ exclusions = c(local({
116110
comparison_negation_linter = Inf,
117111
duplicate_argument_linter = Inf,
118112
equals_na_linter = Inf,
119-
paste_linter = Inf
113+
paste_linter = Inf,
114+
rep_len_linter = Inf,
115+
seq_linter = Inf
120116
))
121117
)
122118
}),

R/as.data.table.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ as.data.table.list = function(x,
169169
# not worse than before, and gets us in a better centralized place to port as.data.table.list to C and use MAYBE_REFERENCED
170170
# again in future, for #617.
171171
}
172-
if (identical(x,list())) vector("list", nrow) else rep(x, length.out=nrow) # new objects don't need copy
172+
if (identical(x, list())) vector("list", nrow) else rep_len(x, nrow) # new objects don't need copy
173173
}
174174
vnames = character(ncol)
175175
k = 1L

R/cedta.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ cedta.pkgEvalsUserCode = c("gWidgetsWWW","statET","FastRWeb","slidify","rmarkdow
3131
.any_eval_calls_in_stack <- function() {
3232
calls = sys.calls()
3333
# likelier to be close to the end of the call stack, right?
34-
for (ii in length(calls):1) { # rev(seq_len(length(calls)))? See https://bugs.r-project.org/show_bug.cgi?id=18406.
34+
for (ii in length(calls):1) { # nolint: seq_linter. rev(seq_len(length(calls)))? See https://bugs.r-project.org/show_bug.cgi?id=18406.
3535
the_call <- calls[[ii]][[1L]]
3636
if (is.name(the_call) && (the_call %chin% c("eval", "evalq"))) return(TRUE)
3737
}

R/data.table.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ replace_dot_alias = function(e) {
825825
if (!bysameorder && keyby && !length(irows) && isTRUE(getOption("datatable.use.index"))) {
826826
# TODO: could be allowed if length(irows)>1 but then the index would need to be squashed for use by uniqlist, #3062
827827
# find if allbyvars is leading subset of any of the indices; add a trailing "__" to fix #3498 where a longer column name starts with a shorter column name
828-
tt = paste0(c(allbyvars,""), collapse="__")
828+
tt = paste(c(allbyvars,""), collapse="__")
829829
w = which.first(startsWith(paste0(indices(x), "__"), tt))
830830
if (!is.na(w)) {
831831
byindex = indices(x)[w]
@@ -960,6 +960,7 @@ replace_dot_alias = function(e) {
960960
else if (any(idx <- nm != jvnames))
961961
warningf('Different branches of j expression produced different auto-named columns: %s; using the most "last" names. If this was intentional (e.g., you know only one branch will ever be used in a given query because the branch is controlled by a function argument), please (1) pull this branch out of the call; (2) explicitly provide missing defaults for each branch in all cases; or (3) use the same name for each branch and re-name it in a follow-up call.', brackify(sprintf('%s!=%s', nm[idx], jvnames[idx])))
962962
}
963+
# nolint next: undesirable_operator_linter. Workaround is clunkier, though a bigger refactor could be considered.
963964
jvnames <<- nm # TODO: handle if() list(a, b) else list(b, a) better
964965
setattr(q, "names", NULL) # drops the names from the list so it's faster to eval the j for each group; reinstated at the end on the result.
965966
}
@@ -3216,18 +3217,18 @@ is_constantish = function(q, check_singleton=FALSE) {
32163217
}
32173218
}
32183219
if (!is.null(idx)){
3219-
if (verbose) {catf("Optimized subsetting with index '%s'\n", paste0( idxCols, collapse = "__"));flush.console()}
3220+
if (verbose) {catf("Optimized subsetting with index '%s'\n", paste(idxCols, collapse = "__"));flush.console()}
32203221
}
32213222
}
32223223
if (is.null(idx)){
32233224
## if nothing else helped, auto create a new index that can be used
32243225
if (!getOption("datatable.auto.index")) return(NULL)
3225-
if (verbose) {catf("Creating new index '%s'\n", paste0(names(i), collapse = "__"));flush.console()}
3226-
if (verbose) {last.started.at=proc.time();catf("Creating index %s done in ...", paste0(names(i), collapse = "__"));flush.console()}
3226+
if (verbose) {catf("Creating new index '%s'\n", paste(names(i), collapse = "__"));flush.console()}
3227+
if (verbose) {last.started.at=proc.time();catf("Creating index %s done in ...", paste(names(i), collapse = "__"));flush.console()}
32273228
setindexv(x, names(i))
32283229
if (verbose) {cat(timetaken(last.started.at),"\n");flush.console()}
3229-
if (verbose) {catf("Optimized subsetting with index '%s'\n", paste0(names(i), collapse = "__"));flush.console()}
3230-
idx = attr(attr(x, "index", exact=TRUE), paste0("__", names(i), collapse = ""), exact=TRUE)
3230+
if (verbose) {catf("Optimized subsetting with index '%s'\n", paste(names(i), collapse = "__"));flush.console()}
3231+
idx = attr(attr(x, "index", exact=TRUE), paste("__", names(i), collapse = ""), exact=TRUE)
32313232
idxCols = names(i)
32323233
}
32333234
if(!is.null(idxCols)){

R/fcast.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ aggregate_funs = function(funs, vals, sep="_", ...) {
130130

131131
dcast.data.table = function(data, formula, fun.aggregate = NULL, sep = "_", ..., margins = NULL, subset = NULL, fill = NULL, drop = TRUE, value.var = guess(data), verbose = getOption("datatable.verbose"), value.var.in.dots = FALSE, value.var.in.LHSdots = value.var.in.dots, value.var.in.RHSdots = value.var.in.dots) {
132132
if (!is.data.table(data)) stopf("'data' must be a data.table.")
133-
drop = as.logical(rep(drop, length.out=2L))
133+
drop = as.logical(rep_len(drop, 2L))
134134
if (anyNA(drop)) stopf("'drop' must be logical TRUE/FALSE")
135135
if (!isTRUEorFALSE(value.var.in.dots))
136136
stopf("Argument 'value.var.in.dots' should be logical TRUE/FALSE")

R/fread.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ yaml=FALSE, autostart=NA, tmpdir=tempdir(), tz="UTC")
187187

188188
yaml_comment_re = '^#'
189189
yaml_string = character(0L)
190-
while (TRUE) {
190+
repeat {
191191
this_line = readLines(f, n=1L)
192192
n_read = n_read + 1L
193193
if (!length(this_line)){

R/setkey.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ setkeyv = function(x, cols, verbose=getOption("datatable.verbose"), physical=TRU
7777
}
7878
if (!is.character(cols) || length(cols)<1L) stopf("Internal error. 'cols' should be character at this point in setkey; please report.") # nocov
7979

80-
newkey = paste0(cols, collapse="__")
80+
newkey = paste(cols, collapse="__")
8181
if (!any(indices(x) == newkey)) {
8282
if (verbose) {
8383
tt = suppressMessages(system.time(o <- forderv(x, cols, sort=TRUE, retGrp=FALSE))) # system.time does a gc, so we don't want this always on, until refcnt is on by default in R

R/test.data.table.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=F
234234
", Sys.timezone()=='", suppressWarnings(Sys.timezone()), "'",
235235
", Sys.getlocale()=='", Sys.getlocale(), "'",
236236
", l10n_info()=='", paste0(names(l10n_info()), "=", l10n_info(), collapse="; "), "'",
237-
", getDTthreads()=='", paste0(gsub("[ ][ ]+","==",gsub("^[ ]+","",capture.output(invisible(getDTthreads(verbose=TRUE))))), collapse="; "), "'",
237+
", getDTthreads()=='", paste(gsub("[ ][ ]+","==",gsub("^[ ]+","",capture.output(invisible(getDTthreads(verbose=TRUE))))), collapse="; "), "'",
238238
", ", .Call(Cdt_zlib_version),
239239
"\n", sep="")
240240

@@ -403,18 +403,18 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no
403403
xsub = substitute(x)
404404
ysub = substitute(y)
405405

406-
actual = list("warning"=NULL, "error"=NULL, "message"=NULL)
406+
actual = list2env(list(warning=NULL, error=NULL, message=NULL))
407407
wHandler = function(w) {
408408
# Thanks to: https://stackoverflow.com/a/4947528/403310
409-
actual$warning <<- c(actual$warning, conditionMessage(w))
409+
actual$warning <- c(actual$warning, conditionMessage(w))
410410
invokeRestart("muffleWarning")
411411
}
412412
eHandler = function(e) {
413-
actual$error <<- conditionMessage(e)
413+
actual$error <- conditionMessage(e)
414414
e
415415
}
416416
mHandler = function(m) {
417-
actual$message <<- c(actual$message, conditionMessage(m))
417+
actual$message <- c(actual$message, conditionMessage(m))
418418
m
419419
}
420420
if (is.null(output) && is.null(notOutput)) {

inst/tests/S4.Rraw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ removeClass("S4Composition")
6161
# miscellaneous missing tests uncovered by CodeCov difference in the process of PR #2573 [S4 portion, c.f. 1872.* in tests.Rraw]
6262
## data.table cannot recycle complicated types
6363
short_s4_col = getClass("MethodDefinition")
64-
test(2, data.table(a = 1:4, short_s4_col), error="attempt to replicate an object of type 'S4'")
64+
test(2, data.table(a = 1:4, short_s4_col), error="attempt to replicate non-vector")
6565

6666
# print dims in list-columns, #3671, c.f. 2130.* in tests.Rraw
6767
s4class = setClass("ex_class", slots = list(x="integer", y="character", z="numeric"))

inst/tests/tests.Rraw

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3678,12 +3678,12 @@ test(1100, dt1[dt2,roll=-Inf,rollends=c(FALSE,TRUE)]$ind, INT(NA,NA,1,2,2,2,2,2,
36783678
set.seed(1)
36793679
DT = data.table(index = c("a","b"), x = 1:2, y = rnorm(2))
36803680
test(1102.186, names(dcast(DT, ... ~ ..., value.var = "y", value.var.in.LHSdots = TRUE)), c("index", "x", "y", "a_1", "b_2"))
3681-
3681+
36823682
DT = data.table(year = c(rep(1986,4), rep(1987,3), rep(1988,2), 1989:1991), continent = rep(c("Europe","Asia"), each = 6), country = rep(c("Sweden","Germany","France","India","Japan","China"), each = 2))
36833683
DT_dcasted_LHSddd = dcast(DT, ... ~ ..., fun.aggregate = length, value.var.in.RHSdots = TRUE, value.var = "country")
36843684
test(1102.187, dim(DT_dcasted_LHSddd), c(7L,11L))
36853685
test(1102.188, names(DT_dcasted_LHSddd), c("year", "continent", "1986_Europe_Germany", "1986_Europe_Sweden", "1987_Asia_India", "1987_Europe_France", "1988_Asia_India", "1988_Asia_Japan", "1989_Asia_Japan", "1990_Asia_China", "1991_Asia_China"))
3686-
3686+
36873687
DT_dcasted_LHSd = dcast(DT, . ~ ..., fun.aggregate = length, value.var.in.RHSdots = TRUE, value.var = "country")
36883688
DT_dcasted_LHSi = dcast(DT, 1 ~ ..., fun.aggregate = length, value.var.in.RHSdots = TRUE, value.var = "country")
36893689

0 commit comments

Comments
 (0)