The R Project SVN R

Rev

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