One big advantage of SAS over R is arguably its ability to produce quite complex reports with few statements; think of PROC SUMMARY or PROC TABULATE for instance.

My heart goes to R because of its openness and vibrant community. But I must admit that SAS's PROCS are quite powerful out-of-the-box. To partially address those issues I wrote an R package titled summarytools which provides ways to generate decent looking and translatable (thanks to pander, Pandoc implemented in R) simple reports (frequencies, univariate stats, codebook, for the essential part) to various formats like RTF, pdf, and markdown.

However, even with the use of by() to stratify the stats (be it frequencies or univariate numerical stats), I feel I'm still miles away from generating as flexible and complete tables such as with PROC TABULATE or PROC MEANS. So my question is: what R packages do you find are "musts" for needs of extracting essential stats from dataframes, splitting on this variable and filtering on that other one. I hope this is not judged as too broad a question; I have made my homework and tried finding the answer to this question before posting here. I'm sure there are some really really well-made packages that address those issues, and I simply haven't seen them around ... yet.

  • 5
    $\begingroup$ I believe SAS reports are inferior to Rs, you just need to find the correct packages and functions to use. I use packages tableone, Hmisc, sjPlot for these tasks. $\endgroup$ Nov 9, 2014 at 13:56
  • 1
    $\begingroup$ I like the sjPlot approach a lot since it gives absolutely beautiful results without having to go through additional steps. $\endgroup$ Nov 9, 2014 at 23:09

3 Answers 3


The problem with R is that there are so many ways to construct great reports, and so many R packages that are helpful for this task. One approach, though getting out of date, is shown in http://biostat.app.vumc.org/wiki/pub/Main/StatReport/summary.pdf . Note that some of the functions there have been updated as shown in http://hbiostat.org/R/Hmisc [and really take note of the tabulr function]. That approach revolves around $\LaTeX$, and I believe you'll find that for producing advanced tables (includes ones containing micrographics and footnotes), $\LaTeX$ has many advantages over the markdown-pandoc approach.

But I believe that we should replace almost all tables with graphics. The new R greport ("graphical report") and hreport ("html report") packages takes the philosophy that graphics should be used for the main presentation, and graphs should be hyperlinked to supporting tables that appear in an appendix to the pdf report. See http://hbiostat.org/r. These packages use new functions in the Hmisc package for graphing categorical data (i.e., translating tables to plots) and for showing whole distributions of continuous variables.

  • 1
    $\begingroup$ I'll look into greport, thanks. The all-graphics avenue seems like a promising one indeed. I also found that gplots, sjPlot (as mentionned by @Adam Robinson) and gridExtra all provide functions that generate graphic tables. $\endgroup$ Nov 10, 2014 at 4:44

It seems like reporting and filtering/splitting data by variables are two orthogonal tasks. And people usually use different packages for those.

For managing the data there are few really popular packages: dplyr and data.table.

For reporting tables one package that stands out for me is stargazer

Here are some demonstrations: http://cran.r-project.org/web/packages/stargazer/vignettes/stargazer.pdf

It covers both latex and html (and ASCII, but haven't used that).

I have never used SAS so I don't know if this will cover all the functionality you wanted.

  • 1
    $\begingroup$ I am quite aware of the existing tools to manipulate data. I'll look into stargazer, thanks for the suggestion. $\endgroup$ Nov 10, 2014 at 11:37
  • 1
    $\begingroup$ Stargazer is nice, but i prefer Tableone because it provides similar functionality for regression results (ShowRegTable function) but also baseline tables (CreateTableOne function). I've sometimes obtained somewhat different confidence intervals in stargazer, as compared to package used for calulating point estimates. Its nice though that it provides AIC, observations used etc... $\endgroup$ Nov 10, 2014 at 11:56
  • 1
    $\begingroup$ I haven't used tableone, but after a quick look it seems to be more about getting tables themselves, while stargazer is more about exporting those tables to html/latex with predefined styles. It might be possible to use tableone for obtaining the table and stargazer for exporting it to documents. like stargazer(ShowRegTable(obj)) $\endgroup$ Nov 10, 2014 at 12:17
  • 1
    $\begingroup$ As Frank put it, there are so many possible ways to achieve great things with R. I'm still thinking the ascii + markdown avenue has a lot to offer for little investment. But I appreciate your input and will continue experimenting. $\endgroup$ Nov 11, 2014 at 16:18

In 2020 the reporter package was released, which operates much like proc report. You get the data and statistics you want using other R packages, and then send the resulting data frame into reporter. Like this:


# Create temporary path
tmp <- file.path(tempdir(), "example3.pdf")

# Read in prepared data
df <- read.table(header = TRUE, text = '
      var     label        A             B          
      "ampg"   "N"          "19"          "13"         
      "ampg"   "Mean"       "18.8 (6.5)"  "22.0 (4.9)" 
      "ampg"   "Median"     "16.4"        "21.4"       
      "ampg"   "Q1 - Q3"    "15.1 - 21.2" "19.2 - 22.8"
      "ampg"   "Range"      "10.4 - 33.9" "14.7 - 32.4"
      "cyl"    "8 Cylinder" "10 ( 52.6%)" "4 ( 30.8%)" 
      "cyl"    "6 Cylinder" "4 ( 21.1%)"  "3 ( 23.1%)" 
      "cyl"    "4 Cylinder" "5 ( 26.3%)"  "6 ( 46.2%)"')

# Create table
tbl <- create_table(df, first_row_blank = TRUE) %>% 
  stub(c("var", "label")) %>% 
  define(var, blank_after = TRUE, label_row = TRUE, 
         format = c(ampg = "Miles Per Gallon", cyl = "Cylinders")) %>% 
  define(label, indent = .25) %>% 
  define(A, label = "Group A", align = "center", n = 19) %>% 
  define(B, label = "Group B", align = "center", n = 13)

# Create report and add content
rpt <- create_report(tmp, orientation = "portrait", output_type = "PDF") %>% 
  page_header(left = "Client: Motor Trend", right = "Study: Cars") %>% 
  titles("Table 1.0", "MTCARS Summary Table") %>% 
  add_content(tbl) %>% 
  footnotes("* Motor Trend, 1974") %>%
  page_footer(left = Sys.time(), 
              center = "Confidential", 
              right = "Page [pg] of [tpg]")

# Write out report

The report can be output in text, RTF, or PDF. Here is the PDF version: enter image description here

The advantage of this package is that you can create almost any kind of report. It will take more work than table1 or stargazer. But since it only generates the report, and doesn't try to generate the statistics, you are free to use any R statistical package. So more work, but more freedom.


Not the answer you're looking for? Browse other questions tagged or ask your own question.