Learn R Programming

prettyR (version 1.1-3)

htmlize: Read an R script and write HTML output

Description

Produces HTML output from an R script.

Usage

htmlize(Rfile,HTMLbase,HTMLdir,title,
 bgcolor="#dddddd",echo=FALSE,do.nav=FALSE,useCSS=NULL,...)

Arguments

Rfile
The R script file from which to read the commands.
HTMLbase
The base name for the HTML files (see Details).
HTMLdir
The directory in which to write the HTML output.
title
The title of the HTML page and the headings for the frames.
bgcolor
The background color for the frames.
echo
Whether to include ("echo") the commands in the listing.
do.nav
Whether to have a navigation window.
useCSS
The name of a CSS stylesheet that will define the appearance of components of the HTML display. If this is not NULL, the CSS file should exist.
...
Additional arguments - currently ignored.

Value

  • nil

Details

htmlize allows the user to produce a basic HTML listing from an existing R script. The script must already run correctly with source. If there is any graphic output, the script must contain the necessary commands to set up the graphic devices. Note that only TIFF, GIF, BMP, JPEG and PNG graphic images are generally viewable in HTML browsers. The last two are probably the most reliable, but see their help pages for more details. The graphic files will be linked to the HTML listing page so that they should be interleaved with text output and commands. If do.nav is TRUE, three files will be output. The first will be named HTMLbase.html, where HTMLbase is whatever string has been passed as that argument. If that argument is missing, the function will attempt to munge the Rfile argument into a base name. This file is an "index" file that sets up the HTML frameset. The second file will be named HTMLbase_nav.html and will be dispayed at the left side of the HTML output as a "navigation" list using the commands as names. Commands longer than 20 characters will be truncated. The third file, named HTMLbase_list.html, contains the program listing. All three files will be written in HTMLdir. If this is missing, the path of Rfile will be used. If do.nav is FALSE, only one file will be written. It will have the same content as the HTMLbase_list.html file except without the name tags for navigation and it will be named HTMLbase.html. Commands that create or alter connections, such as sink are "forbidden", not evaluated and marked as comments in the listing. This prevents such commands from altering the connections necessary to write the HTML files. The ability to nominate a CSS stylesheet allows the user to customize the appearance of the HTML output. The most likely use of the useCSS argument is for the user to specify whatever aspects of the HTML display are to be different from the default browser values in a stylesheet.

Examples

Run this code
rcon<-file("test.R","w")
 cat("test.df<-data.frame(a=factor(sample(LETTERS[1:4],100,TRUE)),
",
  file=rcon)
 cat("b=sample(1:4,100,TRUE),c=rnorm(100),d=rnorm(100))
",file=rcon)
 cat("describe(test.df)
",file=rcon)
 cat("print(freq(test.df$a))
",file=rcon)
 cat("xtab(a~b,test.df)
",file=rcon)
 cat("brkdn(c~b,test.df)
",file=rcon)
 cat("png("hista.png")
hist(test.df$b)
dev.off()
",file=rcon)
 cat("png("plotcd.png")
plot(test.df$c,test.df$d)
dev.off()
",file=rcon)
 close(rcon)
 # call htmlize with minimal arguments
 htmlize("test.R")
 # if you want to see the output, use the following line
 # system(paste(options("browser")," file:",getwd(),"/test.html",sep="",collapse=""))
 # to clean up, use the following line
 # system("rm test.R test.html test_nav.html test_list.html hista.png plotcd.png")

Run the code above in your browser using DataLab