Skip to content

Commit cee6cc1

Browse files
committed
fix as.data.table dispatch
1 parent 339761b commit cee6cc1

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

R/as.data.table.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ as.data.table.list = function(x,
130130
# e.g. cbind(foo=DF1, bar=DF2) have .named=c(TRUE,TRUE) due to the foo= and bar= and trigger "prefix." for non-vector items
131131
...)
132132
{
133+
if (is.data.table(x)) {
134+
# operate on plain list to avoid [[<-.data.table dispatch
135+
x = as.list(x)
136+
}
133137
n = length(x)
134138
eachnrow = integer(n) # vector of lengths of each column. may not be equal if silent repetition is required.
135139
eachncol = integer(n)

R/data.table.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,12 +2309,16 @@ tail.data.table = function(x, n=6L, ...) {
23092309
}
23102310

23112311
"[[<-.data.table" = function(x, i, j, value) {
2312+
n = nargs()
23122313
if (!cedta()) {
2313-
ans = `[[<-.data.frame`(x, i, j, value) # nocov
2314-
return(setalloccol(ans)) # nocov. over-allocate (again)
2314+
# nocov start
2315+
ans = if (n<4L) `[<-.data.frame`(x, i, value=value)
2316+
else `[<-.data.frame`(x, i, j, value)
2317+
return(setalloccol(ans)) # over-allocate (again)
2318+
# nocov end
23152319
}
23162320
x = copy(x)
2317-
if (nargs()<4L) {
2321+
if (n<4L) {
23182322
set(x, j=i, value=value)
23192323
} else {
23202324
set(x, i, j, value)

0 commit comments

Comments
 (0)