Skip to content

Commit 31aa9d4

Browse files
activate implicit_integer_linter (#6762)
1 parent 79aed53 commit 31aa9d4

21 files changed

+79
-78
lines changed

.ci/.lintr.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ linters = c(dt_linters, all_linters(
99
packages = "lintr", # TODO(lintr->3.2.0): Remove this.
1010
# eq_assignment_linter(),
1111
brace_linter(allow_single_line = TRUE),
12+
implicit_integer_linter(allow_colon = TRUE),
1213
# TODO(michaelchirico): Activate these incrementally. These are the
1314
# parameterizations that match our style guide.
1415
# implicit_assignment_linter(allow_lazy = TRUE, allow_scoped = TRUE),
15-
# implicit_integer_linter(allow_colon = TRUE),
1616
# system_time_linter = undesirable_function_linter(c(
1717
# system.time = "Only run timings in benchmark.Rraw"
1818
# )),
@@ -85,6 +85,7 @@ exclusions = c(local({
8585
undesirable_function_linter = Inf
8686
)),
8787
exclusion_for_dir(c("vignettes", "vignettes/fr"), list(
88+
implicit_integer_linter = Inf,
8889
quotes_linter = Inf,
8990
sample_int_linter = Inf
9091
# strings_as_factors_linter = Inf

.dev/CRAN_Release.cmd

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,6 @@ grep -P "\t" ./src/*.c
114114
grep -n "[^A-Za-z0-9]T[^A-Za-z0-9]" ./inst/tests/tests.Rraw
115115
grep -n "[^A-Za-z0-9]F[^A-Za-z0-9]" ./inst/tests/tests.Rraw
116116

117-
# All integers internally should have L suffix to avoid lots of one-item coercions
118-
# Where 0 numeric is intended we should perhaps use 0.0 for clarity and make the grep easier
119-
# 1) tolerance=0 usages in setops.R are valid numeric 0, as are anything in strings
120-
# 2) leave the rollends default using roll>=0 though; comments in PR #3803
121-
grep -Enr "^[^#]*(?:\[|==|>|<|>=|<=|,|\(|\+)\s*[-]?[0-9]+[^0-9L:.e]" R | grep -Ev "stop|warning|tolerance"
122-
123117
# Never use ifelse. fifelse for vectors when necessary (nothing yet)
124118
grep -Enr "\bifelse" R
125119

R/IDateTime.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ as.ITime.POSIXlt = function(x, ms = 'truncate', ...) {
186186
}
187187

188188
as.ITime.times = function(x, ms = 'truncate', ...) {
189-
secs = 86400 * (unclass(x) %% 1)
189+
secs = 86400L * (unclass(x) %% 1L)
190190
secs = clip_msec(secs, ms)
191191
(setattr(secs, "class", "ITime")) # the first line that creates sec will create a local copy so we can use setattr() to avoid potential copy of class()<-
192192
}
@@ -238,16 +238,16 @@ rep.ITime = function(x, ...)
238238
round.ITime <- function(x, digits = c("hours", "minutes"), ...)
239239
{
240240
(setattr(switch(match.arg(digits),
241-
hours = as.integer(round(unclass(x)/3600)*3600),
242-
minutes = as.integer(round(unclass(x)/60)*60)),
241+
hours = as.integer(round(unclass(x)/3600.0)*3600.0),
242+
minutes = as.integer(round(unclass(x)/60.0)*60.0)),
243243
"class", "ITime"))
244244
}
245245

246246
trunc.ITime <- function(x, units = c("hours", "minutes"), ...)
247247
{
248248
(setattr(switch(match.arg(units),
249-
hours = as.integer(unclass(x)%/%3600*3600),
250-
minutes = as.integer(unclass(x)%/%60*60)),
249+
hours = as.integer(unclass(x)%/%3600.0*3600.0),
250+
minutes = as.integer(unclass(x)%/%60.0*60.0)),
251251
"class", "ITime"))
252252
}
253253

@@ -280,7 +280,7 @@ IDateTime.default = function(x, ...) {
280280

281281
# POSIXt support
282282

283-
as.POSIXct.IDate = function(x, tz = "UTC", time = 0, ...) {
283+
as.POSIXct.IDate = function(x, tz = "UTC", time = 0.0, ...) {
284284
if (missing(time) && inherits(tz, "ITime")) {
285285
time = tz # allows you to use time as the 2nd argument
286286
tz = "UTC"

R/between.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,13 @@ inrange = function(x,lower,upper,incbounds=TRUE) {
7676
verbose = isTRUE(getOption("datatable.verbose"))
7777
if (verbose) {last.started.at=proc.time();catf("forderv(query) took ... ");flush.console()}
7878
if (verbose) {cat(timetaken(last.started.at),"\n"); flush.console()}
79-
ans = bmerge(shallow(subject), query, 1L:2L, c(1L,1L),
80-
0, c(FALSE, TRUE), 0L, "all", ops, verbose) # fix for #1819, turn on verbose messages
79+
ans = bmerge(
80+
shallow(subject), query,
81+
icols=1L:2L, xcols=c(1L, 1L),
82+
roll=0.0, rollends=c(FALSE, TRUE),
83+
nomatch=0L, mult="all",
84+
ops=ops, verbose=verbose # fix for #1819, turn on verbose messages
85+
)
8186
xo = ans$xo
8287
options(datatable.verbose=FALSE)
8388
setDT(ans[c("starts", "lens")], key=c("starts", "lens"))

R/data.table.R

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ replace_dot_alias = function(e) {
128128
}
129129
}
130130

131-
"[.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, showProgress=getOption("datatable.showProgress", interactive()))
131+
"[.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.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, showProgress=getOption("datatable.showProgress", interactive()))
132132
{
133133
# ..selfcount <<- ..selfcount+1 # in dev, we check no self calls, each of which doubles overhead, or could
134134
# test explicitly if the caller is [.data.table (even stronger test. TO DO.)
@@ -149,7 +149,7 @@ replace_dot_alias = function(e) {
149149
}
150150
if (!missing(verbose)) {
151151
if (!is.integer(verbose) && !is.logical(verbose)) stopf("verbose must be logical or integer")
152-
if (length(verbose)!=1 || anyNA(verbose)) stopf("verbose must be length 1 non-NA")
152+
if (length(verbose)!=1L || anyNA(verbose)) stopf("verbose must be length 1 non-NA")
153153
# set the global verbose option because that is fetched from C code without having to pass it through
154154
oldverbose = options(datatable.verbose=verbose)
155155
on.exit(options(oldverbose))
@@ -215,7 +215,7 @@ replace_dot_alias = function(e) {
215215
# TO DO (document/faq/example). Removed for now ... if ((roll || rolltolast) && missing(mult)) mult="last" # for when there is exact match to mult. This does not control cases where the roll is mult, that is always the last one.
216216
.unsafe.opt() #3585
217217
missingnomatch = missing(nomatch)
218-
nomatch0 = identical(nomatch,0) || identical(nomatch,0L) || identical(nomatch, FALSE) # for warning with row-numbers in i; #4353
218+
nomatch0 = identical(nomatch,0.0) || identical(nomatch,0L) || identical(nomatch, FALSE) # for warning with row-numbers in i; #4353
219219
if (nomatch0) nomatch=NULL # retain nomatch=0|FALSE backwards compatibility, #857 #5214
220220
if (!is.null(nomatch)) {
221221
if (!(length(nomatch)==1L && is.na(nomatch))) stopf("nomatch= must be either NA or NULL (or 0 for backwards compatibility which is the same as NULL but please use NULL)")
@@ -572,7 +572,7 @@ replace_dot_alias = function(e) {
572572
## benchmarks have shown that starting with 1e6 irows, a tweak can significantly reduce time
573573
## (see #2366)
574574
if (verbose) {last.started.at=proc.time();catf("Reordering %d rows after bmerge done in ... ", length(irows));flush.console()}
575-
if(length(irows) < 1e6){
575+
if(length(irows) < 1e6L){
576576
irows = fsort(irows, internal=TRUE) ## internally, fsort on integer falls back to forderv
577577
} else {
578578
irows = as.integer(fsort(as.numeric(irows))) ## nocov; parallelized for numeric, but overhead of type conversion
@@ -1901,20 +1901,20 @@ replace_dot_alias = function(e) {
19011901
}
19021902

19031903
# adding ghead/gtail(n) support for n > 1 #5060 #523
1904-
q3 = 0
1904+
q3 = 0L
19051905
if (!is.symbol(jsub)) {
19061906
headTail_arg = function(q) {
19071907
if (length(q)==3L && length(q3 <- q[[3L]])==1L && is.numeric(q3) &&
1908-
(q[[1L]]) %chin% c("ghead", "gtail") && q3!=1) q3
1909-
else 0
1908+
(q[[1L]]) %chin% c("ghead", "gtail") && q3!=1L) q3
1909+
else 0L
19101910
}
19111911
if (jsub %iscall% "list"){
19121912
q3 = max(sapply(jsub, headTail_arg))
19131913
} else if (length(jsub)==3L) {
19141914
q3 = headTail_arg(jsub)
19151915
}
19161916
}
1917-
if (q3 > 0) {
1917+
if (q3 > 0L) {
19181918
grplens = pmin.int(q3, len__)
19191919
g = lapply(g, rep.int, times=grplens)
19201920
} else if (.is_nrows(jsub)) {
@@ -2738,7 +2738,7 @@ setcolorder = function(x, neworder=key(x), before=NULL, after=NULL, skip_absent=
27382738
if (length(before)>1L || length(after)>1L)
27392739
stopf("before=/after= accept a single column name or number, not more than one")
27402740
neworder = colnamesInt(x, neworder, check_dups=FALSE, skip_absent=skip_absent) # dups are now checked inside Csetcolorder below
2741-
neworder = neworder[neworder != 0] # tests 498.11, 498.13 fail w/o this
2741+
neworder = neworder[neworder != 0L] # tests 498.11, 498.13 fail w/o this
27422742
if (length(before))
27432743
neworder = c(setdiff(seq_len(colnamesInt(x, before) - 1L), neworder), neworder)
27442744
if (length(after))
@@ -3089,10 +3089,10 @@ gweighted.mean = function(x, w, ..., na.rm=FALSE) {
30893089
else {
30903090
if (na.rm) { # take those indices out of the equation by setting them to 0
30913091
ix <- is.na(x)
3092-
x[ix] <- 0
3093-
w[ix] <- 0
3092+
x[ix] <- 0.0
3093+
w[ix] <- 0.0
30943094
}
3095-
gsum((w!=0)*x*w, na.rm=FALSE)/gsum(w, na.rm=FALSE)
3095+
gsum((w!=0.0)*x*w, na.rm=FALSE)/gsum(w, na.rm=FALSE)
30963096
}
30973097
}
30983098
gprod = function(x, na.rm=FALSE) .Call(Cgprod, x, na.rm)
@@ -3246,7 +3246,7 @@ is_constantish = function(q, check_singleton=FALSE) {
32463246
## redirect to normal DT[x == TRUE]
32473247
stub = call("==", as.symbol(col), TRUE)
32483248
}
3249-
if (length(stub[[1L]]) != 1) return(NULL) # nocov Whatever it is, definitely not one of the valid operators
3249+
if (length(stub[[1L]]) != 1L) return(NULL) # nocov Whatever it is, definitely not one of the valid operators
32503250
operator = as.character(stub[[1L]])
32513251
if (!operator %chin% validOps$op) return(NULL) ## operator not supported
32523252
if (!is.name(stub[[2L]])) return(NULL)
@@ -3287,7 +3287,7 @@ is_constantish = function(q, check_singleton=FALSE) {
32873287
}
32883288
if (length(i) == 0L) internal_error("i became length-0") # nocov
32893289
## convert i to data.table with all combinations in rows.
3290-
if(length(i) > 1L && prod(lengths(i)) > 1e4){
3290+
if(length(i) > 1L && prod(lengths(i)) > 1e4L){
32913291
## CJ would result in more than 1e4 rows. This would be inefficient, especially memory-wise #2635
32923292
if (verbose) {catf("Subsetting optimization disabled because the cross-product of RHS values exceeds 1e4, causing memory problems.\n");flush.console()}
32933293
return(NULL)

R/fdroplevels.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ setdroplevels = function(x, except=NULL, exclude=NULL) {
1919
if (!nrow(x)) return(invisible(x))
2020
ix = vapply_1b(x, is.factor)
2121
if (!is.null(except)) {
22-
stopifnot(is.numeric(except), except >= 1, except <= length(x))
22+
stopifnot(is.numeric(except), except >= 1L, except <= length(x))
2323
ix[except] = FALSE
2424
}
2525
if (!any(ix)) return(invisible(x))

R/fmelt.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ patterns = function(..., cols=character(0L), ignore.case=FALSE, perl=FALSE, fixe
3131

3232
measure = function(..., sep="_", pattern, cols, multiple.keyword="value.name") {
3333
mcall = match.call()
34-
L = as.list(mcall)[-1]
34+
L = as.list(mcall)[-1L]
3535
formal.names = names(formals())
3636
formal.i.vec = which(names(L) %in% formal.names)
3737
fun.list = L[-formal.i.vec]
@@ -52,7 +52,7 @@ measure = function(..., sep="_", pattern, cols, multiple.keyword="value.name") {
5252
# evaluate each value in ... and stop if not function.
5353
for (fun.i in which(user.named)) {
5454
fun = eval(fun.list[[fun.i]], parent.frame(1L))
55-
if (!is.function(fun) || length(formals(args(fun)))==0) {
55+
if (!is.function(fun) || length(formals(args(fun)))==0L) {
5656
stopf("each ... argument to measure must be a function with at least one argument, problem: %s", names(fun.list)[[fun.i]])
5757
}
5858
fun.list[[fun.i]] = fun
@@ -66,7 +66,7 @@ measurev = function(fun.list, sep="_", pattern, cols, multiple.keyword="value.na
6666
if (!missing(sep) && !missing(pattern)) {
6767
stopf("both sep and pattern arguments used; must use either sep or pattern (not both)")
6868
}
69-
if (!(is.character(multiple.keyword) && length(multiple.keyword)==1 && !is.na(multiple.keyword) && nzchar(multiple.keyword))) {
69+
if (!(is.character(multiple.keyword) && length(multiple.keyword)==1L && !is.na(multiple.keyword) && nzchar(multiple.keyword))) {
7070
stopf("multiple.keyword must be a character string with nchar>0")
7171
}
7272
if (!is.character(cols)) {
@@ -89,7 +89,7 @@ measurev = function(fun.list, sep="_", pattern, cols, multiple.keyword="value.na
8989
stopf("pattern must be character string")
9090
}
9191
match.vec = regexpr(pattern, cols, perl=TRUE)
92-
measure.vec.i = which(0 < match.vec)
92+
measure.vec.i = which(match.vec > 0L)
9393
if (length(measure.vec.i) == 0L) {
9494
stopf("pattern did not match any cols, so nothing would be melted; fix by changing pattern")
9595
}
@@ -111,7 +111,7 @@ measurev = function(fun.list, sep="_", pattern, cols, multiple.keyword="value.na
111111
list.of.vectors = strsplit(cols, sep, fixed=TRUE)
112112
vector.lengths = lengths(list.of.vectors)
113113
n.groups = max(vector.lengths)
114-
if (n.groups == 1) {
114+
if (n.groups == 1L) {
115115
stopf("each column name results in only one item after splitting using sep, which means that all columns would be melted; to fix please either specify melt on all columns directly without using measure, or use a different sep/pattern specification")
116116
}
117117
if (n.groups != length(fun.list)) {
@@ -135,7 +135,7 @@ measurev = function(fun.list, sep="_", pattern, cols, multiple.keyword="value.na
135135
for (group.i in fun.i.vec) {
136136
group.name = names(fun.list)[[group.i]]
137137
fun = fun.list[[group.i]]
138-
if (!is.function(fun) || length(formals(args(fun)))==0) {
138+
if (!is.function(fun) || length(formals(args(fun))) == 0L) {
139139
stopf("in the measurev fun.list, each non-NULL element must be a function with at least one argument, problem: %s", group.name)
140140
}
141141
group.val = fun(group.dt[[group.name]])

R/foverlaps.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ foverlaps = function(x, y, by.x=if (!is.null(key(x))) key(x) else key(y), by.y=k
9090
# next representative double > x under the given precision (48,56 or 64-bit in data.table) = x*incr
9191
dt_eps = function() {
9292
bits = floor(log2(.Machine$double.eps))
93-
2 ^ (bits + (getNumericRounding() * 8L))
93+
2L ^ (bits + (getNumericRounding() * 8L))
9494
}
9595
isdouble = TRUE
9696
isposix = "POSIXct" %chin% yclass

R/fread.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ yaml=FALSE, autostart=NULL, tmpdir=tempdir(), tz="UTC")
3232
)
3333
fill = if(identical(fill, Inf)) .Machine$integer.max else as.integer(fill)
3434
nrows=as.double(nrows) #4686
35-
if (is.na(nrows) || nrows<0) nrows=Inf # accept -1 to mean Inf, as read.table does
35+
if (is.na(nrows) || nrows<0L) nrows=Inf # accept -1 to mean Inf, as read.table does
3636
if (identical(header,"auto")) header=NA
3737
stopifnot(
3838
is.logical(header), length(header)==1L, # TRUE, FALSE or NA
@@ -271,7 +271,7 @@ yaml=FALSE, autostart=NULL, tmpdir=tempdir(), tz="UTC")
271271
if (is.integer(skip)) skip = skip + n_read
272272
}
273273
# nocov end
274-
warnings2errors = getOption("warn") >= 2
274+
warnings2errors = getOption("warn") >= 2L
275275
stopifnot(identical(tz,"UTC") || identical(tz,""))
276276
if (tz=="") {
277277
tt = Sys.getenv("TZ", unset=NA_character_)

R/fwrite.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fwrite = function(x, file="", append=FALSE, quote="auto",
77
logicalAsInt=NULL,
88
scipen=getOption('scipen', 0L),
99
dateTimeAs = c("ISO","squash","epoch","write.csv"),
10-
buffMB=8, nThread=getDTthreads(verbose),
10+
buffMB=8L, nThread=getDTthreads(verbose),
1111
showProgress=getOption("datatable.showProgress", interactive()),
1212
compress = c("auto", "none", "gzip"),
1313
compressLevel = 6L,
@@ -52,7 +52,7 @@ fwrite = function(x, file="", append=FALSE, quote="auto",
5252
is.character(eol) && length(eol)==1L,
5353
length(qmethod) == 1L && qmethod %chin% c("double", "escape"),
5454
length(compress) == 1L && compress %chin% c("auto", "none", "gzip"),
55-
length(compressLevel) == 1L && 0 <= compressLevel && compressLevel <= 9,
55+
length(compressLevel) == 1L && 0L <= compressLevel && compressLevel <= 9L,
5656
isTRUEorFALSE(col.names), isTRUEorFALSE(append), isTRUEorFALSE(row.names),
5757
isTRUEorFALSE(verbose), isTRUEorFALSE(showProgress), isTRUEorFALSE(logical01),
5858
isTRUEorFALSE(bom),

0 commit comments

Comments
 (0)