Skip to content
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

moved key= into ... of as.data.table generic #3852

Merged
merged 1 commit into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion R/as.data.table.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
as.data.table = function(x, keep.rownames=FALSE, key=NULL, ...)
as.data.table = function(x, keep.rownames=FALSE, ...)
# cannot add new args before dots otherwise revdeps which implement their methods will start to warn; e.g. riskRegression in #3581
Copy link
Member

@jangorecki jangorecki Sep 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but why not adding key after dots then? or asking revdep to update. Such a warning is not a problem for production systems

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding arguments after ... has some wrinkles in the past. I can't quite remember what the problem is, but isn't ... supposed to be last?
It works, so why add key=NULL after dots?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lots of base examples with dots in the middle (e.g. sapply)... just means you always have to name that argument.

idea of including is to signal its importance in general for this method. how many as.data.table methods don't accept key?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arguments that are after ... has to be always match by name, I can't recall anything other.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's something about S3 generics as well, can't recall off the top of my head

Copy link
Member

@MichaelChirico MichaelChirico Sep 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For edification: 106 base functions with arguments after ... (including as.data.frame, the closest cousin):

names(Filter(function(x) is.function(x) && '...' %chin% (nm <- names(formals(x))) && tail(nm, 1L) != '...',
+              mget(ls(base <- asNamespace('base')), envir = base)))
  [1] "[.Date"                        "[.difftime"                    "[.factor"                     
  [4] "[.POSIXct"                     "[.table"                       "[[.data.frame"                
  [7] "[[.Date"                       "[[.numeric_version"            "[[.POSIXct"                   
 [10] "[[<-.factor"                   "[[<-.numeric_version"          "[<-.Date"                     
 [13] "[<-.factor"                    "[<-.POSIXct"                   "all.equal.character"          
 [16] "all.equal.factor"              "all.equal.list"                "all.equal.numeric"            
 [19] "all.equal.POSIXt"              "all.equal.raw"                 "as.data.frame.character"      
 [22] "as.data.frame.complex"         "as.data.frame.Date"            "as.data.frame.difftime"       
 [25] "as.data.frame.factor"          "as.data.frame.integer"         "as.data.frame.list"           
 [28] "as.data.frame.logical"         "as.data.frame.matrix"          "as.data.frame.noquote"        
 [31] "as.data.frame.numeric"         "as.data.frame.numeric_version" "as.data.frame.ordered"        
 [34] "as.data.frame.POSIXct"         "as.data.frame.raw"             "as.data.frame.table"          
 [37] "as.data.frame.vector"          "attr.all.equal"                "by"                           
 [40] "by.data.frame"                 "by.default"                    "c.Date"                       
 [43] "c.difftime"                    "c.noquote"                     "c.numeric_version"            
 [46] "c.POSIXct"                     "c.POSIXlt"                     "c.warnings"                   
 [49] "cat"                           "cbind"                         "cbind.data.frame"             
 [52] "chkDots"                       "data.frame"                    "eapply"                       
 [55] "errorCondition"                "expand.grid"                   "file.create"                  
 [58] "file.info"                     "file.path"                     "file.show"                    
 [61] "format.data.frame"             "gettext"                       "gettextf"                     
 [64] "interaction"                   "mapply"                        "message"                      
 [67] "namespaceImport"               "order"                         "packageStartupMessage"        
 [70] "paste"                         "paste0"                        "pmax"                         
 [73] "pmax.int"                      "pmin"                          "pmin.int"                     
 [76] "print.by"                      "print.data.frame"              "range.default"                
 [79] "rbind"                         "rbind.data.frame"              "remove"                       
 [82] "requireNamespace"              "rm"                            "sapply"                       
 [85] "save"                          "split<-"                       "split<-.data.frame"           
 [88] "split<-.default"               "stop"                          "stopifnot"                    
 [91] "Summary.data.frame"            "Summary.Date"                  "summary.default"              
 [94] "Summary.difftime"              "Summary.factor"                "Summary.numeric_version"      
 [97] "Summary.ordered"               "Summary.POSIXct"               "Summary.POSIXlt"              
[100] "system.file"                   "table"                         "tapply"                       
[103] "tryCatch"                      "vapply"                        "warning"                      
[106] "warningCondition" 

Another 100 or so among the other default loads

{
if (is.null(x))
return(null.data.table())
Expand Down
2 changes: 1 addition & 1 deletion man/as.data.table.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Functions to check if an object is \code{data.table}, or coerce it if possible.

}
\usage{
as.data.table(x, keep.rownames=FALSE, key=NULL, \dots)
as.data.table(x, keep.rownames=FALSE, \dots)

\method{as.data.table}{data.table}(x, \dots)

Expand Down