[R] HTML Output from R

partha_bagchi@hgsi.com partha_bagchi at hgsi.com
Mon Aug 2 14:11:17 CEST 1999


Task: To generate HTML output from R
Details: I am trying to serve up HTML output from R. That is analyses or
table of data from R saved as HTML output with formatted tables etc. This
file is then called in a CGI script to output to user browser. The CGI
script inspired by Mark J. Ray reads the HTML output, formats the header
and footer and any graphic output if necessary.
My question is: Has anyone done any HTML output from R?

My first attempt at this is the following:
(Note: this function is not intended for "production" work; in particular
no error checking - all the niceties I intend to add in the end)

mat2html <- function(x, y, capt="The Default Title", file= file){
#x: The matrix to be written in HTML
#y: A vector  of length m containing the colnames of x
#capt: The title for the table
#file: The HTML file to write to
  n <- dim(x)[1] #no. of rows
  m <- dim(x)[2] #no. of columns
  sink(paste(file))
  cat("<table border= 1, align= \"center\">\n")
  cat(paste("<caption>", capt, "</caption>\n"))
  cat("<tr>")
  for(i in 1:m)cat(paste("<th>", y[i]))
  cat("</tr>\n")
  for(i in 1:n){
     cat("<tr>\n")
     for(j in 1:m){
        cat(paste("<td>", x[i,j]))
     }
     cat("</tr>\n")
  }
  cat("</table>\n")
  sink()
}
#---------------------------------------------------------------------------------------

Note that I am using the "forbidden" for loop. I am unable to see a
solution otherwise.
Comments and improvements obviously welcome.
TIA.
Partha.
PS: I will summarize all the replies I get.


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list