Re: [R] reformatting R scripts for htmlize()

From: Jim Lemon <jim_at_bitwrit.com.au>
Date: Fri, 20 Jun 2008 22:38:35 +1000

On Wed, 2008-06-18 at 11:49 +0200, Agustin Lobo wrote:
> Hi!
>
> I have a bunch of (mainly class) R scripts that I would
> like to convert into html pages (although if someone
> thinks that what I want to do is easier with latex or pdf,
> please tell me).
>
> Considering the format of my files, htmlize() seems the best
> option. The only problem is that I would need
> to write graphics to a file, thus
> converting parts like:
>
> plot(sel$hora, sel$COD_SP_C)
> #and check the time intervals
> plot(mishdift(sel$hora))
>
> into:
>
> png("1.png");plot(sel$hora, sel$COD_SP_C);dev.off()
> #and check the time intervals
> png("2.png");plot(mishdift(sel$hora));dev.off()
>
> Any ideas on how to write an script (could be done
> in R itself?) that would automatically modify
> the current script into a "htmlize-friendly" script?
>
> One problem is that while R accepts png()
> providing a default name for the png file,
> htmlize() fails unless a name is provided.
>
Hi Agustin,
htmlize was intended to provide a simple way to produce output from R scripts that:

  1. Looked familiar to the average stats consumer.
  2. Required minimal modification from the R script that the average R user would write.

The R2html function in the prettyR package, generously contributed by Phillipe Grosjean, goes some way toward integrating graphics into the output, whereas htmlize requires the user to add the graphic device commands. Because more complex commands are hard to anticipate:

barpos<-barplot(heights,...)
dispbars(barpos,heights,...)
es<-emptyspace(...)
legend(...)

just writing a function that looks up the names of plotting functions and tries to add graphic device commands would only serve for very basic plots. One can't even hold the "dev.off()" until a non-plotting command appears, for these can easily occur within a group of plotting commands as in the above example. I tend to write the graphic device commands into the script, but leave them commented out until I am ready to run htmlize. I'm always happy to listen to suggestions on how the functions in the packages I maintain could be improved, however.

Jim



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 20 Jun 2008 - 16:01:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 20 Jun 2008 - 16:30:46 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive