rnw2rmd: Convert vognettes from *.Rnw to *.Rmd

View source: R/rnw2rmd.R

rnw2rmdR Documentation

Convert vognettes from *.Rnw to *.Rmd

Description

This is a much enhanced R port of Perl code gists from GitHub [1, 2]. It tries its best to convert old Sweave vignettes into R markdown. Please do not expect it to do wonders, but to give you a good starting point for conversions.

Usage

rnw2rmd(
  file,
  output = "rmarkdown::html_vignette",
  output_options = c(toc = "true"),
  engine = "knitr::rmarkdown",
  csl = NULL,
  eval = FALSE,
  replace = NULL,
  flattr_id = NULL,
  write_file = FALSE,
  overwrite = FALSE
)

Arguments

file

Path to an *.Rnw file to convert.

output

Character string defining the R markdown output format.

output_options

A named character vector with additional options. If you need more than the default indentaion, you have to provide it directly (see default values for toc_float).

engine

Character string defining the VignetteEngine value.

csl

Character string defining a CSL style file for the bibliography. Please note that you will have to provide an existing file of that name in an appropriate location, like the *.Rmd file's directory. Ignored if NULL, or if no bibliography was detected.

eval

Logical, a default value for all R code chunks that are found. This is like a safety net to be able to disable all code by default. Setting the default value will be omitted if set to NULL.

replace

An optional list of named character vectors with regular expressions to do custom replacements in the text body. The list must contain vectors with two character elements named from and to, to define what expressions should be replaced and with what.

flattr_id

Character string, the ID value of your Flattr meta tag. If set will be added to the header of the resulting HTML file of the vignette.

write_file

Logical, if set to TRUE results will be written to a file in the same directory as the input file, but with *.Rmd file ending. Default is FALSE, meaning results are returned as a character string.

overwrite

Logical, whether existing files should be overwritten if write_file=TRUE.

References

[1] https://gist.github.com/mikelove/5618f935ace6e389d3fbac03224860cd

[2] https://gist.github.com/lgatto/d9d0e3afcc0a4417e5084e5ca46a4d9e

Examples

## Not run: 
rnw2rmd(file.path(find.package("roxyPackage"),"doc","roxyPackage_vignette.Rnw"))

# use a fancy theme (not so good for CRAN, bloats the HTML file)
rnw2rmd(
  file.path(find.package("roxyPackage"),"doc","roxyPackage_vignette.Rnw"),
  output="html_document",
  output_options=c(
    theme="cerulean",
    highlight="kate",
    toc="true",
    toc_float="\n      collapsed: false\n      smooth_scroll: false",
    toc_depth=3
  )
)

## End(Not run)

unDocUMeantIt/roxyPackage documentation built on March 9, 2023, 6:31 p.m.