Skip to content

Commit 918c38c

Browse files
Revert "Another batch of low-volume, low-complexity lint fixes"
This reverts commit ebd536d.
1 parent ebd536d commit 918c38c

File tree

12 files changed

+49
-43
lines changed

12 files changed

+49
-43
lines changed

.ci/.lintr.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ linters = c(dt_linters, all_linters(
3838
function_argument_linter = NULL,
3939
indentation_linter = NULL,
4040
infix_spaces_linter = NULL,
41+
# TODO(R>3.2.0): Activate this, extending to recognize vapply_1i(x, length).
42+
lengths_linter = NULL,
4143
line_length_linter = NULL,
4244
missing_package_linter = NULL,
4345
namespace_linter = NULL,
@@ -55,20 +57,26 @@ linters = c(dt_linters, all_linters(
5557
# TODO(michaelchirico): Enforce these and re-activate them one-by-one.
5658
brace_linter = NULL,
5759
condition_call_linter = NULL,
60+
conjunct_test_linter = NULL,
5861
fixed_regex_linter = NULL,
62+
function_left_parentheses_linter = NULL,
5963
if_not_else_linter = NULL,
6064
implicit_assignment_linter = NULL,
6165
implicit_integer_linter = NULL,
6266
keyword_quote_linter = NULL,
67+
length_levels_linter = NULL,
68+
matrix_apply_linter = NULL,
6369
missing_argument_linter = NULL,
6470
nzchar_linter = NULL,
6571
object_overwrite_linter = NULL,
6672
paren_body_linter = NULL,
6773
redundant_equals_linter = NULL,
6874
return_linter = NULL,
75+
sample_int_linter = NULL,
6976
scalar_in_linter = NULL,
7077
undesirable_function_linter = NULL,
7178
unnecessary_concatenation_linter = NULL,
79+
unnecessary_lambda_linter = NULL,
7280
unnecessary_nesting_linter = NULL,
7381
unreachable_code_linter = NULL,
7482
unused_import_linter = NULL
@@ -90,8 +98,7 @@ exclusions = c(local({
9098
undesirable_function_linter = Inf
9199
)),
92100
exclusion_for_dir("vignettes", list(
93-
quotes_linter = Inf,
94-
sample_int_linter = Inf
101+
quotes_linter = Inf
95102
# strings_as_factors_linter = Inf
96103
# system_time_linter = Inf
97104
)),
@@ -105,9 +112,7 @@ exclusions = c(local({
105112
equals_na_linter = Inf,
106113
paste_linter = Inf,
107114
rep_len_linter = Inf,
108-
sample_int_linter = Inf,
109-
seq_linter = Inf,
110-
unnecessary_lambda_linter = Inf
115+
seq_linter = Inf
111116
))
112117
)
113118
}),

R/IDateTime.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ as.list.IDate = function(x, ...) NextMethod()
8383
## round.IDate = function (x, digits, units=digits, ...) {
8484
## if (missing(digits)) digits = units # workaround to provide a units argument to match the round generic and round.POSIXt
8585
## units = match.arg(digits, c("weeks", "months", "quarters", "years"))
86-
round.IDate = function(x, digits=c("weeks", "months", "quarters", "years"), ...) {
86+
round.IDate = function (x, digits=c("weeks", "months", "quarters", "years"), ...) {
8787
units = match.arg(digits)
8888
as.IDate(switch(units,
8989
weeks = round(x, "year") + 7L * (yday(x) %/% 7L),
@@ -93,7 +93,7 @@ round.IDate = function(x, digits=c("weeks", "months", "quarters", "years"), ...)
9393
}
9494

9595
#Adapted from `+.Date`
96-
`+.IDate` = function(e1, e2) {
96+
`+.IDate` = function (e1, e2) {
9797
if (nargs() == 1L)
9898
return(e1)
9999
# TODO: investigate Ops.IDate method a la Ops.difftime
@@ -108,7 +108,7 @@ round.IDate = function(x, digits=c("weeks", "months", "quarters", "years"), ...)
108108
(setattr(as.integer(unclass(e1) + unclass(e2)), "class", c("IDate", "Date"))) # () wrap to return visibly
109109
}
110110

111-
`-.IDate` = function(e1, e2) {
111+
`-.IDate` = function (e1, e2) {
112112
if (!inherits(e1, "IDate")) {
113113
if (inherits(e1, 'Date')) return(base::`-.Date`(e1, e2))
114114
stopf("can only subtract from \"IDate\" objects")
@@ -228,7 +228,7 @@ print.ITime = function(x, ...) {
228228
print(format(x))
229229
}
230230

231-
rep.ITime = function(x, ...)
231+
rep.ITime = function (x, ...)
232232
{
233233
y = rep(unclass(x), ...)
234234
class(y) = "ITime" # unlass and rep could feasibly not copy, hence use class<- not setattr()

R/data.table.R

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ replace_dot_alias = function(e) {
129129
}
130130
}
131131

132-
"[.data.table" = function(x, i, j, by, keyby, with=TRUE, nomatch=NA, mult="all", roll=FALSE, rollends=if (roll=="nearest") c(TRUE,TRUE) else if (roll>=0) c(FALSE,TRUE) else c(TRUE,FALSE), which=FALSE, .SDcols, verbose=getOption("datatable.verbose"), allow.cartesian=getOption("datatable.allow.cartesian"), drop=NULL, on=NULL, env=NULL)
132+
"[.data.table" = function (x, i, j, by, keyby, with=TRUE, nomatch=NA, mult="all", roll=FALSE, rollends=if (roll=="nearest") c(TRUE,TRUE) else if (roll>=0) c(FALSE,TRUE) else c(TRUE,FALSE), which=FALSE, .SDcols, verbose=getOption("datatable.verbose"), allow.cartesian=getOption("datatable.allow.cartesian"), drop=NULL, on=NULL, env=NULL)
133133
{
134134
# ..selfcount <<- ..selfcount+1 # in dev, we check no self calls, each of which doubles overhead, or could
135135
# test explicitly if the caller is [.data.table (even stronger test. TO DO.)
@@ -1920,7 +1920,7 @@ replace_dot_alias = function(e) {
19201920
attrs = attr(x, 'index', exact=TRUE)
19211921
skeys = names(attributes(attrs))
19221922
if (!is.null(skeys)) {
1923-
hits = unlist(lapply(paste0("__", names_x[cols]), grep, skeys, fixed=TRUE))
1923+
hits = unlist(lapply(paste0("__", names_x[cols]), function(x) grep(x, skeys, fixed = TRUE)))
19241924
hits = skeys[unique(hits)]
19251925
for (i in seq_along(hits)) setattr(attrs, hits[i], NULL) # does by reference
19261926
}
@@ -2074,17 +2074,19 @@ as.matrix.data.table = function(x, rownames=NULL, rownames.value=NULL, ...) {
20742074
if (is.ff(X[[j]])) X[[j]] = X[[j]][] # nocov to bring the ff into memory, since we need to create a matrix in memory
20752075
xj = X[[j]]
20762076
if (length(dj <- dim(xj)) == 2L && dj[2L] > 1L) {
2077-
if (is.data.table(xj))
2077+
if (inherits(xj, "data.table"))
20782078
xj = X[[j]] = as.matrix(X[[j]])
20792079
dnj = dimnames(xj)[[2L]]
2080-
collabs[[j]] = paste(
2081-
collabs[[j]],
2082-
if (length(dnj) > 0L) dnj else seq_len(dj[2L]), sep = ".")
2080+
collabs[[j]] = paste(collabs[[j]], if (length(dnj) >
2081+
0L)
2082+
dnj
2083+
else seq_len(dj[2L]), sep = ".")
20832084
}
20842085
if (!is.logical(xj))
20852086
all.logical = FALSE
2086-
if (nlevels(xj) > 0L || !(is.numeric(xj) || is.complex(xj) || is.logical(xj)) ||
2087-
(!is.null(cl <- attr(xj, "class", exact=TRUE)) && any(cl %chin% c("Date", "POSIXct", "POSIXlt"))))
2087+
if (length(levels(xj)) > 0L || !(is.numeric(xj) || is.complex(xj) || is.logical(xj)) ||
2088+
(!is.null(cl <- attr(xj, "class", exact=TRUE)) && any(cl %chin%
2089+
c("Date", "POSIXct", "POSIXlt"))))
20882090
non.numeric = TRUE
20892091
if (!is.atomic(xj))
20902092
non.atomic = TRUE
@@ -2102,7 +2104,7 @@ as.matrix.data.table = function(x, rownames=NULL, rownames.value=NULL, ...) {
21022104
if (is.character(X[[j]])) next
21032105
xj = X[[j]]
21042106
miss = is.na(xj)
2105-
xj = if (nlevels(xj)) as.vector(xj) else format(xj)
2107+
xj = if (length(levels(xj))) as.vector(xj) else format(xj)
21062108
is.na(xj) = miss
21072109
X[[j]] = xj
21082110
}
@@ -2134,7 +2136,7 @@ tail.data.table = function(x, n=6L, ...) {
21342136
x[i]
21352137
}
21362138

2137-
"[<-.data.table" = function(x, i, j, value) {
2139+
"[<-.data.table" = function (x, i, j, value) {
21382140
# [<- is provided for consistency, but := is preferred as it allows by group and by reference to subsets of columns
21392141
# with no copy of the (very large, say 10GB) columns at all. := is like an UPDATE in SQL and we like and want two symbols to change.
21402142
if (!cedta()) {
@@ -2238,7 +2240,7 @@ dimnames.data.table = function(x) {
22382240
list(NULL, names(x))
22392241
}
22402242

2241-
"dimnames<-.data.table" = function(x, value) # so that can do colnames(dt)=<..> as well as names(dt)=<..>
2243+
"dimnames<-.data.table" = function (x, value) # so that can do colnames(dt)=<..> as well as names(dt)=<..>
22422244
{
22432245
if (!cedta()) return(`dimnames<-.data.frame`(x,value)) # nocov ; will drop key but names<-.data.table (below) is more common usage and does retain the key
22442246
if (!is.list(value) || length(value) != 2L) stopf("attempting to assign invalid object to dimnames of a data.table")
@@ -2262,7 +2264,7 @@ dimnames.data.table = function(x) {
22622264
x # this returned value is now shallow copied by R 3.1.0 via *tmp*. A very welcome change.
22632265
}
22642266

2265-
within.data.table = function(data, expr, ...)
2267+
within.data.table = function (data, expr, ...)
22662268
# basically within.list but retains key (if any)
22672269
# will be slower than using := or a regular query (see ?within for further info).
22682270
{
@@ -2287,7 +2289,7 @@ within.data.table = function(data, expr, ...)
22872289
ans
22882290
}
22892291

2290-
transform.data.table = function(`_data`, ...)
2292+
transform.data.table = function (`_data`, ...)
22912293
# basically transform.data.frame with data.table instead of data.frame, and retains key
22922294
{
22932295
if (!cedta()) return(NextMethod()) # nocov
@@ -2297,7 +2299,7 @@ transform.data.table = function(`_data`, ...)
22972299
`_data`
22982300
}
22992301

2300-
subset.data.table = function(x, subset, select, ...)
2302+
subset.data.table = function (x, subset, select, ...)
23012303
{
23022304
key.cols = key(x)
23032305

@@ -2346,7 +2348,7 @@ subset.data.table = function(x, subset, select, ...)
23462348
is_na = function(x, by=seq_along(x)) .Call(Cdt_na, x, by)
23472349
any_na = function(x, by=seq_along(x)) .Call(CanyNA, x, by)
23482350

2349-
na.omit.data.table = function(object, cols = seq_along(object), invert = FALSE, ...) {
2351+
na.omit.data.table = function (object, cols = seq_along(object), invert = FALSE, ...) {
23502352
# compare to stats:::na.omit.data.frame
23512353
if (!cedta()) return(NextMethod()) # nocov
23522354
if ( !missing(invert) && is.na(as.logical(invert)) )
@@ -2372,7 +2374,7 @@ which_ = function(x, bool = TRUE) {
23722374
.Call(Cwhichwrapper, x, bool)
23732375
}
23742376

2375-
is.na.data.table = function(x) {
2377+
is.na.data.table = function (x) {
23762378
if (!cedta()) return(`is.na.data.frame`(x))
23772379
do.call("cbind", lapply(x, "is.na"))
23782380
}

R/fcast.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,5 @@ dcast.data.table = function(data, formula, fun.aggregate = NULL, sep = "_", ...,
251251
setattr(ans, 'names', c(lhsnames, allcols))
252252
setDT(ans); setattr(ans, 'sorted', lhsnames)
253253
} else stopf("Internal error -- empty rhsnames in dcast; please report") # nocov
254-
return(ans)
254+
return (ans)
255255
}

R/fdroplevels.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# 647 fast droplevels.data.table method
22
fdroplevels = function(x, exclude = if (anyNA(levels(x))) NULL else NA, ...) {
33
stopifnot(inherits(x, "factor"))
4-
lev = which(tabulate(x, nlevels(x)) & (!match(levels(x), exclude, 0L)))
4+
lev = which(tabulate(x, length(levels(x))) & (!match(levels(x), exclude, 0L)))
55
ans = match(as.integer(x), lev)
66
setattr(ans, 'levels', levels(x)[lev])
77
setattr(ans, 'class', class(x))

R/foverlaps.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ foverlaps = function(x, y, by.x=if (!is.null(key(x))) key(x) else key(y), by.y=k
179179
# CsubsetDT bug has been fixed by Matt. So back to using it! Should improve subset substantially.
180180
if (which) {
181181
if (mult %chin% c("first", "last"))
182-
return(olaps$yid)
182+
return (olaps$yid)
183183
else if (!is.na(nomatch))
184-
return(.Call(CsubsetDT, olaps, which(olaps$yid > 0L), seq_along(olaps)))
185-
else return(olaps)
184+
return (.Call(CsubsetDT, olaps, which(olaps$yid > 0L), seq_along(olaps)))
185+
else return (olaps)
186186
} else {
187187
if (!is.na(nomatch))
188188
olaps = .Call(CsubsetDT, olaps, which(olaps$yid > 0L), seq_along(olaps))
@@ -195,7 +195,7 @@ foverlaps = function(x, y, by.x=if (!is.null(key(x))) key(x) else key(y), by.y=k
195195
xcols2 = setdiff(names(ans), xcols1)
196196
ans[, (ycols) := .Call(CsubsetDT, origy, olaps$yid, chmatch(ycols, names(origy)))]
197197
setcolorder(ans, c(xcols1, ycols, xcols2))
198-
return(ans[])
198+
return (ans[])
199199
}
200200
}
201201

R/fread.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ yaml=FALSE, autostart=NA, tmpdir=tempdir(), tz="UTC")
3333
if (is.na(nrows) || nrows<0) nrows=Inf # accept -1 to mean Inf, as read.table does
3434
if (identical(header,"auto")) header=NA
3535
stopifnot(
36-
is.logical(header), length(header)==1L, # TRUE, FALSE or NA
37-
is.numeric(nThread), length(nThread)==1L
36+
is.logical(header) && length(header)==1L, # TRUE, FALSE or NA
37+
is.numeric(nThread) && length(nThread)==1L
3838
)
3939
nThread=as.integer(nThread)
4040
stopifnot(nThread>=1L)

R/print.data.table.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"),
136136
invisible(x)
137137
}
138138

139-
format.data.table = function(x, ..., justify="none") {
139+
format.data.table = function (x, ..., justify="none") {
140140
if (is.atomic(x) && !is.null(x)) { ## future R can use if (is.atomic(x))
141141

142142
stopf("Internal structure doesn't seem to be a list. Possibly corrupt data.table.")

R/tables.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type_size = function(DT) {
1212
tt = lookup[storage.mode(col)]
1313
if (is.na(tt)) tt = .Machine$sizeof.pointer
1414
tt = tt*nrow(DT)
15-
if (is.factor(col)) tt = tt + nlevels(col)*.Machine$sizeof.pointer
15+
if (is.factor(col)) tt = tt + length(levels(col))*.Machine$sizeof.pointer
1616
ans = ans + tt
1717
}
1818
ans + ncol(DT)*.Machine$sizeof.pointer # column name pointers

R/test.data.table.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ INT = function(...) { as.integer(c(...)) } # utility used in tests.Rraw
311311
gc_mem = function() {
312312
# nocov start
313313
# gc reports memory in MB
314-
m = colSums(gc()[, c(2L, 4L, 6L)])
314+
m = apply(gc()[, c(2L, 4L, 6L)], 2L, sum)
315315
names(m) = c("GC_used", "GC_gc_trigger", "GC_max_used")
316316
m
317317
# nocov end

0 commit comments

Comments
 (0)