The R Project SVN R

Rev

Rev 61433 | Rev 66943 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
47348 ripley 1
% File src/library/tools/man/Rd2HTML.Rd
2
% Part of the R package, http://www.R-project.org
59039 ripley 3
% Copyright 2008-10 R Core Team
47348 ripley 4
% Distributed under GPL 2 or later
5
 
6
\name{Rd2HTML}
47656 ripley 7
\alias{Rd2txt}
56186 murdoch 8
\alias{Rd2HTML}
47624 ripley 9
\alias{Rd2ex}
47649 ripley 10
\alias{Rd2latex}
49354 ripley 11
\title{ Rd Converters }
47348 ripley 12
\description{
49314 ripley 13
  These functions take the output of the \code{\link{parse_Rd}} function
49354 ripley 14
  and produce a help page from it.  As they are mainly
49314 ripley 15
  intended for internal use, their interfaces are subject to change.
47348 ripley 16
}
17
\usage{
47457 murdoch 18
Rd2HTML(Rd, out = "", package = "", defines = .Platform$OS.type,
49785 ripley 19
        Links = NULL, Links2 = NULL,
61433 ripley 20
        stages = "render", outputEncoding = "UTF-8",
56520 murdoch 21
        dynamic = FALSE, no_links = FALSE, fragment = FALSE,
22
        stylesheet = "R.css", ...)
47624 ripley 23
 
49042 hornik 24
Rd2txt(Rd, out = "", package = "", defines = .Platform$OS.type,
50148 ripley 25
       stages = "render", outputEncoding = "",
52279 murdoch 26
       fragment = FALSE, options, ...)
47655 ripley 27
 
49042 hornik 28
Rd2latex(Rd, out = "", defines = .Platform$OS.type,
56280 ripley 29
         stages = "render", outputEncoding = "ASCII",
30
         fragment = FALSE, ..., writeEncoding = TRUE)
47649 ripley 31
 
49042 hornik 32
Rd2ex(Rd, out = "", defines = .Platform$OS.type,
62809 murdoch 33
      stages = "render", outputEncoding = "UTF-8", 
34
      commentDontrun = TRUE, ...)
47348 ripley 35
}
36
\arguments{
48972 murdoch 37
  \item{Rd}{ a filename or \code{Rd} object to use as input. }
47386 ripley 38
  \item{out}{ a filename or connection object to which to write the output. }
39
  \item{package}{ the package to list in the output. }
49578 hornik 40
  \item{defines}{ string(s) to use in \verb{#ifdef} tests. }
48804 murdoch 41
  \item{stages}{ at which stage (\code{"build"}, \code{"install"}, or
49579 hornik 42
    \code{"render"}) should \verb{\Sexpr} macros be executed? See the
49578 hornik 43
    notes below.}
48994 murdoch 44
  \item{outputEncoding}{ see the \sQuote{Encodings} section below.}
49441 ripley 45
  \item{dynamic}{logical: set links for render-time resolution by
46
      dynamic help system.}
49540 ripley 47
  \item{no_links}{logical: suppress hyperlinks to other help topics.
48
      Used by \command{R CMD \link{Rdconv}}.}
52279 murdoch 49
  \item{fragment}{logical:  should fragments of Rd files be accepted?  See the
50
      notes below.}
56520 murdoch 51
  \item{stylesheet}{character: a URL for a stylesheet to be used in the header
52
      of the HTML output page.}
49496 ripley 53
  \item{Links, Links2}{\code{NULL} or a named (by topics) character vector of
49314 ripley 54
    links, as returned by \code{\link{findHTMLlinks}}.}
52351 ripley 55
  \item{options}{An optional named list of options to pass to
56
    \code{\link{Rd2txt_options}}.}
48972 murdoch 57
  \item{...}{ additional parameters to pass to \code{\link{parse_Rd}} when
58
    \code{Rd} is a filename. }
51309 ripley 59
  \item{writeEncoding}{should \verb{\inputencoding} lines be written in
60
      the file for non-ASCII encodings?}
62809 murdoch 61
  \item{commentDontrun}{should \verb{\dontrun} sections be commented
62
      out?}
47348 ripley 63
}
64
\details{
51309 ripley 65
  These functions convert help documents: \code{Rd2HTML} produces HTML,
51310 ripley 66
  \code{Rd2txt} produces plain text, \code{Rd2latex} produces LaTeX.
67
  \code{Rd2ex} extracts the examples in the format used by
68
  \code{\link{example}} and \R utilities.
49008 maechler 69
 
49354 ripley 70
  Each of the functions accepts a filename for an Rd file, and
49103 ripley 71
  will use \code{\link{parse_Rd}} to parse it before applying the
72
  conversions or checks.
61433 ripley 73
 
49496 ripley 74
  The difference between arguments \code{Link} and \code{Link2} is that
75
  links are looked in them in turn, so lazy-evaluation can be used to
76
  only do a second-level search for links if required.
51310 ripley 77
 
78
  Note that the default for \code{Rd2latex} is to output ASCII,
79
  including using the second option of \verb{\enc} markup.  This was
80
  chosen because use of UTF-8 in LaTeX requires version
81
  \sQuote{2005/12/01} or later, and even with that version the coverage
82
  of UTF-8 glyphs is not extensive (and not even as complete as
83
  Latin-1).
61433 ripley 84
 
50094 ripley 85
  \code{Rd2txt} will format text paragraphs to a width determined by
50127 ripley 86
  \code{width}, with appropriate margins.  The default is to be close to
87
  the rendering in versions of \R < 2.10.0.
61433 ripley 88
 
49980 ripley 89
  \code{Rd2txt} will use directional quotes (see \code{\link{sQuote}})
90
  if option \code{"useFancyQuotes"} is true (the default) and
91
#ifdef unix
92
  the current encoding is UTF-8.
93
#endif
94
#ifdef windows
95
  the current locale uses a single-byte encoding (except C).
96
  (Directional quotes are not attempted in CJK locales as they are
97
  usually double-width, which looks wrong with English text.)
98
#endif
52254 murdoch 99
 
100
  Various aspects of formatting by \code{Rd2txt} are controlled by the
101
  \code{options} argument, documented with the \code{\link{Rd2txt_options}}
102
  function. Changes made using \code{options} are temporary, those
103
  made with \code{\link{Rd2txt_options}} are persistent.
61433 ripley 104
 
52279 murdoch 105
  When \code{fragment = TRUE}, the \code{Rd} file will be rendered
106
  with no processing of \verb{\Sexpr} elements or conditional defines
107
  using \verb{#ifdef} or \verb{#ifndef}.  Normally a fragment represents
108
  text within a section, but if the first element of the fragment
61433 ripley 109
  is a section macro, the whole fragment will be rendered as
52279 murdoch 110
  a series of sections, without the usual sorting.
47348 ripley 111
}
48994 murdoch 112
\section{Encodings}{
49103 ripley 113
  Rd files are normally intended to be rendered on a wide variety of
114
  systems, so care must be taken in the encoding of non-ASCII
115
  characters.  In general, any such encoding should be declared using
116
  the \samp{encoding} section for there to be any hope of correct
49335 ripley 117
  rendering.
48994 murdoch 118
 
49335 ripley 119
  For output, the \code{outputEncoding} argument will be used:
120
  \code{outputEncoding = ""} will choose the native encoding for the
51309 ripley 121
  current system.
49335 ripley 122
 
123
  If the text cannot be converted to the \code{outputEncoding}, byte
124
  substitution will be used (see \code{\link{iconv}}): \code{Rd2latex}
61433 ripley 125
  and \code{Rd2ex} give a warning.
48994 murdoch 126
}
127
 
48934 murdoch 128
\note{
49578 hornik 129
  The \verb{\Sexpr} macro is a new addition to Rd files.  It includes
49252 ripley 130
  \R code that will be executed at one of three times: \emph{build} time
61433 ripley 131
  (when a package's source code is built into a tarball),
52669 murdoch 132
  \emph{install} time (when the package is installed or
49252 ripley 133
  built into a binary package), and \emph{render} time (when the man
134
  page is converted to a readable format).
48934 murdoch 135
 
49252 ripley 136
  For example, this man page was:
137
  \enumerate{
138
    \item built on
139
    \Sexpr[stage=build]{format(Sys.time(), "\%Y-\%m-\%d at \%H:\%M:\%S")},
140
    \item installed on
141
    \Sexpr[stage=install]{format(Sys.time(), "\%Y-\%m-\%d at \%H:\%M:\%S")}, and
142
    \item rendered on
143
    \Sexpr[stage=render]{format(Sys.time(), "\%Y-\%m-\%d at \%H:\%M:\%S")}.
144
  }
48934 murdoch 145
}
146
 
49008 maechler 147
\value{
49354 ripley 148
  These functions are executed mainly for the side effect of
49252 ripley 149
  writing the converted help page.  Their value is the name of the output
150
  file (invisibly).  For \code{Rd2latex}, the output name is given an
151
  attribute \code{"latexEncoding"} giving the encoding of the file in a
152
  form suitable for use with the LaTeX \samp{inputenc} package.
47348 ripley 153
}
47624 ripley 154
\author{
47635 ripley 155
  Duncan Murdoch, Brian Ripley
47624 ripley 156
}
47348 ripley 157
\references{ \url{http://developer.r-project.org/parseRd.pdf} }
47624 ripley 158
\seealso{
49354 ripley 159
  \code{\link{parse_Rd}}, \code{\link{checkRd}},
52351 ripley 160
  \code{\link{findHTMLlinks}}, \code{\link{Rd2txt_options}}.
47624 ripley 161
}
49103 ripley 162
\examples{\donttest{
49142 murdoch 163
 
164
\dontrun{
49314 ripley 165
## Simulate install and rendering of this page in HTML and text format:
48934 murdoch 166
 
54949 murdoch 167
Rd <- file.path("src/library/tools/man/Rd2HTML.Rd")
48988 hornik 168
 
56280 ripley 169
outfile <- tempfile(fileext = ".html")
170
browseURL(Rd2HTML(Rd, outfile, package = "tools",
171
          stages = c("install", "render")))
48934 murdoch 172
 
56280 ripley 173
outfile <- tempfile(fileext = ".txt")
174
file.show(Rd2txt(Rd, outfile, package = "tools",
175
          stages = c("install", "render")))
48934 murdoch 176
 
54949 murdoch 177
checkRd(Rd) # A stricter test than Rd2HTML uses
49142 murdoch 178
}}}
47348 ripley 179
\keyword{ documentation }