Skip to content

Commit c4fcff4

Browse files
set key
1 parent bc00de6 commit c4fcff4

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

R/as.data.table.R

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ as.data.table.list = function(x,
214214
}
215215

216216
as.data.table.data.frame = function(x, keep.rownames=FALSE, key=NULL, ...) {
217-
if (is.data.table(x)) return(as.data.table.data.table(x, ...)) # S3 is weird, #6739. Also # nocov; this is tested in 2302.{2,3}, not sure why it doesn't show up in coverage.
217+
if (is.data.table(x)) return(as.data.table.data.table(x)) # S3 is weird, #6739. Also # nocov; this is tested in 2302.{2,3}, not sure why it doesn't show up in coverage.
218218
if (!identical(class(x), "data.frame")) return(as.data.table(as.data.frame(x), keep.rownames=keep.rownames, key=key, ...))
219219
if (!isFALSE(keep.rownames)) {
220220
# can specify col name to keep.rownames, #575; if it's the same as key,
@@ -245,24 +245,14 @@ as.data.table.data.frame = function(x, keep.rownames=FALSE, key=NULL, ...) {
245245
ans
246246
}
247247

248-
as.data.table.data.table = function(x, ...) {
249-
# Extract keep.rownames and key from ... if provided
250-
dots = list(...)
251-
keep.rownames = if("keep.rownames" %in% names(dots)) dots$keep.rownames else FALSE
252-
key_provided = "key" %in% names(dots)
253-
key = if(key_provided) dots$key else NULL
254-
248+
as.data.table.data.table = function(x, keep.rownames = FALSE, key, ...) {
255249
# as.data.table always returns a copy, automatically takes care of #473
256250
if (any(cols_with_dims(x))) { # for test 2089.2
257-
return(as.data.table.list(x, keep.rownames = if(missing(keep.rownames)) FALSE else keep.rownames, key = if(missing(key)) NULL else key, ...))
251+
return(as.data.table.list(x,keep.rownames = keep.rownames, key = key, ...))
258252
}
259253
x = copy(x) # #1681
260254
# fix for #1078 and #1128, see .resetclass() for explanation.
261255
setattr(x, 'class', .resetclass(x, "data.table"))
262-
if (key_provided){
263-
setkeyv(x, key)
264-
} else {
265-
setattr(x, "sorted", NULL)
266-
}
256+
if (!missing(key)) setkeyv(x, key)
267257
x
268258
}

0 commit comments

Comments
 (0)