rnw_to_rmd: Sweave to RMarkdown

View source: R/rnw-tools.R

rnw_to_rmdR Documentation

Sweave to RMarkdown

Description

automated function for converting a single Sweave file to R Markdown file

Usage

rnw_to_rmd(
  input_file,
  output_format,
  clean_up = TRUE,
  autonumber_eq = FALSE,
  autonumber_sec = TRUE,
  suppress_package_startup_message = FALSE,
  kable_tab = TRUE,
  fig_in_r = TRUE,
  algorithm_render = FALSE
)

Arguments

input_file

input Sweave file path

output_format

knit output type for the RMarkdown file options for "bookdown", "biocstyle", "litedown"

clean_up

whether to clean up the intermediate files, default is TRUE

autonumber_eq

whether to autonumber the equations, default is FALSE

autonumber_sec

whether to autonumber the sections, default is TRUE

suppress_package_startup_message

whether to suppress the package startup message, default is FALSE

kable_tab

converts to kable table instead of markdown tables

fig_in_r

whether to include figures in R code chunks, default is TRUE

algorithm_render

Enable to include algorithms with pseudocode.js, default is FALSE optional is TRUE

Value

True if R Markdown file successfully generated in the same folder

Note

Use pandoc version greater than or equal to 3.1

Examples

# move example Sweave article and associated files to a temporary directory
example_dir <- system.file("examples", "sweave_article", package = "texor")
file.copy(from = example_dir, to = tempdir(), recursive = TRUE)
article_dir <- file.path(tempdir(), "sweave_article")

# convert example Sweave article to Rmd
rnw_to_rmd(file.path(article_dir, "example.Rnw"),
           output_format = "bookdown",
           clean_up = TRUE,
           autonumber_eq = TRUE,
           autonumber_sec = FALSE)

# convert Rmd to HTML (comment this step to avoid failure on R CMD Check)
# rmarkdown::render(file.path(article_dir, "example.Rmd"))
# browseURL(file.path(article_dir, "example.html"))

# remove temporary files
unlink(article_dir, recursive = TRUE)

texor documentation built on April 4, 2025, 4:44 a.m.