Skip to content

Latex or html output for freq() in prettyR

2 messages · christiaan pauw, Jim Lemon

#
christiaan pauw wrote:
Hi Christiaan,
One way to get the same output in HTML as in the console is to use the 
htmlize function in the prettyR package. htmlize runs an R script (so 
that you can edit the script until it does just what you want) and 
formats the output of the script as an HTML page. So if you had a script 
that contained:

library(prettyR)
x <- matrix(sample(1:3, 12, replace=TRUE), nrow=3,
 dimnames=list(c('A','B','C'),letters[1:4])) beteen 1 and 3
x # see what it looks like
fx<-freq(x) # create frequency table with frequencies and % per column
fx # looks pretty good, now I want to export it to latex or html

and you named it "testfreq.R". You could get the output you want with:

htmlize("testfreq.R",title="My HTML output")

the output will appear in a file named, "testfreq.html" unless you name 
it something else with the HTMLbase argument to htmlize. The "html" 
function from the Hmisc package is probably expecting a data frame and 
not the output of the freq function. However, it does the best it can 
and tries to make a data.frame out of a pig's ear, constructing and 
displaying the result in an HTML table. Hats off to Professor Harrell 
for writing the function so that it does anything more than barf in the 
situation.

Jim