HTMLtools              package:CGIwithR              R Documentation

_U_t_i_l_i_t_y _F_u_n_c_t_i_o_n_s _f_o_r _W_r_i_t_i_n_g _i_n _H_T_M_L

_D_e_s_c_r_i_p_t_i_o_n:

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

_U_s_a_g_e:

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

_A_r_g_u_m_e_n_t_s:

 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

_D_e_t_a_i_l_s:

     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()' simply does 'cat("<!doctype html public
     \"-//W3C/DTD HTML 4.0/EN\">\n")'

     '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.)

_V_a_l_u_e:

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

_A_u_t_h_o_r(_s):

     David Firth d.firth@warwick.ac.uk

_E_x_a_m_p_l_e_s:

     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-bracket73bracket-normal was done, 
     ## just view temp.html in the web browser.
         

