[R] reformatting R scripts for htmlize()
Jim Lemon
jim at bitwrit.com.au
Fri Jun 20 14:38:35 CEST 2008
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
More information about the R-help
mailing list