Skip to content

Commit fc43386

Browse files
Add a mask for future %||%, use it (#6826)
* Add a mask for future %||%, use it * cemented name in lintr main
1 parent d45546b commit fc43386

File tree

7 files changed

+15
-13
lines changed

7 files changed

+15
-13
lines changed

R/IDateTime.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ as.IDate.POSIXct = function(x, tz = attr(x, "tzone", exact=TRUE), ...) {
4040
if (is_utc(tz))
4141
(setattr(as.integer(as.numeric(x) %/% 86400L), "class", c("IDate", "Date"))) # %/% returns new object so can use setattr() on it; wrap with () to return visibly
4242
else
43-
as.IDate(as.Date(x, tz = if (is.null(tz)) '' else tz, ...))
43+
as.IDate(as.Date(x, tz = tz %||% '', ...))
4444
}
4545

4646
as.IDate.IDate = function(x, ...) x
@@ -147,7 +147,7 @@ as.ITime.default = function(x, ...) {
147147

148148
as.ITime.POSIXct = function(x, tz = attr(x, "tzone", exact=TRUE), ...) {
149149
if (is_utc(tz)) as.ITime(unclass(x), ...)
150-
else as.ITime(as.POSIXlt(x, tz = if (is.null(tz)) '' else tz, ...), ...)
150+
else as.ITime(as.POSIXlt(x, tz = tz %||% '', ...), ...)
151151
}
152152

153153
as.ITime.numeric = function(x, ms = 'truncate', ...) {

R/between.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ between = function(x, lower, upper, incbounds=TRUE, NAbounds=TRUE, check=FALSE)
1818
# POSIX check timezone match
1919
if (is.px(x) && is.px(lower) && is.px(upper)) {
2020
tzs = sapply(list(x,lower,upper), function(x) {
21-
tt = attr(x,"tzone",exact=TRUE)
22-
if (is.null(tt)) "" else tt
21+
attr(x, "tzone", exact=TRUE) %||% ""
2322
})
2423
# lower/upper should be more tightly linked than x/lower, so error
2524
# if the former don't match but only inform if they latter don't

R/data.table.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ replace_dot_alias = function(e) {
640640
# Doing this once here, helps speed later when repeatedly subsetting each column. R's [irows] would do this for each
641641
# column when irows contains negatives.
642642
}
643-
if (which) return( if (is.null(irows)) seq_len(nrow(x)) else irows )
643+
if (which) return(irows %||% seq_len(nrow(x)))
644644
} else { # missing(i)
645645
i = NULL
646646
}
@@ -757,7 +757,7 @@ replace_dot_alias = function(e) {
757757
if (".I" %in% bysubl) { #1732
758758
if (!is.symbol(bysub) && (length(bysubl)!=2L || !is.symbol(bysubl[[2L]]) || !(bysubl[[1L]] %chin% c(".","c","list"))))
759759
stopf("'by' contains .I but only the following are currently supported: by=.I, by=.(.I), by=c(.I), by=list(.I)")
760-
bysub = if (is.null(irows)) seq_len(nrow(x)) else irows
760+
bysub = irows %||% seq_len(nrow(x))
761761
bysuborig = as.symbol("I")
762762
}
763763
if (is.name(bysub) && !(bysub %chin% names_x)) { # TO DO: names(x),names(i),and i. and x. prefixes
@@ -1724,7 +1724,7 @@ replace_dot_alias = function(e) {
17241724
jl__ = as.list(jsubl[[i_]])[-1L] # just keep the '.' from list(.)
17251725
if (isTRUE(nzchar(names(jsubl)[i_]))) {
17261726
# Fix for #2311, prepend named list arguments of c() to that list's names. See tests 2283.*
1727-
njl__ = if (is.null(names(jl__))) rep("", length(jl__)) else names(jl__)
1727+
njl__ = names(jl__) %||% rep("", length(jl__))
17281728
njl__nonblank = nzchar(names(jl__))
17291729
if (length(jl__) > 1L) {
17301730
jn__ = paste0(names(jsubl)[i_], seq_along(jl__))
@@ -1733,7 +1733,7 @@ replace_dot_alias = function(e) {
17331733
}
17341734
jn__[njl__nonblank] = paste(names(jsubl)[i_], njl__[njl__nonblank], sep=".")
17351735
} else {
1736-
jn__ = if (is.null(names(jl__))) rep("", length(jl__)) else names(jl__)
1736+
jn__ = names(jl__) %||% rep("", length(jl__))
17371737
}
17381738
idx = unlist(lapply(jl__, function(x) is.name(x) && x == ".I"))
17391739
if (any(idx))
@@ -2164,7 +2164,7 @@ as.matrix.data.table = function(x, rownames=NULL, rownames.value=NULL, ...) {
21642164
# retain highest type of input for empty output, #4762
21652165
if (length(X)!=0L)
21662166
internal_error("length(X)==%d but a dimension is zero", length(X)) # nocov
2167-
return(array(if (is.null(X)) NA else X, dim = dm, dimnames = list(rownames.value, cn)))
2167+
return(array(X %||% NA, dim=dm, dimnames=list(rownames.value, cn)))
21682168
}
21692169
dim(X) = c(n, length(X)/n)
21702170
dimnames(X) = list(rownames.value, unlist(collabs, use.names = FALSE))

R/foverlaps.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
foverlaps = function(x, y, by.x=if (!is.null(key(x))) key(x) else key(y), by.y=key(y), maxgap=0L, minoverlap=1L, type=c("any", "within", "start", "end", "equal"), mult=c("all", "first", "last"), nomatch=NA, which=FALSE, verbose=getOption("datatable.verbose")) {
1+
foverlaps = function(x, y, by.x=key(x) %||% key(y), by.y=key(y), maxgap=0L, minoverlap=1L, type=c("any", "within", "start", "end", "equal"), mult=c("all", "first", "last"), nomatch=NA, which=FALSE, verbose=getOption("datatable.verbose")) {
22

33
if (!is.data.table(y) || !is.data.table(x)) stopf("y and x must both be data.tables. Use `setDT()` to convert list/data.frames to data.tables by reference or as.data.table() to convert to data.tables by copying.")
44
maxgap = as.integer(maxgap); minoverlap = as.integer(minoverlap)
@@ -78,7 +78,7 @@ foverlaps = function(x, y, by.x=if (!is.null(key(x))) key(x) else key(y), by.y=k
7878
stopf("Some interval cols are of type POSIXct while others are not. Please ensure all interval cols are (or are not) of POSIXct type")
7979
}
8080
# #1143, mismatched timezone
81-
getTZ = function(x) if (is.null(tz <- attr(x, "tzone", exact=TRUE))) "" else tz # "" == NULL AFAICT
81+
getTZ = function(x) attr(x, "tzone", exact=TRUE) %||% "" # "" == NULL AFAICT
8282
tzone_chk = c(getTZ(xval1), getTZ(xval2), getTZ(yval1), getTZ(yval2))
8383
if (length(unique(tzone_chk)) > 1L) {
8484
warningf("POSIXct interval cols have mixed timezones. Overlaps are performed on the internal numerical representation of POSIXct objects (always in UTC epoch time), therefore printed values may give the impression that values don't overlap but their internal representations do Please ensure that POSIXct type interval cols have identical 'tzone' attributes to avoid confusion.")

R/print.data.table.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ paste_dims = function(x) {
172172
dims = if (isS4(x)) {
173173
length(slotNames(x))
174174
} else {
175-
if (is.null(dim(x))) length(x) else dim(x)
175+
dim(x) %||% length(x)
176176
}
177177
paste0("[", paste(dims,collapse="x"), "]")
178178
}

R/utils.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ nan_is_na = function(x) {
2121
stopf("Argument 'nan' must be NA or NaN")
2222
}
2323

24+
# R 4.4.0
25+
if (!exists("%||%", "package:base")) `%||%` <- function(x, y) if (is.null(x)) y else x # nolint: coalesce_linter.
26+
2427
internal_error = function(...) {
2528
e1 = gettext("Internal error in")
2629
e2 = deparse(head(tail(sys.calls(), 2L), 1L)[[1L]][[1L]])

man/foverlaps.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ could be changed.
1616
}
1717

1818
\usage{
19-
foverlaps(x, y, by.x = if (!is.null(key(x))) key(x) else key(y),
19+
foverlaps(x, y, by.x = key(x) \%||\% key(y),
2020
by.y = key(y), maxgap = 0L, minoverlap = 1L,
2121
type = c("any", "within", "start", "end", "equal"),
2222
mult = c("all", "first", "last"),

0 commit comments

Comments
 (0)