5

I am trying to write reproducible manuscripts in R using the marvelous 'bookdown2' package (as a part of the incredible rrtools package) that are sent to publishers for peer review in .docx format.

After the peer review process, there are usually corrections to be made.

Most of the journals require a marked-up version of the manuscript after introducing post-review-corrections.

Is there a way to generate word files with ' changes tracking' from within R?

I am aware that it is possible to generate two files and use Word to compare two versions. This works but is not consistent with the reproducible workflow, error prone and requires point and clicking as well as the Microsoft Word software.

There has to be a better way.

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
WojciechF
  • 370
  • 2
  • 14

2 Answers2

2

There is a very cool R package by Noam Ross. The package,redoc - Reversible Reproducible Documents, is not yet on CRAN. The development version is on github.

See: https://noamross.github.io/redoc/

user25494
  • 1,289
  • 14
  • 27
1

The following code shows a simple example of how we can compare two words files to get the tracked change :

library(RDCOMClient)

path_To_File1 <- "C:\\...\\Word File 1.docx"
path_To_File2 <- "C:\\...\\Word File 2.docx"

wordApp <- COMCreate("Word.Application")
doc1 <- wordApp[["Documents"]]$Open(normalizePath(path_To_File1))
doc2 <- wordApp[["Documents"]]$Open(normalizePath(path_To_File2))

doc3 <- wordApp[["Application"]]$CompareDocuments(OriginalDocument = doc1,
                                                  RevisedDocument = doc2)

doc3$SaveAs("C:\\...\\Word File Compared 1-2.docx")
Emmanuel Hamel
  • 1,769
  • 7
  • 19