Skip to content

Commit 20b7f6a

Browse files
Gforce eval vars (#5887)
* make turn GForce turnon more strict * finish fix * safer to check for numeric than not logical * update tests * fix typo * update tests --------- Co-authored-by: Michael Chirico <[email protected]>
1 parent 685d51d commit 20b7f6a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

R/data.table.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ replace_dot_alias = function(e) {
17671767
length(q) == 3L &&
17681768
is_constantish(q[[3L]], check_singleton = TRUE) &&
17691769
(q[[1L]] != "[[" || eval(call('is.atomic', q[[2L]]), envir=x)) &&
1770-
eval(q[[3L]], parent.frame(3L)) > 0L
1770+
!(as.character(q[[3L]]) %chin% names_x) && is.numeric(q3<-eval(q[[3L]], parent.frame(3L))) && length(q3)==1L && q3>0L
17711771
}
17721772
.gweighted.mean_ok = function(q, x) { #3977
17731773
q = match.call(gweighted.mean, q)

inst/tests/tests.Rraw

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18245,3 +18245,18 @@ test(2243.35, dt[, min(y, na.rm=as.logical(j)), g, verbose=TRUE], data.table(
1824518245
test(2243.36, dt[, max(y, na.rm=as.logical(j)), g, verbose=TRUE], data.table(g=c(1L,2L), V1=c(3L,4L)), output="GForce FALSE")
1824618246
test(2243.37, dt[, var(y, na.rm=as.logical(j)), g, verbose=TRUE], data.table(g=c(1L,2L), V1=c(2,2)), output="GForce FALSE")
1824718247
test(2243.38, dt[, sd(y, na.rm=as.logical(j)), g, verbose=TRUE], data.table(g=c(1L,2L), V1=c(sqrt(c(2,2)))), output="GForce FALSE")
18248+
# revdeps
18249+
dt = data.table(x = c(2,2,1,1), y = 1:4, z=letters[1:4])
18250+
i=c(1,2)
18251+
j=1L
18252+
old = options(datatable.optimize=1L)
18253+
test(2243.41, dt[, .I[TRUE], x]$V1, 1:4)
18254+
test(2243.42, dt[, z[y], x], data.table(x=c(2,2,1,1), V1=c("a","b",NA,NA)))
18255+
options(datatable.optimize=2L, datatable.verbose=TRUE)
18256+
test(2243.51, dt[, .I[TRUE], x]$V1, 1:4, output="GForce FALSE")
18257+
test(2243.52, dt[, z[y], x], data.table(x=c(2,2,1,1), V1=c("a","b",NA,NA)), output="GForce FALSE")
18258+
test(2243.53, dt[, .I[1], x]$V1, c(1L, 3L), output="GForce TRUE")
18259+
test(2243.54, dt[, .I[j], x]$V1, c(1L, 3L), output="GForce TRUE")
18260+
test(2243.55, dt[, .I[i], x]$V1, 1:4, output="GForce FALSE")
18261+
test(2243.56, dt[, .I[1:2], x]$V1, 1:4, output="GForce FALSE")
18262+
options(old)

0 commit comments

Comments
 (0)