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

[FR] keep.rownames in as.data.table.xts() supports string #4232

Closed
shrektan opened this issue Feb 5, 2020 · 0 comments · Fixed by #4234
Closed

[FR] keep.rownames in as.data.table.xts() supports string #4232

shrektan opened this issue Feb 5, 2020 · 0 comments · Fixed by #4234
Assignees
Milestone

Comments

@shrektan
Copy link
Member

shrektan commented Feb 5, 2020

I often want to convert an xts object to data.table. I need to keep the index of the xts object. At present, data.table will force to name the column of the index to "index". However, I often need to rename the column to other strings, e.g., "DATE".

So I'm proposing that the keep.rownames argument inas.data.table.xts() should permits a string value as as.data.table.data.frame() does.

If there's no objection, I will file a PR later.

Thanks.

as.data.table.data.frame() permits a string value for keep.rownames

data.table::as.data.table(iris[1:5, ], keep.rownames = "ITEM")
#>      ITEM Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#>    <char>        <num>       <num>        <num>       <num>  <fctr>
#> 1:      1          5.1         3.5          1.4         0.2  setosa
#> 2:      2          4.9         3.0          1.4         0.2  setosa
#> 3:      3          4.7         3.2          1.3         0.2  setosa
#> 4:      4          4.6         3.1          1.5         0.2  setosa
#> 5:      5          5.0         3.6          1.4         0.2  setosa

but as.data.table.xts() doesn't and it should, in my opinion

xts_obj <- xts::xts(1, order.by = Sys.Date())
data.table::as.data.table(xts_obj, "Date")
#> Error in !keep.rownames: invalid argument type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants