Rd_help2txt: Extract selected help sections as text.

View source: R/Rdutils.R

Rd_help2txtR Documentation

Extract selected help sections as text.

Description

Extract selected help sections as text.

Usage

Rd_help2txt(x, topic, pkgname = "", help_type = "text",
               verbose = FALSE, try.all.packages = FALSE,
               keep_section = TRUE, omit_sec_header = FALSE)

Arguments

x

the help object. Its class may be "Rd", string or "help_files_with_topic".

topic

passed on to Rd_fun

pkgname

passed on to Rd_fun

help_type

passed on to Rd_fun

verbose

passed on to Rd_fun

try.all.packages

passed on to Rd_fun

keep_section

the section to keep. If it is a character vector of length at least one, the sections listed in it (plus ⁠\title⁠ and ⁠\name⁠) are kept in the result, the rest are dropped. Otherwise all sections are returned.

omit_sec_header

whether to omit or not the section header

Details

Basically, this function calls Rd_fun to get an Rd object containing the required help sections, then converts them to text with tools::Rd2txt. At this point however unwanted sections may be present since tools::Rd2txt requires ⁠\title⁠ and ⁠\name⁠. If ⁠\title⁠ is not an element of keep_section, it should be dropped. Other header information is dropped if omit_sec_header = TRUE. The way this is done is crude and based on inspection. It would be better done using the Rd object but then I might need to, effectively reprogram Rd2txt.

FIXME: The above was done for version R-2.10 (I think), see if a more modular version is available in current versions of R. Also, it is tested only with help_type="text".

FIXME: Arguments whose description is marked "passed on to Rd_fun" could be replaced by a "..." argument.

Value

A character vector containing the text of the selected help sections.

Note

In R-2.12.0 the function tools::Rd2txt acquired a fragment argument. So, tools::Rd2txt now works with fragments and can be used directly in many cases.

Author(s)

Georgi N. Boshnakov

Examples

# 1st arg is the name of a function
Rd_help2txt("data.frame",keep_section="\\arguments")

Rd_help2txt("seq",keep_section="\\examples")
Rd_help2txt("seq",keep_section="\\examples",omit_sec_header=TRUE)

GeoBosh/gbRd documentation built on Oct. 19, 2023, 3:15 p.m.