Skip to content

Instantly share code, notes, and snippets.

@hadley
Last active June 27, 2016 00:07
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadley/e4cfe72fc85f7a7cbac0 to your computer and use it in GitHub Desktop.
Save hadley/e4cfe72fc85f7a7cbac0 to your computer and use it in GitHub Desktop.
diamonds <- ggplot2::diamonds
pryr::object_size(diamonds)
#> 3.46 MB

diamonds2 <- transform(diamonds, price_per_carat = price / carat)
pryr::object_size(diamonds2)
#> 3.89 MB

# Size of both data frames combined
pryr::object_size(diamonds, diamonds2)
#> 3.89 MB
@decisionstats
Copy link

why does a data.table have a bigger objectsize than same data.frame

@mattdowle
Copy link

@decisionstats how much bigger do you see? I see 0.0006 MB bigger for one extra internal attribute of fixed size. Unless perhaps your data.table has had an automatic index added. DT[ someCol == someVal, ] does that by default for convenience and instant lookup if someCol is queried again. In which case both base::object.size() and pryr::object_size() will include the size of the data.table index which is added as an attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment