Skip to content

Commit 242847a

Browse files
committed
restructure
1 parent 7b84533 commit 242847a

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

R/data.table.R

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -735,17 +735,22 @@ replace_dot_alias = function(e) {
735735
names(..syms) = ..syms
736736
j = eval(jsub, lapply(substr(..syms, 3L, nchar(..syms)), get, pos=parent.frame()), parent.frame())
737737
}
738-
if (is.logical(j)) j = which(j)
739738
if (!length(j) && !notj) return( null.data.table() )
740739
if (is.factor(j)) j = as.character(j) # fix for FR: #358
740+
if (is.character(j) || (is.numeric(j) && !is.logical(j))) {
741+
if (!missingby) {
742+
j_type = if (is.character(j)) "a character" else "a numeric"
743+
warning(
744+
"`by` or `keyby` is ignored when `j` is ", j_type, " vector used for column selection. ",
745+
"Perhaps you intended to use `.SD`? For example: DT[, .SD[, ", deparse(jsub), "], by = ...]",
746+
call. = FALSE
747+
)
748+
}
749+
}
750+
751+
if (is.logical(j)) j = which(j)
752+
741753
if (is.character(j)) {
742-
if (!missingby) {
743-
warning(
744-
"`by` or `keyby` is ignored when `j` is a character vector used for column selection. ",
745-
"Perhaps you intended to use `.SD`? For example: DT[, .SD[, ", deparse(jsub), "], by = ...]",
746-
call. = FALSE
747-
)
748-
}
749754
if (notj) {
750755
if (anyNA(idx <- chmatch(j, names_x)))
751756
warningf(ngettext(sum(is.na(idx)), "column not removed because not found: %s", "columns not removed because not found: %s"),
@@ -769,12 +774,6 @@ replace_dot_alias = function(e) {
769774
# else the NA in ansvals are for join inherited scope (test 1973), and NA could be in irows from join and data in i should be returned (test 1977)
770775
# in both cases leave to the R-level subsetting of i and x together further below
771776
} else if (is.numeric(j)) {
772-
if (!missingby) {
773-
warning(
774-
"`by` or `keyby` is ignored when `j` is a numeric vector used for column selection. ", "Perhaps you intended to use `.SD`? For example: DT[, .SD[, ", deparse(jsub), "], by = ...]",
775-
call. = FALSE
776-
)
777-
}
778777
j = as.integer(j)
779778
if (any(w <- (j>ncol(x)))) stopf("Item %d of j is %d which is outside the column number range [1,ncol=%d]", idx <- which.first(w), j[idx], ncol(x))
780779
j = j[j!=0L]

0 commit comments

Comments
 (0)