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
xts object is a matrix, isn't it? If so, can't convert a matrix to data.table by reference IIUC. The underlying data structure isn't the same. A data.frame is a vector of column pointers - rows of each column is contiguous in memory, but not the columns themselves. But a matrix is just a vector with attributes - entire vector is contiguous in memory.
I'm not sure but this might be related to lack of as.data.table.default method in data.table (related #969).
2. changing arg name from keep.rownames to keep.index?
3. handling case when the xts object already contain column named index, maybe the simple warning about duplicate colnames in resulting dt?
4. GSee comment from SO:
The as.data.table.xts function converts the index to character and the as.xts.data.table function does not allow for xts objects that are not numeric (e.g. an all character xts)
Didn't check this one yet.
5. prepare xts index by reference. I believe I could use setattr instead rownames on the DF right before as.xts, here.
I suppose, it's really as.data.frame.xts that loses the class of the index when it converts it to rownames. Since there are some choices to be made, simple is probably better -- i.e. leave it up to the user to convert back to a timeBased class.
It has now the advantage over data.frame because it retains the class of index after conversion.
When completed I will submit PR, to 1.9.7 hopefully :)
I still have problem with point 1, tried few combinations to keep xts in suggests and do not attach it on search path. After compiling in package it needs to by used as:
I've pushed it as a new DT branch: https://github.com/jangorecki/data.table/tree/as.xts
Tests are ready (as testthat at the moment) but not yet merged into tests.Rraw.
Am I correct they should be transformed into test(num,x,y) tests?
I will PR it to 1.9.7.
Yes, can help w/ tests if you want to keep w/ testthat -- I'm not actually sure if these are being run anymore? We can migrate this to the new suggested layout for testthat tests if so ...
There is not need to use testthat if current test process is working fine. It should be straight to transfer expect_equal calls.
I will do the edits and merge into one commit before PR. Unfortunately I can't make cran check to work (dependency not available on 3.1.2).
I've pushed PR, dontrun and tests.Rraw. Let me know if everything ok so I can merge them as single commit (there are two commits at the moment).
It failed on test numbering, will try to fix it soon.
Activity
[-]convert to xts by reference: setXTS(dt)[/-][+][Request] convert to xts by reference: setXTS(dt)[/+]arunsrinivasan commentedon Dec 4, 2014
xtsobject is a matrix, isn't it? If so, can't convert a matrix to data.table by reference IIUC. The underlying data structure isn't the same. A data.frame is a vector of column pointers - rows of each column is contiguous in memory, but not the columns themselves. But a matrix is just a vector with attributes - entire vector is contiguous in memory.jangorecki commentedon Dec 4, 2014
Thanks. You are right. The matrix is just a dimensioned vector. So by reference cannot be done. Closing as I don't see any alternative for this.
non by-reference wrappers for xts-data.table conversion available here: https://github.com/jangorecki/dwtools/blob/b8981b5658509333378f6325d5b1a0c71bf9da9a/R/xts.R
mattdowle commentedon Dec 8, 2014
Jan - very nice answer : http://stackoverflow.com/a/27356884/403310
Reopening and changed title to consider including this in data.table as per Dirk's comment?
[-][Request] convert to xts by reference: setXTS(dt)[/-][+][Request] convert DT to xts efficiently[/+]jangorecki commentedon Dec 8, 2014
I can prepare PR to data.table.
Just some things to consider:
I'm not sure but this might be related to lack of
as.data.table.defaultmethod in data.table (related #969).2. changing arg name from
keep.rownamestokeep.index?3. handling case when the xts object already contain column named index, maybe the simple warning about duplicate colnames in resulting dt?
4. GSee comment from SO:
Didn't check this one yet.
5. prepare xts index by reference. I believe I could use
setattrinsteadrownameson the DF right before as.xts, here.gsee commentedon Dec 8, 2014
I suppose, it's really
as.data.frame.xtsthat loses the class of the index when it converts it to rownames. Since there are some choices to be made, simple is probably better -- i.e. leave it up to the user to convert back to a timeBased class.jangorecki commentedon Dec 13, 2014
I've address 2-5.
Find recent dev version of code in:
It has now the advantage over data.frame because it retains the class of index after conversion.
When completed I will submit PR, to 1.9.7 hopefully :)
I still have problem with point 1, tried few combinations to keep xts in suggests and do not attach it on search path. After compiling in package it needs to by used as:
Seems to not be related to lack of
as.data.table.defaultbut suggested package xts.Info from: http://r-pkgs.had.co.nz/namespace.html
looks like ti will not be handled nice using
xtsin suggests.jangorecki commentedon Jan 8, 2015
I've pushed it as a new DT branch: https://github.com/jangorecki/data.table/tree/as.xts
Tests are ready (as
testthatat the moment) but not yet merged intotests.Rraw.Am I correct they should be transformed into
test(num,x,y)tests?I will PR it to
1.9.7.arunsrinivasan commentedon Jan 8, 2015
@jangorecki looks great! Looks like you've .Rd files now. If they've to be merged to .Rraw, then yes, they have to be converted. I can help with that.
But if you'd like to keep the file as-is, then maybe @lianos can help? He has setup tests for S4-classes using
testthatframework.I'll push a
as.data.table.defaultmethod.xtsshould be insuggestsand should the examples be wrapped with\dontrun{}?lianos commentedon Jan 8, 2015
Yes, can help w/ tests if you want to keep w/
testthat-- I'm not actually sure if these are being run anymore? We can migrate this to the new suggested layout for testthat tests if so ...jangorecki commentedon Jan 8, 2015
There is not need to use
testthatif currenttestprocess is working fine. It should be straight to transferexpect_equalcalls.I will do the edits and merge into one commit before PR. Unfortunately I can't make cran check to work (dependency not available on 3.1.2).
arunsrinivasan commentedon Jan 8, 2015
Great. I can help you with that.. You can go ahead and make the PR...
arunsrinivasan commentedon Jan 9, 2015
@lianos missed your reply before, sorry. I'm not sure if they're being run. I assumed so. What's the new suggested layout you refer to?
jangorecki commentedon Jan 9, 2015
I've pushed PR,
dontrunandtests.Rraw. Let me know if everything ok so I can merge them as single commit (there are two commits at the moment).It failed on test numbering, will try to fix it soon.
xts-data.table conversion, closes Rdatatable#882
Merge pull request #998 from jangorecki/as.xts