MyNixOS website logo
Description

Concordances for 'R Markdown'.

Supports concordances in 'R Markdown' documents. This currently allows the original source location in the '.Rmd' file of errors detected by 'HTML tidy' to be found more easily, and potentially allows forward and reverse search in 'HTML' and 'LaTeX' documents produced from 'R Markdown'. The 'LaTeX' support has been included in the most recent development version of the 'patchDVI' package.

RmdConcord

R-CMD-check

The goal of RmdConcord is to provide support for concordances in R Markdown files.

This is based on a suggestion and initial code from Heather Turner. Thanks!

Rmarkdown files (type .Rmd) allow presentation articles to be generated from simple text documents. However, if there are errors, these can be difficult to track back to the originating markdown text because there are often intermediate stages: the R Markdown file is converted to plain Markdown, the plain Markdown is converted to HTML or LaTeX, the LaTeX is converted to PDF. A concordance that allows back-tracking of errors from the later steps is needed.

The main use for this in HTML output is to help deciphering HTML Tidy error messages. If you replace the original driver with RmdConcord::html_documentC, R CMD check should report locations in the original .Rmd file.

With PDF output using patchDVI::pdf_documentC (from patchDVI version 1.11.0 or newer), Synctex output will be enabled, and it will be patched to refer to the .Rmd file. This is helpful in previewers like the one in TeXworks that can link source to a preview. This package contains RmdConcord::pdf_documentC0, which does part of the work (preparing the concordance records) but doesn’t do the patching to make previewers work with it.

Limitations

The Pandoc Commonmark driver is still in development, so some features supported in the rmarkdown drivers will not be fully supported using the drivers from this package. At present I am using Pandoc 2.19.2 and I know of the following missing features:

  • Citations, e.g. [@doe99]

  • Raw LaTeX will need to be “fenced”, e.g. entered as

    ```{=latex}
    LaTeX
    ```
    

    (The \pagebreak and \newpage macros receive special treatment, so they don’t need fencing as long as they are separated by blank lines from text above and below.)

If you notice others, please let me know, e.g. by posting an issue to the Github site.

These will not cause errors (Markdown doesn’t ever give errors!), but they won’t be handled properly. We suggest using the RmdConcord and patchDVI drivers during early development or to track down obscure bugs, but using the rmarkdown drivers for regular production.

Installation

This version of RmdConcord makes use of some functions that will be released in R 4.3.0. Those functions have been copied into RmdConcord, so the package should be compatible with older versions of R.

You can install the development version of RmdConcord from GitHub with:

# install.packages("devtools")
devtools::install_github("dmurdoch/RmdConcord")

Example

To embed concordances in an R Markdown HTML document, change the output YAML to patchDVI::html_documentC. For a PDF document, use patchDVI::pdf_documentC.

output: patchDVI::html_documentC

This is used in the Sample.Rmd vignette, which contains an error on line 23.

library(RmdConcord)
example(processConcordance)
#> 
#> prcssC> # This example works on the file inst/sample/Sample.Rmd,
#> prcssC> # which should be a copy of the vignette Sample.Rmd.  This
#> prcssC> # is convenient because RStudio doesn't install vignettes by default.
#> prcssC> 
#> prcssC> # First, see the results without concordances:
#> prcssC> 
#> prcssC> library(RmdConcord)
#> 
#> prcssC> dir <- tempdir()
#> 
#> prcssC> intermediates <- tempfile()
#> 
#> prcssC> infile <- system.file("sample/Sample.Rmd", package = "RmdConcord")
#> 
#> prcssC> outfile1 <- file.path(dir, "html_vignette.html")
#> 
#> prcssC> rmarkdown::render(infile,
#> prcssC+                   intermediates_dir = intermediates,
#> prcssC+                   output_file = outfile1,
#> prcssC+                   quiet = TRUE)
#> 
#> prcssC> tidy_validate(outfile1)
#>      line  col msg                                       txt              
#> [1,] "359" "4" "Error: <foobar> is not recognized!"      "<p><foobar></p>"
#> [2,] "359" "4" "Warning: discarding unexpected <foobar>" "<p><foobar></p>"
#> 
#> prcssC> # Next, see them with concordances by setting
#> prcssC> # the output format to use RmdConcord::html_documentC
#> prcssC> # which post-processes the document with processConcordance.
#> prcssC> 
#> prcssC> dir <- tempdir()
#> 
#> prcssC> outfile2 <- file.path(dir, "commonmark.html")
#> 
#> prcssC> rmarkdown::render(infile,
#> prcssC+                   intermediates_dir = intermediates,
#> prcssC+                   output_file = outfile2,
#> prcssC+                   output_format = html_documentC(),
#> prcssC+                   quiet = TRUE)
#> 
#> prcssC> tidy_validate(outfile2)
#>      line  col msg                                       txt       
#> [1,] "319" "1" "Error: <foobar> is not recognized!"      "<foobar>"
#> [2,] "319" "1" "Warning: discarding unexpected <foobar>" "<foobar>"
#>      srcFile      srcLine
#> [1,] "Sample.Rmd" "23"   
#> [2,] "Sample.Rmd" "23"   
#> 
#> prcssC> unlink(c(intermediates, outfile1, outfile2), recursive = TRUE)
Metadata

Version

0.3

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows