To install the Rd2md
package, you can either use the
official CRAN repository or install directly from github.
From CRAN:
install.packages("Rd2md")
From Github:
::install_github("quantsch/Rd2md") devtools
The package does not have any third-party package dependencies as I wanted to keep things simple. However, it heavily borrows ideas and code from pkgdown, so big thanks to the great work there!
See the introduction vignette:
vignette("introduction")
date_format
, etc.You can “easily” extend the parsing functionality by implementing your own parser. Without further details, an (almost) minimal example for text reference manual:
# required: a generic parsing function
<- function(x, ...) UseMethod("as_txt")
as_txt # required: introduces recursion
<- function(x, ...) {
process_txt_contents # traverse through list and concatenate to string
if (is.list(x)) x[] <- lapply(x, as_txt, ...)
paste(as.character(x), collapse = "")
}# required: a fallback as not all tags might have an `as_txt` method
<- function(x, ...) {
as_txt.default process_txt_contents(x, ...)
}# not required but improves output significantly:
# we add a section title and a separator for readability
<- function(x, ...) {
as_txt.rdsection paste0(
:::tag_to_title(x),
Rd2md"\n----------------\n\n",
process_txt_contents(x, ...), "\n\n"
)
}# not required but improves output significantly:
# we add a paragraph after the description file
<- function(x, ...) paste0(x, "\n\n")
as_txt.DESCRIPTION # not required but looks better: we drop the comments
<- function(x, ...) ""
as_txt.COMMENT
# required: the output_format definition
<- function() output_format("txt", ".txt", as_txt)
txt_document
# now we can render our new text refman:
render_refman(output_format = txt_document())