Skip to content
Back to formatted view

Raw Message

Message-ID: <CABdHhvEtG5+NhjorrSDJ4uAhm+483U7k1dN=Z83UwkfAPgFJXQ@mail.gmail.com>
Date: 2013-01-31T13:45:56Z
From: Hadley Wickham
Subject: [Rcpp-devel] Performance question about DataFrame
In-Reply-To: <CAESjWnu70G=uGOTmBa+XRYrwi_wq1Sm5Z6286Xs6G4W5tzgPWg@mail.gmail.com>

On Fri, Jan 18, 2013 at 6:25 PM, John Merrill <john.merrill at gmail.com> wrote:
> Sure.  I'll write something up for the gallery, but here's the crude
> outline.
>
> Here's the C++ code:

Is C++ really necessary here?  I have the following R function in plyr:

quickdf <- function(list) {
  rows <- unique(unlist(lapply(list, NROW)))
  stopifnot(length(rows) == 1)

  names(list) <- make_names(list, "X")
  class(list) <- "data.frame"
  attr(list, "row.names") <- c(NA_integer_, -rows)

  list
}

which is basically equivalent (although I do some tricks with
rownames).  It's even more efficient if you copy and paste the
contents instead of calling the function because then that avoids
duplicating the input list, and instead modifies it in place.

Hadley

-- 
Chief Scientist, RStudio
http://had.co.nz/