HTMLtools {CGIwithR}R Documentation

Utility Functions for Writing in HTML

Description

These functions provide shorthand ways of sending simple HTML constructions to standard output.

Usage

HTMLheader(title = character(0), css = character(0))
tag(tagname, ...)
untag(tagname)
comments(text)
br(n = 1)
linkto(text, URL)
mailto(text, address)
img(src, ..., graphURLroot)
lf(n = 1)

Arguments

tagname an HTML tag identifier, such as PRE, BODY, B, etc. If getOption("useUnquotedTagnames") is TRUE (the default, which can be unset by options(useUnquotedTagnames = FALSE)), tag names do not need to be quoted, for example tag(PRE) can be used in place of tag("PRE"). Otherwise tagname should be a character string.
... HTML qualifier(s) such as color="red"
text a character string
URL the target URL for an HTML anchor
address the email address in a mailto: construction
n an integer number of linefeeds or <BR>s to insert in the output
src a character string, the URL for the image
graphURLroot a character string giving the name of the directory in the Web site to in which the image file is located. This is not the actual directory in the file system, but rather the name of the directory as seen by a Web client.
title a character vector whose contents are collapsed into a single string (separated by spaces) and inserted into an HTML title
css a character vector giving the file names or URIs of the Cascading Style Sheet files to load for the HTML document. For each element, a <LINK rel="stylesheet" type="text/css" HREF=...> is inserted into the HEAD element of the HTML document. For elements that have a name, the name is treated as the value of the MEDIA attribute and added to the LINK element.

Details

These functions are all shorthand wrappers for commonly-used HTML constructions. Each simply outputs a piece of HTML code. Any of these can be done manually instead (using cat, for example) if something nonstandard is required.

HTMLheader() writes out the DOCTYPE, HTML, HEAD and start of the BODY element in the document. If title or css are specified in the call, then the corresponding elements are added to the HEAD element.

HTMLfooter closes the BODY and HTML tags at the end of the document.

tag and untag supply field signifiers such as <BODY> and </BODY>.

comments puts text inside the HTML comment markers <!-- and -->.

br outputs a <BR> (or more than one if n is greater than 1).

lf(n) inserts n linefeeds into the output.

linkto, mailto, img provide the standard HTML anchor, email and image insertion. For img, note that the source URL src is defined relative to graphURLroot if that is defined. For example, if graphURLroot is "/home/david/graphs/" then img("mypic.png") will output <IMG SRC="/home/david/graphs/mypic.png">. (Actually, a random query string is added to the URL by img to ensure that browsers do not display old, cached versions of graphs.)

Value

None (invisible(NULL)), except for img which returns invisible("image")

Author(s)

David Firth d.firth@warwick.ac.uk

Examples


useUnquotedTagnames <- TRUE

testpage<-function(){
    tag(HTML)
        tag(HEAD)
            tag(TITLE)
                cat("An example HTML page")
            untag(TITLE)
        untag(HEAD)
        lf()
        comments("Some comments to be ignored by the web browser")
        lf(2)
        tag(BODY, bgcolor = "yellow")
        lf(2)
        tag(h1)
            cat("A large heading")
        untag(h1)
        lf(2)
        tag(p)
            cat("A table of results:")
            tag(pre)
                lf()
                indentPrint(data.frame(Est = c(1.23,3.45),
                                       StErr = c(0.86,0.78),
                                       row.names = c("b0","b1")))
                lf()
            untag(pre)
        untag(p)
        lf(2)
        cat("Here is a graph:") ; br()
        img(src="http://www.stats.ox.ac.uk/~firth/CGIwithR/test.png") ; br(2)
        lf(2)
        cat("The author is ")
        mailto("David Firth", "david.firth@nuffield.ox.ac.uk")
        cat(" and here is his ")
        linkto("website.", "http://www.stats.ox.ac.uk/~firth/") ; br()
        lf()
        tag(p)
            cat("Output produced at ", date())
        untag(p)
        lf()
        untag(BODY)
        lf()
    untag(HTML)
    lf()
    }
    
# sink("temp.html")
testpage()

## The output if pasted into a file should be viewable by
## a web browser.  Or if the this-is-escaped-codenormal-bracket83bracket-normal was done, 
## just view temp.html in the web browser.
    

[Package CGIwithR version 0.72 Index]