| 47348 |
ripley |
1 |
% File src/library/tools/man/Rd2HTML.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 89561 |
smeyer |
3 |
% Copyright 2008-2026 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,
|
| 81921 |
deepayan |
22 |
stylesheet = if (dynamic) "/doc/html/R.css" else "R.css",
|
| 81913 |
deepayan |
23 |
texmath = getOption("help.htmlmath"),
|
| 83035 |
hornik |
24 |
concordance = FALSE,
|
| 83410 |
deepayan |
25 |
standalone = TRUE,
|
| 86166 |
deepayan |
26 |
hooks = list(),
|
| 89561 |
smeyer |
27 |
toc = FALSE,
|
| 83410 |
deepayan |
28 |
Rhtml = FALSE,
|
| 81881 |
deepayan |
29 |
...)
|
| 47624 |
ripley |
30 |
|
| 49042 |
hornik |
31 |
Rd2txt(Rd, out = "", package = "", defines = .Platform$OS.type,
|
| 50148 |
ripley |
32 |
stages = "render", outputEncoding = "",
|
| 52279 |
murdoch |
33 |
fragment = FALSE, options, ...)
|
| 47655 |
ripley |
34 |
|
| 49042 |
hornik |
35 |
Rd2latex(Rd, out = "", defines = .Platform$OS.type,
|
| 75593 |
hornik |
36 |
stages = "render", outputEncoding = "UTF-8",
|
| 87676 |
smeyer |
37 |
fragment = FALSE, ..., writeEncoding = outputEncoding != "UTF-8",
|
| 83035 |
hornik |
38 |
concordance = FALSE)
|
| 47649 |
ripley |
39 |
|
| 49042 |
hornik |
40 |
Rd2ex(Rd, out = "", defines = .Platform$OS.type,
|
| 66943 |
maechler |
41 |
stages = "render", outputEncoding = "UTF-8",
|
|
|
42 |
commentDontrun = TRUE, commentDonttest = FALSE, ...)
|
| 47348 |
ripley |
43 |
}
|
|
|
44 |
\arguments{
|
| 48972 |
murdoch |
45 |
\item{Rd}{ a filename or \code{Rd} object to use as input. }
|
| 76883 |
maechler |
46 |
\item{out}{a filename or connection object to which to write the
|
|
|
47 |
output. The default \code{out = ""} is equivalent to
|
|
|
48 |
\code{out = \link{stdout}()}.}
|
| 47386 |
ripley |
49 |
\item{package}{ the package to list in the output. }
|
| 49578 |
hornik |
50 |
\item{defines}{ string(s) to use in \verb{#ifdef} tests. }
|
| 48804 |
murdoch |
51 |
\item{stages}{ at which stage (\code{"build"}, \code{"install"}, or
|
| 49579 |
hornik |
52 |
\code{"render"}) should \verb{\Sexpr} macros be executed? See the
|
| 49578 |
hornik |
53 |
notes below.}
|
| 48994 |
murdoch |
54 |
\item{outputEncoding}{ see the \sQuote{Encodings} section below.}
|
| 49441 |
ripley |
55 |
\item{dynamic}{logical: set links for render-time resolution by
|
|
|
56 |
dynamic help system.}
|
| 49540 |
ripley |
57 |
\item{no_links}{logical: suppress hyperlinks to other help topics.
|
|
|
58 |
Used by \command{R CMD \link{Rdconv}}.}
|
| 52279 |
murdoch |
59 |
\item{fragment}{logical: should fragments of Rd files be accepted? See the
|
|
|
60 |
notes below.}
|
| 56520 |
murdoch |
61 |
\item{stylesheet}{character: a URL for a stylesheet to be used in the header
|
|
|
62 |
of the HTML output page.}
|
| 81913 |
deepayan |
63 |
\item{texmath}{character: controls how mathematics in \verb{\eqn} and
|
|
|
64 |
\verb{\deqn} commands are typeset in HTML output. Useful values
|
| 81970 |
deepayan |
65 |
are \code{"katex"} (default) and \code{"mathjax"} to use
|
| 85927 |
hornik |
66 |
\href{https://katex.org/}{\I{KaTeX}} or
|
|
|
67 |
\href{https://www.mathjax.org/}{\I{MathJax}} respectively, otherwise
|
| 81913 |
deepayan |
68 |
basic substitutions are used. May be ignored under certain
|
|
|
69 |
circumstances, e.g., if the help page already uses macros from the
|
| 81970 |
deepayan |
70 |
\code{\link[mathjaxr]{mathjaxr}} package.
|
|
|
71 |
}
|
| 83035 |
hornik |
72 |
\item{concordance}{Whether concordance data should be embedded in the
|
|
|
73 |
output file and attached to the return value.}
|
| 83410 |
deepayan |
74 |
\item{standalone}{logical: whether the output is intended to be a
|
|
|
75 |
standalone HTML file. If \code{FALSE}, the header and footer are
|
|
|
76 |
omitted, so that the output can be combined with other fragments.
|
|
|
77 |
}
|
| 87676 |
smeyer |
78 |
\item{hooks}{a list of functions controlling details of
|
| 86166 |
deepayan |
79 |
output. Currently the only component used is \code{pkg_href}, which
|
|
|
80 |
is used by \code{pkg2HTML} to determine the output HTML file path
|
|
|
81 |
given a package name as input. }
|
| 85407 |
deepayan |
82 |
\item{toc}{logical: whether the HTML output should include a table
|
| 89561 |
smeyer |
83 |
of contents. This requires a special \code{stylesheet}.
|
|
|
84 |
Ignored unless \code{standalone = TRUE}. }
|
| 85953 |
hornik |
85 |
\item{Rhtml}{logical: whether the output is intended to be a \I{Rhtml}
|
| 83699 |
smeyer |
86 |
file that can be processed using \CRANpkg{knitr}. If \code{TRUE}, the
|
| 83410 |
deepayan |
87 |
examples section is wrapped inside a \code{rcode} block. }
|
| 49496 |
ripley |
88 |
\item{Links, Links2}{\code{NULL} or a named (by topics) character vector of
|
| 49314 |
ripley |
89 |
links, as returned by \code{\link{findHTMLlinks}}.}
|
| 87676 |
smeyer |
90 |
\item{options}{an optional named list of options to pass to
|
| 52351 |
ripley |
91 |
\code{\link{Rd2txt_options}}.}
|
| 48972 |
murdoch |
92 |
\item{...}{ additional parameters to pass to \code{\link{parse_Rd}} when
|
|
|
93 |
\code{Rd} is a filename. }
|
| 87676 |
smeyer |
94 |
\item{writeEncoding}{logical: should an \verb{\inputencoding} line be written
|
|
|
95 |
for non-ASCII encodings? \LaTeX release 2018-04-01 and later
|
|
|
96 |
default to UTF-8; the declaration is obsolete in that case.}
|
|
|
97 |
\item{commentDontrun}{logical: should \verb{\dontrun} sections be commented
|
| 62809 |
murdoch |
98 |
out?}
|
| 87676 |
smeyer |
99 |
\item{commentDonttest}{logical: should \verb{\donttest} sections be commented out?}
|
| 47348 |
ripley |
100 |
}
|
|
|
101 |
\details{
|
| 51309 |
ripley |
102 |
These functions convert help documents: \code{Rd2HTML} produces HTML,
|
| 51310 |
ripley |
103 |
\code{Rd2txt} produces plain text, \code{Rd2latex} produces LaTeX.
|
|
|
104 |
\code{Rd2ex} extracts the examples in the format used by
|
|
|
105 |
\code{\link{example}} and \R utilities.
|
| 49008 |
maechler |
106 |
|
| 49354 |
ripley |
107 |
Each of the functions accepts a filename for an Rd file, and
|
| 49103 |
ripley |
108 |
will use \code{\link{parse_Rd}} to parse it before applying the
|
|
|
109 |
conversions or checks.
|
| 61433 |
ripley |
110 |
|
| 49496 |
ripley |
111 |
The difference between arguments \code{Link} and \code{Link2} is that
|
|
|
112 |
links are looked in them in turn, so lazy-evaluation can be used to
|
|
|
113 |
only do a second-level search for links if required.
|
| 51310 |
ripley |
114 |
|
| 77924 |
maechler |
115 |
Before \R 3.6.0, the default for \code{Rd2latex} was \code{outputEncoding = "ASCII"},
|
|
|
116 |
including using the second option of \verb{\enc} markup, because \LaTeX
|
|
|
117 |
versions did not provide enough coverage of UTF-8 glyphs for a long time.
|
| 61433 |
ripley |
118 |
|
| 50094 |
ripley |
119 |
\code{Rd2txt} will format text paragraphs to a width determined by
|
| 50127 |
ripley |
120 |
\code{width}, with appropriate margins. The default is to be close to
|
|
|
121 |
the rendering in versions of \R < 2.10.0.
|
| 61433 |
ripley |
122 |
|
| 49980 |
ripley |
123 |
\code{Rd2txt} will use directional quotes (see \code{\link{sQuote}})
|
| 81960 |
kalibera |
124 |
if option \code{"useFancyQuotes"} is true (usually the default,
|
| 90043 |
smeyer |
125 |
see \code{\link{sQuote}}) and the output encoding is UTF-8.
|
| 52254 |
murdoch |
126 |
|
|
|
127 |
Various aspects of formatting by \code{Rd2txt} are controlled by the
|
|
|
128 |
\code{options} argument, documented with the \code{\link{Rd2txt_options}}
|
| 76883 |
maechler |
129 |
function. Changes made using \code{options} are temporary, those
|
| 52254 |
murdoch |
130 |
made with \code{\link{Rd2txt_options}} are persistent.
|
| 61433 |
ripley |
131 |
|
| 52279 |
murdoch |
132 |
When \code{fragment = TRUE}, the \code{Rd} file will be rendered
|
|
|
133 |
with no processing of \verb{\Sexpr} elements or conditional defines
|
|
|
134 |
using \verb{#ifdef} or \verb{#ifndef}. Normally a fragment represents
|
|
|
135 |
text within a section, but if the first element of the fragment
|
| 61433 |
ripley |
136 |
is a section macro, the whole fragment will be rendered as
|
| 52279 |
murdoch |
137 |
a series of sections, without the usual sorting.
|
| 47348 |
ripley |
138 |
}
|
| 48994 |
murdoch |
139 |
\section{Encodings}{
|
| 49103 |
ripley |
140 |
Rd files are normally intended to be rendered on a wide variety of
|
|
|
141 |
systems, so care must be taken in the encoding of non-ASCII
|
|
|
142 |
characters. In general, any such encoding should be declared using
|
|
|
143 |
the \samp{encoding} section for there to be any hope of correct
|
| 49335 |
ripley |
144 |
rendering.
|
| 48994 |
murdoch |
145 |
|
| 49335 |
ripley |
146 |
For output, the \code{outputEncoding} argument will be used:
|
|
|
147 |
\code{outputEncoding = ""} will choose the native encoding for the
|
| 51309 |
ripley |
148 |
current system.
|
| 49335 |
ripley |
149 |
|
|
|
150 |
If the text cannot be converted to the \code{outputEncoding}, byte
|
|
|
151 |
substitution will be used (see \code{\link{iconv}}): \code{Rd2latex}
|
| 61433 |
ripley |
152 |
and \code{Rd2ex} give a warning.
|
| 48994 |
murdoch |
153 |
}
|
|
|
154 |
|
| 48934 |
murdoch |
155 |
\note{
|
| 83035 |
hornik |
156 |
The \verb{\Sexpr} macro includes
|
| 49252 |
ripley |
157 |
\R code that will be executed at one of three times: \emph{build} time
|
| 61433 |
ripley |
158 |
(when a package's source code is built into a tarball),
|
| 52669 |
murdoch |
159 |
\emph{install} time (when the package is installed or
|
| 49252 |
ripley |
160 |
built into a binary package), and \emph{render} time (when the man
|
|
|
161 |
page is converted to a readable format).
|
| 48934 |
murdoch |
162 |
|
| 49252 |
ripley |
163 |
For example, this man page was:
|
|
|
164 |
\enumerate{
|
|
|
165 |
\item built on
|
|
|
166 |
\Sexpr[stage=build]{format(Sys.time(), "\%Y-\%m-\%d at \%H:\%M:\%S")},
|
|
|
167 |
\item installed on
|
|
|
168 |
\Sexpr[stage=install]{format(Sys.time(), "\%Y-\%m-\%d at \%H:\%M:\%S")}, and
|
|
|
169 |
\item rendered on
|
|
|
170 |
\Sexpr[stage=render]{format(Sys.time(), "\%Y-\%m-\%d at \%H:\%M:\%S")}.
|
|
|
171 |
}
|
| 48934 |
murdoch |
172 |
}
|
|
|
173 |
|
| 49008 |
maechler |
174 |
\value{
|
| 84923 |
deepayan |
175 |
These functions are executed mainly for the side effect of writing the
|
|
|
176 |
converted help page. Their value is the name of the output file
|
|
|
177 |
(invisibly). For \code{Rd2latex}, the output name is given an
|
| 49252 |
ripley |
178 |
attribute \code{"latexEncoding"} giving the encoding of the file in a
|
| 84923 |
deepayan |
179 |
form suitable for use with the LaTeX \samp{inputenc} package. For
|
|
|
180 |
\code{Rd2HTML} with \code{standalone = FALSE}, an attribute
|
|
|
181 |
\code{"info"} gives supplementary information such as the contents of
|
|
|
182 |
the \code{name} and \code{title} fields. This is currently
|
|
|
183 |
experimental, and the details are subject to change.
|
| 83035 |
hornik |
184 |
|
| 84923 |
deepayan |
185 |
For \code{Rd2HTML} and \code{Rd2latex} with \code{concordance = TRUE}, a
|
|
|
186 |
\code{"concordance"} attribute is added, containing an
|
|
|
187 |
\code{\link{Rconcordance}} object.
|
| 47348 |
ripley |
188 |
}
|
| 47624 |
ripley |
189 |
\author{
|
| 47635 |
ripley |
190 |
Duncan Murdoch, Brian Ripley
|
| 47624 |
ripley |
191 |
}
|
| 70260 |
ripley |
192 |
\references{ \url{https://developer.r-project.org/parseRd.pdf} }
|
| 47624 |
ripley |
193 |
\seealso{
|
| 49354 |
ripley |
194 |
\code{\link{parse_Rd}}, \code{\link{checkRd}},
|
| 83035 |
hornik |
195 |
\code{\link{findHTMLlinks}}, \code{\link{Rd2txt_options}},
|
|
|
196 |
\code{\link{matchConcordance}}.
|
| 47624 |
ripley |
197 |
}
|
| 86023 |
smeyer |
198 |
\examples{\donttest{% timestamp, browseURL()
|
|
|
199 |
## Simulate rendering of this (installed) page in HTML and text format
|
|
|
200 |
Rd <- Rd_db("tools")[["Rd2HTML.Rd"]]
|
| 49142 |
murdoch |
201 |
|
| 56280 |
ripley |
202 |
outfile <- tempfile(fileext = ".html")
|
| 86023 |
smeyer |
203 |
Rd2HTML(Rd, outfile, package = "tools") |> browseURL()
|
| 48934 |
murdoch |
204 |
|
| 56280 |
ripley |
205 |
outfile <- tempfile(fileext = ".txt")
|
| 86023 |
smeyer |
206 |
Rd2txt(Rd, outfile, package = "tools") |> file.show()
|
|
|
207 |
}}
|
| 47348 |
ripley |
208 |
\keyword{ documentation }
|