A wrapper for R’s data() function

[This article was first published on factbased, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The workflow for statistical analyses is discussed at several places. Often, it is recommended:

  • never change the raw data, but transform it,
  • keep your analysis reproducible,
  • separate functions and data,
  • use R package system as organizing structure.

In some recent projects I tried an S4 class approach for this workflow, which I want to present and discuss. It makes use of the package datamart, which I recently submitted to CRAN. Here is a sample session:

> library(datamart)
> library(beeswarm)
> # load one of my datasets
> xp <- expenditures()
> # introspection: what
> # "resources" for this
> # dataset did I once define?
> queries(xp)
Evs#Categories Evs#Elasticities   Evs#Elasticity 
"Categories"   "Elasticities"     "Elasticity" 
> # get me a resource
> head(query(xp, "Raw"))
coicop2                                    coicop2de
1      15 Expenditures (exclusive private consumption)
2      15 Expenditures (exclusive private consumption)
3      15 Expenditures (exclusive private consumption)
4      15 Expenditures (exclusive private consumption)
5      15 Expenditures (exclusive private consumption)
6      15 Expenditures (exclusive private consumption)
income               hhtype value
1  (all)                (all)  2539
2  (all)               Single  1462
3  (all)         Single woman  1232
4  (all)           Single man  1866
5  (all)        Single parent  1004
6  (all) Single parent, 1 kid   991

Read on to see how a S4 dataset object is defined and accessed, and what I see in favour and against this approach.

Read more »

To leave a comment for the author, please follow the link and comment on their blog: factbased.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)