-
Notifications
You must be signed in to change notification settings - Fork 1k
Completes coverage of all .R files #3761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
45ce60e
c4a2f9f
c27521f
6915452
9c72433
b863930
5d96c71
8c1fe1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -841,8 +841,10 @@ replace_order = function(isub, verbose, env) { | |
| byvars = all.vars(bysubl[[jj+1L]], functions = TRUE) | ||
| if (length(byvars) == 1L) tt = byvars | ||
| else { | ||
| tt = grep("^eval|^[^[:alpha:]. ]",byvars,invert=TRUE,value=TRUE) | ||
| if (length(tt)) tt = tt[1L] else all.vars(bysubl[[jj+1L]])[1L] | ||
| # take the first variable that is (1) not eval (#3758) and (2) starts with a character that can't start a variable name | ||
| tt = grep("^eval$|^[^[:alpha:]. ]", byvars, invert=TRUE, value=TRUE) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. simple fix for #3758 -- add ending anchor |
||
| # byvars but exclude functions or `0`+`1` becomes `+` | ||
| tt = if (length(tt)) tt[1L] else all.vars(bysubl[[jj+1L]])[1L] | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previous code I believe was doing nothing in the |
||
| } | ||
| # fix for #497 | ||
| if (length(byvars) > 1L && tt %chin% all.vars(jsub, FALSE)) { | ||
|
|
@@ -1087,9 +1089,9 @@ replace_order = function(isub, verbose, env) { | |
| if (is.list(k)) { | ||
| origj = j = if (name[[1L]] == "$") as.character(name[[3L]]) else eval(name[[3L]], parent.frame(), parent.frame()) | ||
| if (is.character(j)) { | ||
| if (length(j)!=1L) stop("L[[i]][,:=] syntax only valid when i is length 1, but it's length %d",length(j)) | ||
| if (length(j)!=1L) stop("Cannot assign to an under-allocated recursively indexed list -- L[[i]][,:=] syntax is only valid when i is length 1, but it's length ", length(j)) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quite the obscure error. Especially because the first code works while the second produces this error: |
||
| j = match(j, names(k)) | ||
| if (is.na(j)) stop("Item '",origj,"' not found in names of list") | ||
| if (is.na(j)) stop("Internal error -- item '", origj, "' not found in names of list") # nocov | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't see a way for this to be triggered, so marking it as internal |
||
| } | ||
| .Call(Csetlistelt,k,as.integer(j), x) | ||
| } else if (is.environment(k) && exists(as.character(name[[3L]]), k)) { | ||
|
|
@@ -1118,7 +1120,7 @@ replace_order = function(isub, verbose, env) { | |
| xcolsAns = seq_along(ansvars) | ||
| icols = icolsAns = integer() | ||
| } else { | ||
| if (!length(leftcols)) stop("column(s) not found: ", paste(ansvars[wna],collapse=", ")) | ||
| if (!length(leftcols)) stop("Internal error -- column(s) not found: ", paste(ansvars[wna],collapse=", ")) # nocov | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto above. AFAICT things that might trigger this are caught much earlier than here. |
||
| xcols = w[!wna] | ||
| xcolsAns = which(!wna) | ||
| map = c(seq_along(i), leftcols) # this map is to handle dups in leftcols, #3635 | ||
|
|
@@ -1131,7 +1133,7 @@ replace_order = function(isub, verbose, env) { | |
| if (any(w2na <- is.na(w2))) { | ||
| ivars[leftcols] = paste0("i.",ivars[leftcols]) | ||
| w2[w2na] = chmatch(ansvars[wna][w2na], ivars) | ||
| if (any(w2na <- is.na(w2))) stop("column(s) not found: ", paste(ansvars[wna][w2na],sep=", ")) | ||
| if (any(w2na <- is.na(w2))) stop("Internal error -- column(s) not found: ", paste(ansvars[wna][w2na],sep=", ")) # nocov | ||
| } | ||
| } | ||
| icols = w2 | ||
|
|
@@ -1294,7 +1296,7 @@ replace_order = function(isub, verbose, env) { | |
| identical(irows, integer(0L)) && !bynull, | ||
| length(irows) && !anyNA(irows) && all(irows==0L) ## anyNA() because all() returns NA (not FALSE) when irows is all-NA. TODO: any way to not check all 'irows' values? | ||
| )) | ||
| if (is.atomic(jval)) jval = jval[0L] else jval = lapply(jval, `[`, 0L) | ||
| jval = lapply(jval, `[`, 0L) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't believe Just above you can see this branch enters with either Obviously So we've either got |
||
| if (is.atomic(jval)) { | ||
| setattr(jval,"names",NULL) | ||
| jval = data.table(jval) # TO DO: should this be setDT(list(jval)) instead? | ||
|
|
@@ -1884,7 +1886,7 @@ as.matrix.data.table = function(x, rownames=NULL, rownames.value=NULL, ...) { | |
| non.numeric = non.atomic = FALSE | ||
| all.logical = TRUE | ||
| for (j in seq_len(p)) { | ||
| if (is.ff(X[[j]])) X[[j]] = X[[j]][] # to bring the ff into memory, since we need to create a matrix in memory | ||
| if (is.ff(X[[j]])) X[[j]] = X[[j]][] # nocov to bring the ff into memory, since we need to create a matrix in memory | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't have |
||
| xj = X[[j]] | ||
| if (length(dj <- dim(xj)) == 2L && dj[2L] > 1L) { | ||
| if (inherits(xj, "data.table")) | ||
|
|
@@ -1930,13 +1932,13 @@ as.matrix.data.table = function(x, rownames=NULL, rownames.value=NULL, ...) { | |
|
|
||
| # bug #2375. fixed. same as head.data.frame and tail.data.frame to deal with negative indices | ||
| head.data.table = function(x, n=6L, ...) { | ||
| if (!cedta()) return(NextMethod()) | ||
| if (!cedta()) return(NextMethod()) # nocov | ||
| stopifnot(length(n) == 1L) | ||
| i = seq_len(if (n<0L) max(nrow(x)+n, 0L) else min(n,nrow(x))) | ||
| x[i, , ] | ||
| } | ||
| tail.data.table = function(x, n=6L, ...) { | ||
| if (!cedta()) return(NextMethod()) | ||
| if (!cedta()) return(NextMethod()) # nocov | ||
| stopifnot(length(n) == 1L) | ||
| n = if (n<0L) max(nrow(x) + n, 0L) else min(n, nrow(x)) | ||
| i = seq.int(to=nrow(x), length.out=n) | ||
|
|
@@ -2077,7 +2079,7 @@ within.data.table = function (data, expr, ...) | |
| # basically within.list but retains key (if any) | ||
| # will be slower than using := or a regular query (see ?within for further info). | ||
| { | ||
| if (!cedta()) return(NextMethod()) | ||
| if (!cedta()) return(NextMethod()) # nocov | ||
| parent = parent.frame() | ||
| e = evalq(environment(), data, parent) | ||
| eval(substitute(expr), e) # might (and it's known that some user code does) contain rm() | ||
|
|
@@ -2101,7 +2103,7 @@ within.data.table = function (data, expr, ...) | |
| transform.data.table = function (`_data`, ...) | ||
| # basically transform.data.frame with data.table instead of data.frame, and retains key | ||
| { | ||
| if (!cedta()) return(NextMethod()) | ||
| if (!cedta()) return(NextMethod()) # nocov | ||
| e = eval(substitute(list(...)), `_data`, parent.frame()) | ||
| tags = names(e) | ||
| inx = chmatch(tags, names(`_data`)) | ||
|
|
@@ -2176,7 +2178,7 @@ any_na = function(x, by=seq_along(x)) .Call(CanyNA, x, by) | |
|
|
||
| na.omit.data.table = function (object, cols = seq_along(object), invert = FALSE, ...) { | ||
| # compare to stats:::na.omit.data.frame | ||
| if (!cedta()) return(NextMethod()) | ||
| if (!cedta()) return(NextMethod()) # nocov | ||
| if ( !missing(invert) && is.na(as.logical(invert)) ) | ||
| stop("Argument 'invert' must be logical TRUE/FALSE") | ||
| if (is.character(cols)) { | ||
|
|
@@ -2761,15 +2763,15 @@ rowid = function(..., prefix=NULL) { | |
|
|
||
| rowidv = function(x, cols=seq_along(x), prefix=NULL) { | ||
| if (!is.null(prefix) && (!is.character(prefix) || length(prefix) != 1L)) | ||
| stop("prefix must be NULL or a character vector of length=1.") | ||
| stop("'prefix' must be NULL or a character vector of length 1.") | ||
| if (is.atomic(x)) { | ||
| if (!missing(cols) && !is.null(cols)) | ||
| stop("x is a single vector, non-NULL 'cols' doesn't make sense.") | ||
| cols = 1L | ||
| x = as_list(x) | ||
| } else { | ||
| if (!length(cols)) | ||
| stop("x is a list, 'cols' can not be on 0-length.") | ||
| stop("x is a list, 'cols' cannot be 0-length.") | ||
| if (is.character(cols)) | ||
| cols = chmatch(cols, names(x)) | ||
| cols = as.integer(cols) | ||
|
|
@@ -2790,15 +2792,15 @@ rleid = function(..., prefix=NULL) { | |
|
|
||
| rleidv = function(x, cols=seq_along(x), prefix=NULL) { | ||
| if (!is.null(prefix) && (!is.character(prefix) || length(prefix) != 1L)) | ||
| stop("prefix must be NULL or a character vector of length=1.") | ||
| stop("'prefix' must be NULL or a character vector of length 1.") | ||
| if (is.atomic(x)) { | ||
| if (!missing(cols) && !is.null(cols)) | ||
| stop("x is a single vector, non-NULL 'cols' doesn't make sense.") | ||
| cols = 1L | ||
| x = as_list(x) | ||
| } else { | ||
| if (!length(cols)) | ||
| stop("x is a list, 'cols' can not be 0-length.") | ||
| stop("x is a list, 'cols' cannot be 0-length.") | ||
| if (is.character(cols)) | ||
| cols = chmatch(cols, names(x)) | ||
| cols = as.integer(cols) | ||
|
|
@@ -2880,7 +2882,7 @@ isReallyReal = function(x) { | |
| ## redirect to normal DT[x == TRUE] | ||
| stub = call("==", as.symbol(col), TRUE) | ||
| } | ||
| if (length(stub[[1L]]) != 1) return(NULL) ## Whatever it is, definitely not one of the valid operators | ||
| if (length(stub[[1L]]) != 1) return(NULL) # nocov Whatever it is, definitely not one of the valid operators | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't see a way to reach this branch and the comment suggests it's there as an internal default, could you confirm @MarkusBonsch?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are completely right. |
||
| operator = as.character(stub[[1L]]) | ||
| if (!operator %chin% validOps$op) return(NULL) ## operator not supported | ||
| if (!is.name(stub[[2L]])) return(NULL) | ||
|
|
@@ -2902,7 +2904,6 @@ isReallyReal = function(x) { | |
| # the mode() checks also deals with NULL since mode(NULL)=="NULL" and causes this return, as one CRAN package (eplusr 0.9.1) relies on | ||
| return(NULL) | ||
| } | ||
| if(is.character(x[[col]]) && !operator %chin% c("==", "%in%", "%chin%")) return(NULL) ## base R allows for non-equi operators on character columns, but these can't be optimized. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant to here in current logic: |
||
| if (!operator %chin% c("%in%", "%chin%")) { | ||
| # additional requirements for notjoin and NA values. Behaviour is different for %in%, %chin% compared to other operators | ||
| # RHS is of length=1 or n | ||
|
|
@@ -2998,7 +2999,6 @@ isReallyReal = function(x) { | |
| pat = paste0("(", ops, ")", collapse="|") | ||
| if (is.call(onsub) && onsub[[1L]] == "eval") { | ||
| onsub = eval(onsub[[2L]], parent.frame(2L), parent.frame(2L)) | ||
| if (is.call(onsub) && onsub[[1L]] == "eval") { onsub = onsub[[2L]] } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The After |
||
| } | ||
| if (is.call(onsub) && as.character(onsub[[1L]]) %chin% c("list", ".")) { | ||
| spat = paste0("[ ]+(", pat, ")[ ]+") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted in
?OpsHence we can't really reach this branch since the
incompatible methodsbarrier is hit first.