knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The diff_rmd
function can be used to produce a nicely-formatted document showing the differences between two rmarkdown files. For the purposes of demonstration, we'll use the example files bundled with the package. We'll compare modified_file
to its earlier version reference_file
:
modified_file <- system.file("extdata/CheatSheet-modified.Rmd", package = "reviewer") reference_file <- system.file("extdata/CheatSheet.Rmd", package = "reviewer")
## for demo purposes, just take the first few lines of these files tempfile1 <- tempfile() writeLines(head(readLines(modified_file), 14), con = tempfile1) modified_file <- tempfile1 tempfile2 <- tempfile() writeLines(head(readLines(reference_file), 12), con = tempfile2) reference_file <- tempfile2
Compare:
library(reviewer) result <- diff_rmd(modified_file, reference_file)
And our output:
## some minor trickery to make the rendered output appear properly in the rendered file htmltools::includeHTML(result$raw)
We can also compare the current version of a document to a previous version in stored in a git repository. (These examples are not run here).
If a reference_file
argument is not provided, by default the modified_file
will be compared to the most recent copy in the git repo:
result <- diff_rmd(modified_file)
Or we can compare it to how it appeared in the git repository after a particular commit (here, the commit with reference 750ab4):
result <- diff_rmd(reference_file, "750ab4")
Anyone can view annotations, but to fully use the annotation functionality and
add your own annotations an account is needed at the Hypothes.is
website. Annotations can be enabled by using the
RStudio addin Insert html annotation js snippet
. Annotations have even been
enabled for this document! It works by adding the following javascript snippet
to the bottom of your RMarkdown document:
<script src="https://hypothes.is/embed.js" async></script>
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.