I recommend that you model your HTML write function after write.table(). It's got many of the features you'd like to have and also will give you some good hints on how to handle row and column names and avoid that "forbidden" for loop. -- Terry J. Westley, Principal Engineer Veridian Engineering, Calspan Operations P.O. Box 400, Buffalo, NY 14225 twestley at buffalo.veridian.com http://www.veridian.com> -----Original Message----- > From: owner-r-help at stat.math.ethz.ch > [mailto:owner-r-help at stat.math.ethz.ch]On Behalf Of > partha_bagchi at hgsi.com > Sent: Monday, August 02, 1999 8:11 AM > To: r-help at stat.math.ethz.ch > Subject: [R] HTML Output from R > > > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> Terry J Westley writes:> I recommend that you model your HTML write function after > write.table(). It's got many of the features you'd like > to have and also will give you some good hints on how > to handle row and column names and avoid that "forbidden" > for loop.Yes, this is a very good suggestion. Eventually, one could have something like write.table(..., format = "HTML") (or LaTeX). -k> -- > Terry J. Westley, Principal Engineer > Veridian Engineering, Calspan Operations > P.O. Box 400, Buffalo, NY 14225 > twestley at buffalo.veridian.com http://www.veridian.com>> -----Original Message----- >> From: owner-r-help at stat.math.ethz.ch >> [mailto:owner-r-help at stat.math.ethz.ch]On Behalf Of >> partha_bagchi at hgsi.com >> Sent: Monday, August 02, 1999 8:11 AM >> To: r-help at stat.math.ethz.ch >> Subject: [R] HTML Output from R >> >> >> 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 >> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._