Browse Source

Set default wrapping behavior with options()

Closes #47
master
Noam Ross 1 year ago
parent
commit
6c0aba6898
6 changed files with 24 additions and 19 deletions
  1. +5
    -3
      R/dedoc.R
  2. +2
    -2
      R/diff.R
  3. +2
    -2
      R/redoc.R
  4. +5
    -4
      man/dedoc.Rd
  5. +6
    -5
      man/redoc.Rd
  6. +4
    -3
      man/redoc_diff.Rd

+ 5
- 3
R/dedoc.R View File

@@ -26,7 +26,8 @@
#' attempts to restore the code as close to its original location in the document
#' as possible. "comment" will do so but wrap it in HTML comments. "omit" will
#' not restore the code at all.
#' @param wrap The width at which to wrap text. If `NA`, text is not wrapped
#' @param wrap The width at which to wrap text. If `NA`, text is not wrapped.
#' Set the default with `"redoc.wrap"` in `options()`.
#' @param overwrite Whether to overwrite an existing file
#' @param orig_codefile,orig_docx The original `.codelist.yml` or Word document
#' created when the document was first knit. Useful for debugging, or in
@@ -43,7 +44,7 @@ dedoc <- function(docx, to = NULL, dir = ".",
track_changes = "comments_only",
block_missing = "comment",
inline_missing = "omit",
wrap = 80, overwrite = FALSE,
wrap = getOption("redoc.wrap", 80), overwrite = FALSE,
orig_docx = NULL, orig_codefile = NULL,
verbose = FALSE) {
if (!is_redoc(docx) && is.null(orig_codefile) && is.null(orig_docx)) {
@@ -271,7 +272,8 @@ merge_yaml_headers <- function(md, codelist) {

convert_docx_to_md <- function(docx,
track_changes,
wrap = 80, verbose, md_only) {
wrap = getOption("redoc.wrap", 80),
verbose, md_only) {
docx <- normalizePath(docx)
track_changes <- match.arg(track_changes, track_changes)
if (track_changes == "criticmarkup") {


+ 2
- 2
R/diff.R View File

@@ -16,7 +16,7 @@
#' @param track_changes,block_missing,inline_missing Arguments passed to
#' [dedoc()] to determine how to handle edits in the Word document.
#' @param wrap Width to wrap text lines when converting from docx to markdown.
#' If `NULL`, no wrapping.
#' If `NULL`, no wrapping. Set the default with `"redoc.wrap"` in `options()`.
#' @param mode,context,tar.banner,cur.banner,... Arguments passed to
#' [diffobj::diffFile()] to customize printing of the diff.
#' @return A [`Diff`][diffobj::diffPrint()] object, which will be displayed in the RStudio
@@ -30,7 +30,7 @@ redoc_diff <- function(docx,
track_changes = "comments_only",
block_missing = "comment",
inline_missing = "omit",
wrap = 80,
wrap = getOption("redoc.wrap", 80),
mode = "sidebyside", context = "auto",
tar.banner = NULL, cur.banner = NULL,
...) {


+ 2
- 2
R/redoc.R View File

@@ -6,7 +6,7 @@
#' @param highlight_outputs whether to highlight outputs from chunks and inline
#' code in the final document
#' @param wrap when round-tripping the document, at what width to wrap the
#' markdown output? See [dedoc()].
#' markdown output? Set the default with `"redoc.wrap"` in `options()`. See [dedoc()].
#' @param margins page margin size. Can be a single value or a named vector
#' with values, `top`, `bottom`, `left`, `right`, `gutter`, `header`, and
#' `footer`. If NULL defaults to the reference document.
@@ -28,7 +28,7 @@
#' @importFrom rmarkdown word_document
#' @importFrom knitr knit_print knit_global opts_chunk opts_knit
#' @export
redoc <- function(highlight_outputs = TRUE, wrap = 80,
redoc <- function(highlight_outputs = TRUE, wrap = getOption("redoc.wrap", 80),
margins = NULL, line_numbers = NULL,
comment_author = NULL, keep_md = FALSE,
wrappers = list(


+ 5
- 4
man/dedoc.Rd View File

@@ -5,9 +5,9 @@
\title{Convert an Reversible Document back to R Markdown}
\usage{
dedoc(docx, to = NULL, dir = ".", track_changes = "comments_only",
block_missing = "comment", inline_missing = "omit", wrap = 80,
overwrite = FALSE, orig_docx = NULL, orig_codefile = NULL,
verbose = FALSE)
block_missing = "comment", inline_missing = "omit",
wrap = getOption("redoc.wrap", 80), overwrite = FALSE,
orig_docx = NULL, orig_codefile = NULL, verbose = FALSE)
}
\arguments{
\item{docx}{The `.docx`` file to convert}
@@ -35,7 +35,8 @@ attempts to restore the code as close to its original location in the document
as possible. "comment" will do so but wrap it in HTML comments. "omit" will
not restore the code at all.}

\item{wrap}{The width at which to wrap text. If \code{NA}, text is not wrapped}
\item{wrap}{The width at which to wrap text. If \code{NA}, text is not wrapped.
Set the default with \code{"redoc.wrap"} in \code{options()}.}

\item{overwrite}{Whether to overwrite an existing file}



+ 6
- 5
man/redoc.Rd View File

@@ -4,17 +4,18 @@
\alias{redoc}
\title{R Markdown format for Reversible Reproducible Word Documents}
\usage{
redoc(highlight_outputs = TRUE, wrap = 80, margins = NULL,
line_numbers = NULL, comment_author = NULL, keep_md = FALSE,
wrappers = list(htmlcommentwrap, latexwrap, rawblockwrap, rawspanwrap,
cmwrap, citationwrap), diagnostics = TRUE, ...)
redoc(highlight_outputs = TRUE, wrap = getOption("redoc.wrap", 80),
margins = NULL, line_numbers = NULL, comment_author = NULL,
keep_md = FALSE, wrappers = list(htmlcommentwrap, latexwrap,
rawblockwrap, rawspanwrap, cmwrap, citationwrap), diagnostics = TRUE,
...)
}
\arguments{
\item{highlight_outputs}{whether to highlight outputs from chunks and inline
code in the final document}

\item{wrap}{when round-tripping the document, at what width to wrap the
markdown output? See \code{\link[=dedoc]{dedoc()}}.}
markdown output? Set the default with \code{"redoc.wrap"} in \code{options()}. See \code{\link[=dedoc]{dedoc()}}.}

\item{margins}{page margin size. Can be a single value or a named vector
with values, \code{top}, \code{bottom}, \code{left}, \code{right}, \code{gutter}, \code{header}, and


+ 4
- 3
man/redoc_diff.Rd View File

@@ -6,8 +6,9 @@
\usage{
redoc_diff(docx, target = "original", current = "current",
track_changes = "comments_only", block_missing = "comment",
inline_missing = "omit", wrap = 80, mode = "sidebyside",
context = "auto", tar.banner = NULL, cur.banner = NULL, ...)
inline_missing = "omit", wrap = getOption("redoc.wrap", 80),
mode = "sidebyside", context = "auto", tar.banner = NULL,
cur.banner = NULL, ...)
}
\arguments{
\item{docx}{Path to an MS Word \code{.docx} file originally generated with
@@ -20,7 +21,7 @@ redoc_diff(docx, target = "original", current = "current",
\code{\link[=dedoc]{dedoc()}} to determine how to handle edits in the Word document.}

\item{wrap}{Width to wrap text lines when converting from docx to markdown.
If \code{NULL}, no wrapping.}
If \code{NULL}, no wrapping. Set the default with \code{"redoc.wrap"} in \code{options()}.}

\item{mode, context, tar.banner, cur.banner, ...}{Arguments passed to
\code{\link[diffobj:diffFile]{diffobj::diffFile()}} to customize printing of the diff.}


Loading…
Cancel
Save