In 20120718Wed143201, an Sweave example we used Sweave, xtable, and print options to display a dataframe in LaTeX.

In 20120718Wed183538, a knitr-to-LaTeX example we performed the same task replacing Sweave by knitr.

Now we will produce an html document to display the same table.

Whereas in a LaTeX document it was important to control the width of the columns so that a dataframe with long text passages in one of its columns (variables) would be legible, in this lesson we just depend on our ability to squish and squeeze the browser window using the mouse. The table responds accordingly---at least in today's browsers.

Suppose you have a table (or matrix or dataframe) with a lot of text in a cell, such as the following.

The header option "results='markup'" displays something like what the R "console" would show us:

whereas specifying "results='asis'" gives something illegible without further work:

This is where xtable, along with "a judicious choice of print options," comes in handy.

In this situation, "results='markup'" is not what we want:

In addition to the visible double pound signs (number signs), the displayed table does not reshape itself when I use the mouse to reshape the browser window (Firefox 8.0.1 or Safari 5.1.7).

But with "results='asis'", things are nicer:

Unlike with "results='markup'" this displayed table does reshape itself with my browser window.

Now let's display only the results, not the code, by setting "echo=FALSE".

Fine print (we use "results='markup'" so that this will display legibly):

Jacob Wegelin, 19 July 2012