Skip to content

Commit 9bafc08

Browse files
more formal styling with lintr
1 parent d769cba commit 9bafc08

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

inst/tests/other.Rraw

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -792,13 +792,13 @@ if (loaded[["DBI"]] && loaded[["RSQLite"]]) {
792792
# ln, rn: lhs names, rhs names, symmult: symmetric mult
793793
mult_all = function(tbl, cols, ...) sprintf(
794794
"(\n SELECT %s FROM %s \n) %s",
795-
paste(setdiff(cols, "row_id"), collapse=", "), tbl, tbl
795+
toString(setdiff(cols, "row_id")), tbl, tbl
796796
)
797797
mult_one = function(tbl, cols, on, mult) sprintf(
798798
"(SELECT %s FROM (\n SELECT *, ROW_NUMBER() OVER (PARTITION BY %s ORDER BY row_id %s) AS rownum FROM %s \n) %s WHERE rownum=1) %s",
799-
paste(setdiff(cols, c("row_id", "rownum")), collapse=", "),
800-
paste(on, collapse=", "),
801-
if (mult=="first") "ASC" else "DESC",
799+
toString(setdiff(cols, c("row_id", "rownum"))),
800+
toString(on),
801+
if (mult == "first") "ASC" else "DESC",
802802
tbl, tbl, tbl
803803
)
804804
sql = function(how, on, mult, ln, rn, symmult=FALSE, notjoin=FALSE) {
@@ -813,7 +813,7 @@ if (loaded[["DBI"]] && loaded[["RSQLite"]]) {
813813
}
814814
nm = list()
815815
nm[["lhs"]] = ln; nm[["rhs"]] = rn
816-
using = sprintf("USING (%s)", paste(on, collapse=", "))
816+
using = sprintf("USING (%s)", toString(on))
817817
lhs = "lhs"; rhs = "rhs"
818818
join = if (how == "inner") {
819819
if (mult == "all") sprintf("%s \n INNER JOIN \n %s \n %s", mult_all(lhs, nm[[lhs]]), mult_all(rhs, nm[[rhs]]), using)
@@ -834,7 +834,7 @@ if (loaded[["DBI"]] && loaded[["RSQLite"]]) {
834834
sprintf("SELECT %s FROM \n %s%s", select, join, where)
835835
}
836836

837-
dbSend <- function(..., silent=FALSE) try(suppressWarnings(DBI::dbSendQuery(...)), silent=silent)
837+
dbSend = function(..., silent=FALSE) try(suppressWarnings(DBI::dbSendQuery(...)), silent=silent)
838838

839839
# .conn SQLite connection, if provided it will use it instead of creating temporary one
840840
# .drop logical TRUE (default) will drop db tables before and after and populate new, when FALSE it expects tables to be populated
@@ -844,7 +844,7 @@ if (loaded[["DBI"]] && loaded[["RSQLite"]]) {
844844
names(l) = c("lhs", "rhs")
845845
lhs = l[["lhs"]]; rhs = l[["rhs"]]
846846
stopifnot(is.data.table(lhs), is.data.table(rhs),
847-
is.character(how), is.character(mult), length(mult)==1L,
847+
is.character(how), is.character(mult), length(mult) == 1L,
848848
is.character(on),
849849
is.logical(allow.cartesian), is.logical(.drop))
850850
if (err && mult == "error") {
@@ -875,7 +875,7 @@ if (loaded[["DBI"]] && loaded[["RSQLite"]]) {
875875
s = sql(how, on, mult, names(lhs), names(rhs))
876876
s = paste0(s, ";\n")
877877
# run data.table and SQLite
878-
dt = mergelist(list(lhs[,!"row_id"], rhs[,!"row_id"]), on=on, how=how, mult=mult)
878+
dt = mergelist(list(lhs[, !"row_id"], rhs[, !"row_id"]), on=on, how=how, mult=mult)
879879
sq = try(silent=TRUE, as.data.table(DBI::dbGetQuery(conn, s)))
880880
if (inherits(sq, "try-error")) {
881881
if (.debug) {message("error during sql statement"); browser()}
@@ -921,7 +921,7 @@ if (loaded[["DBI"]] && loaded[["RSQLite"]]) {
921921
if (!isTRUE(a)) {
922922
if (.debug) browser()
923923
cat(sep="\n", c(
924-
sprintf("# dtq:\nmergelist(l, on='%s', how='%s', mult='%s')", paste(on, collapse=", "), how, mult),
924+
sprintf("# dtq:\nmergelist(l, on='%s', how='%s', mult='%s')", toString(on), how, mult),
925925
sprintf("# sql:\n%s", s),
926926
a, "\n"))
927927
}
@@ -949,13 +949,13 @@ if (loaded[["DBI"]] && loaded[["RSQLite"]]) {
949949
DBI::dbWriteTable(conn, name="lhs", value=lhs)
950950
DBI::dbWriteTable(conn, name="rhs", value=rhs)
951951
len = prod(length(cases), length(hows), length(mults))
952-
if (len > (len.warn <- getOption("tests.length.warning", 1e3)))
952+
if (len > (len.warn <- getOption("tests.length.warning", 1000L)))
953953
warning("You are about to run ", len.warn, " tests. To suppress this warning use the 'tests.length.warning' option.")
954954
for (how in hows) {
955955
ans[[case]][[how]] = list()
956956
for (mult in mults) {
957957
if (!is.null(ans[[case]][[how]][[mult]])) {
958-
dup_n = dup_n+1L
958+
dup_n = dup_n + 1L
959959
next #warning("Some tests are duplicated, so far ", dup_n)
960960
}
961961
ans[[case]][[how]][[mult]] = join.sql.equal(list(lhs=lhs, rhs=rhs), on=on, how=how, mult=mult, .conn=conn, .drop=FALSE, .debug=.debug)
@@ -970,7 +970,7 @@ if (loaded[["DBI"]] && loaded[["RSQLite"]]) {
970970
ans
971971
}
972972
case_data = function(case) {
973-
set.seed(108)
973+
set.seed(108L)
974974
if (case == 1L) { # 2 match
975975
lhs = data.table(id = c(1L, 5L, 3L, 7L), v1=1:4)
976976
rhs = data.table(id = c(2L, 4L, 3L, 5L), v2=1:4)
@@ -1005,8 +1005,8 @@ if (loaded[["DBI"]] && loaded[["RSQLite"]]) {
10051005
lhs = data.table(id = c(1L, 1L, 1L, 1L), v1=1:4)
10061006
rhs = data.table(id = c(2L, 2L, 2L, 2L), v2=1:4)
10071007
} else if (case == 12L) { # no match, no overlap
1008-
lhs = data.table(id = c(1:4), v1=1:4)
1009-
rhs = data.table(id = c(6:9), v2=1:4)
1008+
lhs = data.table(id = 1:4, v1=1:4)
1009+
rhs = data.table(id = 6:9, v2=1:4)
10101010
} else if (case == 13L) { # all i matches
10111011
lhs = data.table(id = c(1L, 5L, 3L, 7L, 9L), v1=1:5)
10121012
rhs = data.table(id = c(7L, 5L, 3L, 1L), v2=1:4)
@@ -1023,48 +1023,48 @@ if (loaded[["DBI"]] && loaded[["RSQLite"]]) {
10231023
lhs = data.table(id = sample(10L, 10L, TRUE), v1=1:10)
10241024
rhs = data.table(id = sample(10L, 10L, TRUE), v2=1:10)
10251025
} else if (case == 17L) {
1026-
lhs = data.table(id = sample(1e2L, 1e2L, TRUE), v1=1:1e2)
1027-
rhs = data.table(id = sample(1e2L, 1e2L, TRUE), v2=1:1e2)
1026+
lhs = data.table(id = sample(100L, 100L, TRUE), v1=1:100)
1027+
rhs = data.table(id = sample(100L, 100L, TRUE), v2=1:100)
10281028
} else if (case == 18L) {
1029-
lhs = data.table(id = sample(1e2L, 1e2L, TRUE), v1=1:1e2)
1030-
rhs = data.table(id = sample(10L, 20L, TRUE), v2=1:1e2)
1031-
} else if (case==19L) {
1032-
lhs = as.data.table(list(id=sample(1e3), v1=1:1e3))
1033-
rhs = as.data.table(list(id=sample(1e3), v2=1:1e3))
1034-
} else if (case==20L) {
1035-
lhs = as.data.table(list(id=sample(1e3*2L, 1e3), v1=1:1e3))
1036-
rhs = as.data.table(list(id=sample(1e3*2L, 1e3), v2=1:1e3))
1037-
} else if (case==21L) {
1038-
lhs = as.data.table(list(id=sample(1e3, 1e3*2L, TRUE), v1=1:1e3))
1039-
rhs = as.data.table(list(id=sample(1e3, 1e3*2L, TRUE), v2=1:1e3))
1040-
} else if (case==22L) { ## LHS equals RHS
1029+
lhs = data.table(id = sample(100L, 100L, TRUE), v1=1:100)
1030+
rhs = data.table(id = sample(10L, 20L, TRUE), v2=1:100)
1031+
} else if (case == 19L) {
1032+
lhs = as.data.table(list(id=sample(1000L), v1=1:1000))
1033+
rhs = as.data.table(list(id=sample(1000L), v2=1:1000))
1034+
} else if (case == 20L) {
1035+
lhs = as.data.table(list(id=sample(2000L, 1000L), v1=1:1000))
1036+
rhs = as.data.table(list(id=sample(2000L, 1000L), v2=1:1000))
1037+
} else if (case == 21L) {
1038+
lhs = as.data.table(list(id=sample(1000L, 2000L, TRUE), v1=1:1000))
1039+
rhs = as.data.table(list(id=sample(1000L, 2000L, TRUE), v2=1:1000))
1040+
} else if (case == 22L) { ## LHS equals RHS
10411041
lhs = data.table(id=1:2, v1=1:2)
10421042
rhs = data.table(id=1:2, v2=1:2)
1043-
} else if (case==23L) { ## cross join
1043+
} else if (case == 23L) { ## cross join
10441044
lhs = data.table(id=c(1L, 1L), v1=1:2)
10451045
rhs = data.table(id=c(1L, 1L), v2=1:2)
1046-
} else if (case==24L) { ## cartesian match, dups on both sides of match
1046+
} else if (case == 24L) { ## cartesian match, dups on both sides of match
10471047
lhs = data.table(id=c(1L, 1:2), v1=1:3)
10481048
rhs = data.table(id=c(1L, 1L, 3L), v2=1:3)
1049-
} else if (case==25L) { ## duplicates in RHS
1049+
} else if (case == 25L) { ## duplicates in RHS
10501050
lhs = data.table(id=1:2, v1=1:2)
10511051
rhs = data.table(id=c(2L, 2:3), v2=1:3)
1052-
} else if (case==26L) { ## duplicates in RHS and LHS, some RHS dups does not have matches in LHS (merge.data.table+mult fails)
1052+
} else if (case == 26L) { ## duplicates in RHS and LHS, some RHS dups does not have matches in LHS (merge.data.table+mult fails)
10531053
lhs = data.table(id=c(1:3, 3L), v1=1:4)
10541054
rhs = data.table(id=c(1L, 1L, 3:4, 4L), v2=1:5)
1055-
} else if (case==27L) { ## duplicates in RHS and LHS, some LHS dups does not have matches in RHS
1055+
} else if (case == 27L) { ## duplicates in RHS and LHS, some LHS dups does not have matches in RHS
10561056
lhs = data.table(id=c(1L, 1L, 3:4, 4L), v1=1:5)
10571057
rhs = data.table(id=c(1:3, 3L), v2=1:4)
1058-
} else if (case==28L) { ## duplicates in RHS and LHS
1058+
} else if (case == 28L) { ## duplicates in RHS and LHS
10591059
lhs = data.table(id=c(1:3, 3L), v1=1:4)
10601060
rhs = data.table(id=c(1L, 1L, 3:4), v2=1:4)
1061-
} else if (case==29L) { ## duplicates in RHS
1061+
} else if (case == 29L) { ## duplicates in RHS
10621062
lhs = data.table(id=1:2, v1=1:2)
10631063
rhs = data.table(id=c(2L, 2:3), v2=1:3)
1064-
} else if (case==30L) { ## duplicates in LHS
1064+
} else if (case == 30L) { ## duplicates in LHS
10651065
lhs = data.table(id=c(1:2, 2L), v1=1:3)
10661066
rhs = data.table(id=2:3, v2=1:2)
1067-
} else if (case==31L) {
1067+
} else if (case == 31L) {
10681068
lhs = data.table(id=integer(), v1=integer())
10691069
rhs = data.table(id=integer(), v2=integer())
10701070
} else stop("case not found")

0 commit comments

Comments
 (0)