You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Slow="73d79edf8ff8c55163e90631072192301056e336", # Parent of the first commit in the PR (https://github.com/Rdatatable/data.table/commit/8397dc3c993b61a07a81c786ca68c22bc589befc)
278
278
Fast="8397dc3c993b61a07a81c786ca68c22bc589befc"), # Commit in the PR (https://github.com/Rdatatable/data.table/pull/7019/commits) that removes inefficiency
279
279
280
+
"isoweek improved in #7144"=atime::atime_test(
281
+
setup= {
282
+
set.seed(349)
283
+
x= sample(Sys.Date() -0:5000, N, replace=TRUE)
284
+
},
285
+
expr=data.table::isoweek(x),
286
+
Slow="548410d23dd74b625e8ea9aeb1a5d2e9dddd2927", # Parent of the first commit in the PR (https://github.com/Rdatatable/data.table/commit/548410d23dd74b625e8ea9aeb1a5d2e9dddd2927)
287
+
Fast="c0b32a60466bed0e63420ec105bc75c34590865e"), # Commit in the PR (https://github.com/Rdatatable/data.table/pull/7144/commits) that uses a much faster implementation
origListNames=if (missing(.named)) names(x) elseNULL# as.data.table called directly, not from inside data.table() which provides .named, #3854
135
138
empty_atomic=FALSE
139
+
140
+
# Handle keep.rownames for vectors (mimicking data.frame behavior)
141
+
rownames_=NULL
142
+
check_rownames=!isFALSE(keep.rownames)
143
+
136
144
for (iin seq_len(n)) {
137
145
xi=x[[i]]
138
146
if (is.null(xi)) next# eachncol already initialized to 0 by integer() above
147
+
if (check_rownames&& is.null(rownames_)) {
148
+
if (is.null(dim(xi))) {
149
+
if (!is.null(nm<- names(xi))) {
150
+
rownames_=nm
151
+
x[[i]] = unname(xi)
152
+
}
153
+
} else {
154
+
if (!is.null(nm<- rownames(xi))) {
155
+
rownames_=nm
156
+
}
157
+
}
158
+
}
139
159
if (!is.null(dim(xi)) &&missing.check.names) check.names=TRUE
140
160
if ("POSIXlt" %chin% class(xi)) {
141
161
warningf("POSIXlt column type detected and converted to POSIXct. We do not recommend use of POSIXlt at all because it uses 40 bytes to store one date.")
Copy file name to clipboardExpand all lines: man/as.data.table.Rd
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ is.data.table(x)
31
31
}
32
32
\arguments{
33
33
\item{x}{AnRobject.}
34
-
\item{keep.rownames}{Defaultis \code{FALSE}.If \code{TRUE}, addstheinputobject's names as a separate column named \code{"rn"}. \code{keep.rownames = "id"} names the column \code{"id"} instead.}
34
+
\item{keep.rownames}{Defaultis \code{FALSE}.If \code{TRUE}, addstheinputobject's names as a separate column named \code{"rn"}. \code{keep.rownames = "id"} names the column \code{"id"} instead. For lists and when calling \code{data.table()}, names from the first named vector are extracted and used as row names, similar to \code{data.frame()} behavior.}
35
35
\item{key}{ Character vector of one or more column names which is passed to \code{\link{setkeyv}}. }
36
36
\item{sorted}{logical used in \emph{array} method, default \code{TRUE} is overridden when \code{key} is provided. }
37
37
\item{value.name}{character scalar used in \emph{array} method, default \code{"value"}.}
\item{keyby}{ Same as \code{by}, but with an additional \code{setkey()} run on the \code{by} columns of the result, for convenience. It is common practice to use \code{keyby=} routinely when you wish the result to be sorted. May also be \code{TRUE} or \code{FALSE} when \code{by} is provided as an alternative way to accomplish the same operation.}
119
119
120
-
\item{with}{ By default \code{with=TRUE} and \code{j} is evaluated within the frame of \code{x}; column names can be used as variables. In case of overlapping variables names inside dataset and in parent scope you can use double dot prefix \code{..cols} to explicitly refer to \code{cols} variable parent scope and not from your dataset.
120
+
\item{with}{ By default \code{with=TRUE} and \code{j} is evaluated within the frame of \code{x}; column names can be used as variables. In the case of overlapping variable names inside \code{x} and in parent scope, you can use the double dot prefix \code{..cols} to explicitly refer to the \code{cols} variable in parent scope and not from \code{x}.
121
121
122
-
When \code{j} is a character vector of column names, a numeric vector of column positions to select or of the form \code{startcol:endcol}, and the value returned is always a \code{data.table}. \code{with=FALSE} is not necessary anymore to select columns dynamically. Note that \code{x[, cols]} is equivalent to \code{x[, ..cols]} and to \code{x[, cols, with=FALSE]} and to \code{x[, .SD, .SDcols=cols]}.}
122
+
When \code{j} is a character vector of column names, a numeric vector of column positions to select, or of the form \code{startcol:endcol}, the value returned is always a \code{data.table}.
123
+
124
+
New code should rarely use this argument, which was originally needed for similarity to data.frame. For example, to select columns from a character vector \code{cols}, in data.frame we do \code{x[, cols]}, which has several equivalents in data.table: \code{x[, .SD, .SDcols=cols]}, \code{x[, ..cols]}, \code{x[, cols, env = list(cols = I(cols))]}, or \code{x[, cols, with=FALSE]}.}
123
125
124
126
\item{nomatch}{ When a row in \code{i} has no match to \code{x}, \code{nomatch=NA} (default) means \code{NA} is returned. \code{NULL} (or \code{0} for backward compatibility) means no rows will be returned for that row of \code{i}. }
Copy file name to clipboardExpand all lines: vignettes/datatable-reshape.Rmd
+13-13Lines changed: 13 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -142,31 +142,31 @@ So far we've seen features of `melt` and `dcast` that are implemented efficientl
142
142
However, there are situations we might run into where the desired operation is not expressed in a straightforward manner. For example, consider the `data.table` shown below:
And you'd like to combine (`melt`) all the `dob` columns together, and `gender` columns together. Using the old functionality, we could do something like this:
156
+
And you'd like to combine (`melt`) all the `name` columns together, and `gender` columns together. Using the old functionality, we could do something like this:
str(DT.c1) ## gender column is character type now!
165
165
```
166
166
167
167
#### Issues
168
168
169
-
1. What we wanted to do was to combine all the `dob` and `gender` type columns together respectively. Instead, we are combining *everything* together, and then splitting them again. I think it's easy to see that it's quite roundabout (and inefficient).
169
+
1. What we wanted to do was to combine all the `name` and `gender` type columns together respectively. Instead, we are combining *everything* together, and then splitting them again. I think it's easy to see that it's quite roundabout (and inefficient).
170
170
171
171
As an analogy, imagine you've a closet with four shelves of clothes and you'd like to put together the clothes from shelves 1 and 2 together (in 1), and 3 and 4 together (in 3). What we are doing is more or less to combine all the clothes together, and then split them back on to shelves 1 and 3!
172
172
@@ -189,9 +189,9 @@ Since we'd like for `data.table`s to perform this operation straightforward and
189
189
The idea is quite simple. We pass a list of columns to `measure.vars`, where each element of the list contains the columns that should be combined together.
@@ -206,7 +206,7 @@ str(DT.m2) ## col type is preserved
206
206
Usually in these problems, the columns we'd like to melt can be distinguished by a common pattern. We can use the function `patterns()`, implemented for convenience, to provide regular expressions for the columns to be combined together. The above operation can be rewritten as:
0 commit comments