The purpose of convertr
is to automate converting between R scripts,
RMarkdown files and Quarto files with, focusing on managing code-chunks,
code comments, and the differences in YAML options between .qmd and .rmd
files.
⚠️ WarningThis package is currently under development and may only work as intended in a limited number of situations. As with all R functions that write files,
convertr
will not check for duplicate files and will automatically overwrite files in the output directory if an output file with the name already exists. Test on a back-up copy of your file before using.
You can install the development version of convertr from GitHub with:
# install.packages("devtools")
devtools::install_github("martinasladek/convertr")
The package currently three main functions:
qmd_to_r()
: Convert a .qmd file into a .R file. Headings are converted into section titles (e.g# heading -----
as defined by the the shortcut ctrl/cmd + shift + R). Text outside of code chunks is converted into comments. Chunk options defined by#|
are retained as comments.r_to_qmd()
: Convert a .R file into a .qmd file. Section titles are converted into headings (e.g# heading -----
as defined by the the shortcut ctrl/cmd + shift + R). Comments are converted into text in between code chunks (unless the comments are within the code, in which case they stay inside of the code chunk).knitr_opts_to_yaml()
: Take an existing .rmd file and convert its YAML header options to be compatible with Quarto. Currently minimal functionality. html output options are automatically set toself-contained: TRUE
. Underscores are replaced with hyphens for all other options.
Load convertr
:
library(convertr)
Convert Quarto into an R script:
convertr::qmd_to_r(
input_dir = "path/to/some_quarto_file.qmd",
output_dir = "path/to/new_converted_r_script.R"
)
Convert an R script into a Quarto file:
convertr::r_to_qmd(
input_dir = "path/to/some_R_script.R",
output_dir = "path/to/new_converted_qmd_file.qmd"
)
Convert an RMarkdown chunk options into a Quarto YAML header:
convertr::knitr_opts_to_yaml(
input_dir = "path/to/some_old_rmd_file.rmd",
output_dir = "path/to/new_qmd_file.qmd"
)