[Rcpp-devel] Construct data.table object at the C++ level ?

Dirk Eddelbuettel edd at debian.org
Sat Nov 4 21:30:26 CET 2017


On 4 November 2017 at 15:22, Dirk Eddelbuettel wrote:
| 
| On 2 November 2017 at 23:24, Dirk Eddelbuettel wrote:
| | 
| | On 2 November 2017 at 15:36, Matt Dowle wrote:
| | | I replied in the issue.
| | 
| | So did I, now that I am back online after a company event.
| | 
| | I'll fill a simple concrete event: constructing a DT from a DF and then using
| | nanotime to construct sane nanotime/bit64 objects.   All fine and trivial,
| | but would be nicer to do this -- and more -- and the C++ level.
| 
| Ok, the 'create a nanotime vector from int64_t' part is now sorted out [1],
| and it trivially becomes a column in a data.frame and hence ...
| | 
| | | I don't know what you're asking for here.  A data.table is a list of
| | | same-length vectors, so it's almost trivial to create.  Then just add the
| | 
| | We understand that part.
| | 
| | We are less sure about to get to the bits that are not data.frame, and how to
| | do so at the C level.
| 
| ... in a data.table.  But I still call setDT() via Rcpp::Function.  I'll see
| if I can play fast and loose and just set that S3 attribute directly.

Yes, seems to work (at least for a fresh and reasonable data.frame object):

    //Rcpp::Function dt("setDT");
    //return dt(df);
    df.attr("class") = Rcpp::CharacterVector::create("data.table", "data.frame");
    return(df);  

Dirk
| 
| I'll try to remind myself to write a Rcpp Gallery piece once I have all the
| pieces.  Having data.table objects with nanosecond-resolution time is pretty
| slick. 
| 
| Dirk
| 
| [1] Mostly, still uses one call via Rcpp::Function() to create the S4 object
| which we may be able to amortise, but that may not really matter.
| 
| 
| | Dirk
| | 
| | | attributes which setDT() does from R level, and trace that through to see
| | | what it does.  I don't really get what you're asking for as on the face of
| | | it it's simple.  I had asked in the issue about whether it's the recycling
| | | you need but I'm not clear.
| | | 
| | | On Thu, Nov 2, 2017 at 2:35 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
| | | 
| | | >
| | | > Does anybody have any (public) code constructing data.table objects?
| | | >
| | | > I can of course do as we do for data.frame, which is (essentially)
| | | > constructing a List and setting a class attribute at end.  But I gather
| | | > someone may have done something somewhere already?  C code works too,
| | | > making
| | | > it shorter always works...
| | | >
| | | > Dirk
| | | >
| | | > PS Long-parked related  wishlist ticket is at
| | | > https://github.com/Rdatatable/data.table/issues/1694
| | | >
| | | > --
| | | > http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
| | | >
| | 
| | -- 
| | http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
| 
| -- 
| http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list