Giter Club home page Giter Club logo

redoc's Introduction

redoc - Reversible Reproducible Documents

License: MIT Project Status: Suspended – Initial development has started, but there has not yet been a stable, usable release; work has been stopped for the time being but the author(s) intend on resuming work. Build Status AppVeyor build status codecov

redoc is a package to enable a two-way R Markdown-Microsoft Word workflow. It generates Word documents that can be de-rendered back into R Markdown, retaining edits on the Word document, including tracked changes.

redoc is not yet stable (and currently in suspended mode); its core engine and API are still subject to change. It’s been overhauled a few times already! I welcome your contributions and feedback (though it'll take a bit to get to them).

Installation

Install the redoc package with the remotes (or devtools) package:

remotes::install_github("noamross/redoc")

Note that redoc requires a recent version of Pandoc (>= 2.1.2). If you have RStudio version 1.2 or higher, you should have this by default.

Basic Usage

redoc provides an R Markdown output format, redoc(), built on top of rmarkdown::word_document(). You will typically call it via the YAML header in your R Markdown document. You have the option of highlighting the outputs (both chunk and inline) in the Word Document.

---
output:
  redoc::redoc
---

redoc() output resembles typical R Markdown Word output, but has some key differences:

  • Critic Markup edits will be converted to Word tracked changes.
  • By default, parts of the documented generated programmatically will be highlighted. (Change this with highlight_outputs = FALSE)
  • The original .Rmd and all code is stored internally in Word document for later retrieval.

Word files that have been created by redoc() can be reverted to .Rmd with the dedoc() function, even after they are edited. dedoc() will return the path of the de-rendered document.

library(redoc)
print(basename(redoc_example_docx()))
#> [1] "example.docx"
dedoc(redoc_example_docx())
#> [1] "./example.Rmd"

If the Word document has tracked changes, dedoc() will, by default, convert these to back to Critic Markup syntax. However, tracked changes are not necessary. You can view the changes between the original R Markdown file and the de-rendered one using the redoc_diff() function.

redoc_diff(redoc_example_edited_docx())

More details and features can be found in the vignettes for users and developers.

RStudio Integration

redoc has three RStudio Addins to simplify workflow when working with R Markdown documents:

  • “Render and Update” renders an R Markdown Document and the updates the text after round-tripping in to Word format and back. This helps with cleaning up small syntax differences (e.g. white space, line wrapping).
  • “Dedoc to active file” and “Dedoc to new file” de-render a file and place the contents in RStudio editor tabs, and also display a the changes from redoc_diff() in the RStudio viewer.

The package also contains a dedoc R Markdown template.

Related Work

  • officedown produces rich MS Word documents from R Markdown. We hope for more integration between these packages in the future.
  • diffobj visualizes differences between R objects and drives redoc’s diff view.

Contributing

Want have feedback or want to contribute? Great! Please take a look at the contributing guidelines before filing an issue or pull request.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

redoc's People

Contributors

brunograndephd avatar espinielli avatar henrikbengtsson avatar jaystern avatar maelle avatar noamross avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

redoc's Issues

Check pandoc version on startup, give informative message

Per #44, it would be helpful to check the version of Pandoc on package load, at least in interacctive mode. Run rmarkdown::pandoc_version(), and give an informative message if version is <2.1.2. One could also use rmarkdown::pandoc_exec() to figure out if the Pandoc version is the one bundled with RStudio, in which case the message can recommend updating RStudio.

Unknit title block

Pandoc's docx writer hard-codes writing metadata to a header block. See if we can unknit this (including when these fields are R-generated, such as with the date).

Move all capturing and wrapping to pre-knit processor

Moving all capture and wrapping to a pre-processor has some benefits. It will drop the need to use knit hooks, which reduces the interference with people building on top of the method. It also make it straightforward to explain to developers how to build on top of the approach.

It is also the appropriate place to capture additional components, such as raw LaTeX and HTML comments (and other raw HTML, specialized blocks, etc). This will allow HTML commends in worded or the \newpage` lua filter (#13).

Breaking from the legacy knitr parser would also allow things to be simpler, so easier to capture things like captions (#20).

Tables are not being rendered in output Word document

Tables are not being rendered in the output Word document when I use the redoc::redoc() format. This issue does not exist when I switch to rmarkdown::word_document() as the format. I've included below my reproducible example and session info. Let me know if you need any further information.

Using redoc

---
output: redoc::redoc
---

# Test Report

```{r, results='asis'}
knitr::kable(iris)
```

test_report.redoc.docx

Using rmarkdown

---
output: rmarkdown::word_document
---

# Test Report

```{r, results='asis'}
knitr::kable(iris)
```

test_report.rmarkdown.docx

Session Info

Click to expand
Session info ───────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.5.3 (2019-03-11)
 os       macOS Mojave 10.14.4        
 system   x86_64, darwin15.6.0        
 ui       RStudio                     
 language (EN)                        
 collate  en_CA.UTF-8                 
 ctype    en_CA.UTF-8                 
 tz       America/Vancouver           
 date     2019-05-21Packages ───────────────────────────────────────────────────────────────────────
 package     * version    date       lib source                          
 assertthat    0.2.0      2017-04-11 [2] CRAN (R 3.5.0)                  
 base64enc     0.1-3      2015-07-28 [2] CRAN (R 3.5.0)                  
 cli           1.1.0      2019-03-19 [2] CRAN (R 3.5.3)                  
 crayon        1.3.4      2017-09-16 [2] CRAN (R 3.5.0)                  
 diffobj       0.2.2.9003 2019-05-16 [1] Github (brodieG/diffobj@5c9b288)
 digest        0.6.18     2018-10-10 [2] CRAN (R 3.5.0)                  
 evaluate      0.13       2019-02-12 [2] standard (@0.13)                
 htmltools     0.3.6      2017-04-28 [2] standard (@0.3.6)               
 httr          1.4.0      2018-12-11 [2] standard (@1.4.0)               
 jsonlite      1.6        2018-12-07 [2] CRAN (R 3.5.0)                  
 knitr         1.22       2019-03-08 [2] standard (@1.22)                
 magrittr      1.5        2014-11-22 [2] CRAN (R 3.5.0)                  
 mime          0.6        2018-10-05 [2] standard (@0.6)                 
 officer       0.3.3      2019-03-01 [1] CRAN (R 3.5.2)                  
 R6            2.4.0      2019-02-14 [2] CRAN (R 3.5.2)                  
 Rcpp          1.0.0      2018-11-07 [2] CRAN (R 3.5.0)                  
 redoc       * 0.1.0.9000 2019-05-21 [1] Github (noamross/redoc@5e25471) 
 rlang         0.3.1      2019-01-08 [2] CRAN (R 3.5.2)                  
 rmarkdown     1.12       2019-03-14 [1] CRAN (R 3.5.2)                  
 rstudioapi    0.9.0      2019-01-09 [2] standard (@0.9.0)               
 sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.5.0)                  
 stringi       1.3.1      2019-02-13 [2] CRAN (R 3.5.2)                  
 uuid          0.1-2      2015-07-28 [2] CRAN (R 3.5.0)                  
 whoami        1.3.0      2019-03-19 [1] CRAN (R 3.5.2)                  
 withr         2.1.2      2018-03-15 [2] CRAN (R 3.5.0)                  
 xfun          0.5        2019-02-20 [2] standard (@0.5)                 
 xml2          1.2.0      2018-01-24 [2] CRAN (R 3.5.0)                  
 yaml          2.2.0      2018-07-25 [2] standard (@2.2.0)               
 zip           2.0.1      2019-03-11 [1] CRAN (R 3.5.2) 

Pandoc version: Version 2.7.2

RStudio version: Version 1.2.1335

dedoc default documentation

Thanks for the amazing package, Noam. I just noticed that the default for the track_changes argument in dedoc is "comments_only" but the documentation for the function states that "criticmarkup" is the default.

Additional linebreaks and second yaml header after render and update

Problem

When I render and update the rmd-file (or knit and dedoc), additional unintended linebreaks are inserted and the yaml header is inserted a second time.
In the first rendered docx, the lines stay together as a paragraph. But subsequent renders of the updated rmd of course inserts the linebreaks in the docx as well.

Files attached

The attached redoc_reprex.txt contains the initial rmd file (please rename to .rmd, github didn'support .rmd upload within this form), the redoc_reprex_after_render_and_update.txt
the malformatted file after render and update. redoc_reprex.docx
contains the result of the initial rendering.

Word Version, sessionInfo and Pandoc

MS Word 2016 (16.0.4849.1000) 64bit

R rmarkdown::pandoc_version()
[1] ‘2.7.2’

R sessionInfo()
version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C LC_TIME=German_Germany.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 rstudioapi_0.9.0 knitr_1.23 xml2_1.2.0 magrittr_1.5 uuid_0.1-2
[7] R6_2.4.0 rlang_0.3.4 stringr_1.4.0 httr_1.4.0 tools_3.5.2 packrat_0.5.0-5
[13] xfun_0.7 sessioninfo_1.1.1 cli_1.1.0 withr_2.1.2 htmltools_0.3.6 assertthat_0.2.1
[19] yaml_2.2.0 digest_0.6.19 crayon_1.3.4 zip_2.0.2 whoami_1.3.0 officer_0.3.4
[25] base64enc_0.1-3 evaluate_0.13 mime_0.6 rmarkdown_1.12 stringi_1.4.3 compiler_3.5.2
[31] diffobj_0.2.2.9003 redoc_0.1.0.9000 jsonlite_1.6

Resolving changes/comments with the CriticMarkup syntax in Rmd files (if at all supported)

Hi Noam,

This issue is related to https://twitter.com/noamross/status/1129423451234668547.

Using redoc version 0.1.0.9000 and MS Word for Mac version 16.16.10 (190512), I found no way to accept or reject changes from the CriticMarkup syntax in an Rmd file. Maybe you would like users to interact with changes in the MS Word version, resolve them there, then use redoc::dedoc() once that's all done.

If you are interested in supporting a way to resolve changes, I would imagine that some type of browser-like viewer that is similar to interfaces for resolving git conflicts would be useful (choose option A --aka left--, option B --aka right-- or make your new option C).

There's also some of this functionality already in the CriticMarkup TextMate addin (which I then modified so it would work a bit with Rmd files) at https://github.com/lcolladotor/criticmarkup.tmbundle forked from https://github.com/DivineDominion/criticmarkup.tmbundle. The accept code basically is this one: https://github.com/lcolladotor/criticmarkup.tmbundle/blob/master/Support/bin/accept_critic.rb which is a series of gsub calls. I believe that it's not 100% complete for all the CriticMarkup syntax cases. These could be RStudio addins (similar to TextMate Bundle commands) and are likely easier to code than the git conflict-like interface. Though just stating in the documentation that users should resolve changes in the MS Word version could be ok too ^^.

Best,
Leo

Session info

> library('redoc')
> options(width = 120)
> sessioninfo::session_info()
─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.6.0 (2019-04-26)
 os       macOS Mojave 10.14.4        
 system   x86_64, darwin15.6.0        
 ui       AQUA                        
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       America/New_York            
 date     2019-05-20Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version    date       lib source                             
 assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.0)                     
 base64enc     0.1-3      2015-07-28 [1] CRAN (R 3.6.0)                     
 cli           1.1.0      2019-03-19 [1] CRAN (R 3.6.0)                     
 crayon        1.3.4      2017-09-16 [1] CRAN (R 3.6.0)                     
 diffobj       0.2.2.9003 2019-05-17 [1] Github (brodieG/diffobj@5c9b288)   
 digest        0.6.18     2018-10-10 [1] CRAN (R 3.6.0)                     
 evaluate      0.13       2019-02-12 [1] CRAN (R 3.6.0)                     
 htmltools     0.3.6      2017-04-28 [1] CRAN (R 3.6.0)                     
 httr          1.4.0      2018-12-11 [1] CRAN (R 3.6.0)                     
 jsonlite      1.6        2018-12-07 [1] CRAN (R 3.6.0)                     
 knitr         1.22       2019-03-08 [1] CRAN (R 3.6.0)                     
 magrittr      1.5        2014-11-22 [1] CRAN (R 3.6.0)                     
 mime          0.6        2018-10-05 [1] CRAN (R 3.6.0)                     
 officer       0.3.4      2019-05-17 [1] Github (davidgohel/officer@c1e1a57)
 R6            2.4.0      2019-02-14 [1] CRAN (R 3.6.0)                     
 Rcpp          1.0.1      2019-03-17 [1] CRAN (R 3.6.0)                     
 redoc       * 0.1.0.9000 2019-05-17 [1] Github (noamross/redoc@5e25471)    
 rlang         0.3.4      2019-04-07 [1] CRAN (R 3.6.0)                     
 rmarkdown     1.12       2019-03-14 [1] CRAN (R 3.6.0)                     
 sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.0)                     
 stringi       1.4.3      2019-03-12 [1] CRAN (R 3.6.0)                     
 uuid          0.1-2      2015-07-28 [1] CRAN (R 3.6.0)                     
 whoami        1.3.0      2019-03-19 [1] CRAN (R 3.6.0)                     
 withr         2.1.2      2018-03-15 [1] CRAN (R 3.6.0)                     
 xfun          0.7        2019-05-14 [1] CRAN (R 3.6.0)                     
 xml2          1.2.0      2018-01-24 [1] CRAN (R 3.6.0)                     
 yaml          2.2.0      2018-07-25 [1] CRAN (R 3.6.0)                     
 zip           2.0.2      2019-05-13 [1] CRAN (R 3.6.0)                     

[1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library
> 

redoc not rendering using the reference document styles

Hi Noam,

I asked you on Twitter about how to use a reference DOCX file to change the formatting of a redoc document. I figured it was the same providing a reference_docx to a standard R Markdown with output as word_document; and you confirmed this to be the case and asked that I file an issue if it didn't work.

Here is the basics of what I did:

- Open RStudio
- File >> New File >> R Markdown... >> From Template >> redoc

With the following YAML header:

---
title: Reversible R Markdown Document
subtitle: Your subtitle
author: Your Name
date: Created `r Sys.Date()`
output:
  redoc::redoc:
    reference_docx: /path/to/file/ref-style-serif.docx
---

I have attached the reference file here (ref-style-serif.docx), if that helps. In the same session, I verified that I can pass the reference doc to a standard word_document format R Markdown file and it does indeed render using the reference format. So it seems like something specific to redoc. The reference document I am providing was created using the recommended approach (i.e. get a template word document from pandoc and modify the style as preferred.

Session Info
R version 3.5.3 (2019-03-11)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.4

Pandoc version (get with rmarkdown::pandoc_version):

rmarkdown::pandoc_version()
[1] ‘2.7.2’

RStudio version (if applicable): Version 1.2.1335

Capture comments in code-generated sections when de-rendering

Hi Noam,

This issue is related to https://twitter.com/noamross/status/1129423451234668547.

Using redoc version 0.1.0.9000 and MS Word for Mac version 16.16.10 (190512), comments on the word and code in the MS Word version do not get read in by redoc::dedoc( track_changes = 'criticmarkup', overwrite = TRUE).

Knowing this, a user can then manually check for missing comments in the code and pictures from the MS Word version and make the changes they want in the Rmd file. So, without adding any new code, this manual work around would work. Although if you think that this can be introduced in the code in the future, that would be great.

Best,
Leo

Session info

> library('redoc')
> options(width = 120)
> sessioninfo::session_info()
─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.6.0 (2019-04-26)
 os       macOS Mojave 10.14.4        
 system   x86_64, darwin15.6.0        
 ui       AQUA                        
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       America/New_York            
 date     2019-05-20Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version    date       lib source                             
 assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.0)                     
 base64enc     0.1-3      2015-07-28 [1] CRAN (R 3.6.0)                     
 cli           1.1.0      2019-03-19 [1] CRAN (R 3.6.0)                     
 crayon        1.3.4      2017-09-16 [1] CRAN (R 3.6.0)                     
 diffobj       0.2.2.9003 2019-05-17 [1] Github (brodieG/diffobj@5c9b288)   
 digest        0.6.18     2018-10-10 [1] CRAN (R 3.6.0)                     
 evaluate      0.13       2019-02-12 [1] CRAN (R 3.6.0)                     
 htmltools     0.3.6      2017-04-28 [1] CRAN (R 3.6.0)                     
 httr          1.4.0      2018-12-11 [1] CRAN (R 3.6.0)                     
 jsonlite      1.6        2018-12-07 [1] CRAN (R 3.6.0)                     
 knitr         1.22       2019-03-08 [1] CRAN (R 3.6.0)                     
 magrittr      1.5        2014-11-22 [1] CRAN (R 3.6.0)                     
 mime          0.6        2018-10-05 [1] CRAN (R 3.6.0)                     
 officer       0.3.4      2019-05-17 [1] Github (davidgohel/officer@c1e1a57)
 R6            2.4.0      2019-02-14 [1] CRAN (R 3.6.0)                     
 Rcpp          1.0.1      2019-03-17 [1] CRAN (R 3.6.0)                     
 redoc       * 0.1.0.9000 2019-05-17 [1] Github (noamross/redoc@5e25471)    
 rlang         0.3.4      2019-04-07 [1] CRAN (R 3.6.0)                     
 rmarkdown     1.12       2019-03-14 [1] CRAN (R 3.6.0)                     
 sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.0)                     
 stringi       1.4.3      2019-03-12 [1] CRAN (R 3.6.0)                     
 uuid          0.1-2      2015-07-28 [1] CRAN (R 3.6.0)                     
 whoami        1.3.0      2019-03-19 [1] CRAN (R 3.6.0)                     
 withr         2.1.2      2018-03-15 [1] CRAN (R 3.6.0)                     
 xfun          0.7        2019-05-14 [1] CRAN (R 3.6.0)                     
 xml2          1.2.0      2018-01-24 [1] CRAN (R 3.6.0)                     
 yaml          2.2.0      2018-07-25 [1] CRAN (R 3.6.0)                     
 zip           2.0.2      2019-05-13 [1] CRAN (R 3.6.0)                     

[1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library
> 

Should `highlight_outputs` be TRUE or FALSE by default?

The highlight_outputs argument in redoc() colors parts of the output document that are generated by code. The purpose of this is to signal to collaborators what parts of the document aren't super helpful to edit by hand. However, I'm not sure that I like the way that it looks - it looks odd when interacting with code highlighting and doesn't look right with images. Also, it could confuse collaborators - part of redoc's design philosophy is to minimize cognitive overhead for those editing on the Word side.

Should I change the default for highlight_outputs to FALSE? Or is there some other approach?

I note there may be some ways to lock parts of the word document from editing in the future, but only for chunk-type outputs, not inline text. It will be some time before I get to this, though, if ever.

Embedded data does not survive editing in Libreoffice

If I try to undoc a docx file created from an Rmd with redoc but edited in Libreoffice I get an error:

Error in undoc("manuscript/manuscript.docx") :
Document is not reversible and no alternate data provided via
orig_chunkfile or orig_docx

Maybe a note about this incompatibility could be added to the Details section of undoc?

Capture diagnostic info inside word doc

The chunkfile, or and additional file, should capture diagnostic information.

This should include:

  • sessioninfo::sessioninfo()
  • rmarkdown::pandoc_version() (Are there other system dependencies in the stack?
  • if available, rstudioapi::getVersion()

Anything else?

Thinking of moving the chunkfile to YAML so this could be appended at the end easily. This should be available to turn off for security reasons.

It might be helpful to extract similar information from the word doc itself, like the version of word last edited with.

Google Docs Support

Google Docs support would be great for this, but there are a lot of things that need to happen before that's possible. Here I outline these in case people are interested in helping take this on.

redoc relies on two major tools for working with Word documents. Pandoc does two-way conversion between markdown and docx, with support for custom scripting in the conversion. officer is an R package that supports direct manipulation of docx files. There are not yet equivalent tools for Google Docs, but they can be created.

Google recently released an API for Google Docs that includes a JSON representation of the documents themselves and mechanisms for manipulating them. First, someone needs to create custom or Haskell-native readers and writers for Pandoc to translate this JSON structure. This will allow for general markdown-gdoc conversion.

Next, we need some general tooling for the Google Docs API, along similar lines as the googledocs or googlesheets packages.

Next, we will need to figure out the right mechanism for storing the extra data (a copy of the original .Rmd and the YAML file containing code pieces) in or along the google document. Simply storing them elsewhere in the Google Drive is possible, but it would be best if there is a field in the JSON structure of the document where we can stash these to make the "re-gdoc" portable.

Finally, we need to come up with the scheme for annotating code sections to match them against chunks of stored code. For Word, we do this with custom hidden styles. With Google Docs, I think we can use Named Ranges.

Quotes in YAML need to be escaped somehow

@rmflight this relates to your problem in #41

When rendering a document with R code in YAML with quotes like this, rendering YAML fails with the warning pandoc warning [WARNING] Could not parse YAML metadata :

---
date: "`r Sys.Date()`"
output: 
  redoc::redoc
---

This works if the YAML if placed in single quotes:

---
date: '`r Sys.Date()`'
output: 
  redoc::redoc
---

This is because, prior to knitting, redoc wraps R code in tags that include a quoted class. If you render the document with clean=FALSE, the pre-processed file will look like this:

---
date: "<span class="redoc" id="redoc-inlinecode-1">`r Sys.Date()`</span>"
output: 
  redoc::redoc
---

Currently working on a solution. I previously used pandoc-style native spans, which look like this, but switched to HTML style because something was conflicting with those:

[`r Sys.Date()`]{.redoc #redoc-inlineccode-1}

The yaml package always defaults to writing single quotes, so maybe I should always re-write header YAML as single quotes to avoid this? In any case, using single quotes will temporarily solve the issue.

cannot successfully load package

Hi,
I tried downloading and loading redoc from your github and the library won't load.
Here is the code i entered and output. Do I have to update all of the packages in order for this to work? I'm just hesitant to do so.

> remotes::install_github("noamross/redoc")
Downloading GitHub repo noamross/redoc@master
These packages have more recent versions available.
Which would you like to update?

 1:   assertthat (0.2.0  -> 0.2.1 ) [CRAN]   2:   digest     (0.6.18 -> 0.6.19) [CRAN]
 3:   highr      (0.7    -> 0.8   ) [CRAN]   4:   knitr      (1.22   -> 1.23  ) [CRAN]
 5:   openssl    (1.2.1  -> 1.3   ) [CRAN]   6:   rmarkdown  (1.11   -> 1.13  ) [CRAN]
 7:   sys        (1.6    -> 3.2   ) [CRAN]   8:   tinytex    (0.10   -> 0.13  ) [CRAN]
 9:   xfun       (0.5    -> 0.7   ) [CRAN]  10:   zip        (1.0.0  -> 2.0.2 ) [CRAN]
11:   CRAN packages only                    12:   All                                 
13:   None                                  
Enter one or more numbers separated by spaces, or an empty line to cancel
1: 13
Downloading GitHub repo davidgohel/officer@master
These packages have more recent versions available.
Which would you like to update?

1:   digest (0.6.18 -> 0.6.19) [CRAN]
2:   zip    (1.0.0  -> 2.0.2 ) [CRAN]
3:   CRAN packages only
4:   All
5:   None

Enter one or more numbers separated by spaces, or an empty line to cancel
1: 3
digest (0.6.18 -> 0.6.19) [CRAN]
zip    (1.0.0  -> 2.0.2 ) [CRAN]
Installing 2 packages: digest, zip
trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.5/digest_0.6.19.tgz'
Content type 'application/x-gzip' length 212339 bytes (207 KB)
==================================================
downloaded 207 KB

trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.5/zip_2.0.2.tgz'
Content type 'application/x-gzip' length 195279 bytes (190 KB)
==================================================
downloaded 190 KB


The downloaded binary packages are in
	/var/folders/1s/xccvxp5921b4b92jlx1kp27w0000gn/T//RtmppCCD0x/downloaded_packages
✔  checking for file ‘/private/var/folders/1s/xccvxp5921b4b92jlx1kp27w0000gn/T/RtmppCCD0x/remotes3ff75b73a7b0/davidgohel-officer-c1e1a57/DESCRIPTION’ ...
─  preparing ‘officer’:
✔  checking DESCRIPTION meta-information ...
─  cleaning src
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building ‘officer_0.3.4.tar.gz’
   
* installing *source* package ‘officer’ ...
** libs
clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c border.cpp -o border.o
clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c color_spec.cpp -o color_spec.o
clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c ml_data_frame.cpp -o ml_data_frame.o
clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c ppr.cpp -o ppr.o
clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c rpr.cpp -o rpr.o
clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c talk_ppr.cpp -o talk_ppr.o
clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c talk_rpr.cpp -o talk_rpr.o
clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c talk_tcpr.cpp -o talk_tcpr.o
clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c tcpr.cpp -o tcpr.o
clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o officer.so RcppExports.o border.o color_spec.o ml_data_frame.o ppr.o rpr.o talk_ppr.o talk_rpr.o talk_tcpr.o tcpr.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/3.5/Resources/library/officer/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (officer)
Downloading GitHub repo brodieG/diffobj@development
✔  checking for file ‘/private/var/folders/1s/xccvxp5921b4b92jlx1kp27w0000gn/T/RtmppCCD0x/remotes3ff768118ed/brodieG-diffobj-5c9b288/DESCRIPTION’ ...
─  preparing ‘diffobj’:
✔  checking DESCRIPTION meta-information ...
─  cleaning src
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building ‘diffobj_0.2.2.9003.tar.gz’
   
* installing *source* package ‘diffobj’ ...
** libs
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c diff.c -o diff.o
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c diffobj.c -o diffobj.o
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c init.c -o init.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o diffobj.so diff.o diffobj.o init.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/3.5/Resources/library/diffobj/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (diffobj)
✔  checking for file ‘/private/var/folders/1s/xccvxp5921b4b92jlx1kp27w0000gn/T/RtmppCCD0x/remotes3ff73a79863e/noamross-redoc-d6fbcfa/DESCRIPTION’ ...
─  preparing ‘redoc’:
✔  checking DESCRIPTION meta-information ...
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building ‘redoc_0.1.0.9000.tar.gz’
   
* installing *source* package ‘redoc’ ...
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (redoc)
> library(redoc)

Support of other formats: papaja, rdocx_document, word_document2

There should be a way to use redoc with other formats based off of rmarkdown::word_document, such as those in the papaja, officedown, and bookdown packages. I see three possibilities:

  1. We make versions of these output formats in the redoc package. This is the easiest to control, but they will rely on internal functions from those other packages, which will require those packages to be changed to export functions.

  2. Make changes to those other packages to base their formats on redoc::redoc. Easiest for me, as others need to do it! I could write a vignette on how to develop an output format using redoc. Essentially one just needs to be careful about ordering to ensure no clashes between various pre- and post-processors, and then write appropriate code-capture wrappers if one needs them for new markup. We could PR these into those packages, of course.

  3. Write a wrapper function, like redoc_render(), which renders and word-based format as a redoc. This would be convenient but is the most fragile approach, I think, and it would break things like the RStudio "knit" button and other code based on the rmarkdown::render() function.

Thoughts, @davidgohel, @yihui, @crsh?

Formatting changes aren't captured as track changes

For formatting supported by pandoc markdown (bold/italic/underline), changes in formatting in the word document aren't captured as tracked changes. Pandoc only captures insertions, deletions, and moves. If this were to be supported, some options:

  • PR into pandoc to capture these options. Insert/delete formatting text, or maybe treat as replacing the whole line.
  • Pre-process word XML to convert some types of formatting changes to insertions/deletions
  • Find these changes after in markdown via diffing
  • Skip and leave this to diff-based workflows

Add handling of page breaks

redoc does not currently render page breaks when converting to word such that the \newpage latex command is ignored when creating the rdocx output.

It would be helpful to implement a filter as per (https://stackoverflow.com/a/49415018/9449563) to add page breaks created using \newpage to the .docx output (and ideally to convert page breaks added in word back to \newpage

Re-insert non-header YAML blocks into locations in Rmd body

Use knitr document hook to wrap YAML blocks in divs for placement, put ones with deleted placeholders (in order) at end of doc


redoc/R/extract.R

Lines 167 to 172 in 438fa10

# TODO: Re-insert non-header YAML blocks into locations in Rmd body
# BODY: Use knitr document hook to wrap YAML blocks in divs for placement, put ones with deleted placeholders (in order) at end of doc
prepend_yaml <- function(md_lines, chunk_df) {
chunk_df <- chunk_df[chunk_df$label == "yaml-header", ]
if (nrow(chunk_df)) {
md_lines <- c(chunk_df$code, "", md_lines)


This issue was generated by todo based on a TODO comment in 438fa10.

move empty chunk handler to a lua filter to make more general

# TODO: move empty chunk handler to a lua filter to make more general
paste0("```{=openxml}\n<w:p><w:pPr><w:pStyle w:val=\"chunk-",
options$label,
"\"/><w:rPr><w:vanish/></w:rPr></w:pPr></w:p>\n```")
} else {
paste0("::: {custom-style=\"chunk-", options$label, "\"}\n",


This issue was generated by todo based on a TODO comment in 12a7884. It's been assigned to @noamross because they committed the code.

Problem with bookdown::markdown_document2(base_format=redoc::redoc)

Cross-reference for Table 1 is broken for the following output. Please address this issue.

Broken Results

Table <span class=“redoc” id=“redoc-citation-1”>@ref(tab:iris)

Reproducible Code

---
output: 
  bookdown::markdown_document2:
    base_format: redoc::redoc
---

Table \@ref(tab:iris)

```{r iris}
knitr::kable(head(iris), caption = "iris")
```

Table \@ref(tab:mtcars)

```{r mtcars}
knitr::kable(head(mtcars), caption = "mtcars")
```

Figure \@ref(fig:histogram)

```{r histogram, fig.cap="Histogram of Ozone."}
hist(airquality$Ozone, col="blue")
```

how to set highlight_outputs = FALSE in YAML header?

For a given header, how can one set the option for highlight_outputs = FALSE in the YAML itself?

title: "My Title"
author: "Robert M Flight, Joshua M Mitchell, Hunter NB Moseley"
date: "2019-08-21"
output: 
  redoc::redoc:
    highlight_outputs: FALSE

Doesn't seem to work.

Convenience function to extract comments

Request from @cmzambranat, related to but a bit different from #10: A function to extract all the comments from a Word doc as a separate file.

Probably as simple as extract_comments(), with a similar RStudio add-in to the others that allows you to select the file and send to a new text file. Default would be to write a markdown document for these but an underlying function could return an R list structure for other processing. Metadata/title block can reflect the filename and date of extract

Will need to see how nested/reply comments work.

Protect empty spans via lua filter

The protect-empty-div.lua filter replaces empty divs with word OOXML that is invisible but retained in the word document. It looks like this is needed for empty spans, especially if we implement #21.

Not compatible with Chinese

I, as a MS Word user, appreciate this change tracking function from redoc so very much! However, recently, I encountered troubles when writing articles with redoc in Chinese. I attached a demo file based on a simplified version of Yihui's ctex template in rticle. The file can be compiled by word_document but not redoc.
test.zip

The error message was

processing file: test.preprocessed.Rmd
Quitting from lines 2-19 (test.preprocessed.Rmd) 
Error in nchar(input) : invalid multibyte string, element 1
Calls: <Anonymous> ... process_group.inline -> call_inline -> in_dir -> inline_exec
In addition: Warning messages:
1: In readChar(x, file.info(x)$size) :
  can only read in bytes in a non-UTF-8 MBCS locale
2: In knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet,  :
  The file "test.preprocessed.Rmd" must be encoded in UTF-8. Please see https://yihui.name/en/2018/11/biggest-regret-knitr/ for more info.
Execution halted

I'm using MS Word 2019 and here's the session info and, yes, I already set the default encoding as UTF-8 and tried to switch Sys.setlocale() to Chinese and English. Nothing helps.

R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936 
[2] LC_CTYPE=Chinese (Simplified)_China.936   
[3] LC_MONETARY=Chinese (Simplified)_China.936
[4] LC_NUMERIC=C                              
[5] LC_TIME=Chinese (Simplified)_China.936    

attached base packages:
[1] stats     graphics  grDevices utils     datasets 
[6] methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3             whoami_1.3.0          
 [3] digest_0.6.23          crayon_1.3.4          
 [5] mime_0.7               R6_2.4.1              
 [7] jsonlite_1.6           magrittr_1.5          
 [9] evaluate_0.14          httr_1.4.1            
[11] zip_2.0.4              stringi_1.4.3         
[13] rlang_0.4.2            uuid_0.1-2            
[15] diffobj_0.2.3          rstudioapi_0.10.0-9003
[17] xml2_1.2.2             rmarkdown_1.18        
[19] tools_3.6.1            officer_0.3.6         
[21] xfun_0.11              yaml_2.2.0            
[23] compiler_3.6.1         base64enc_0.1-3       
[25] htmltools_0.4.0        knitr_1.26            
[27] redoc_0.1.0.9000      

Cross-references using bookdown::word_document2

As far as I know, currently redoc::redoc utilizes rmarkdown::word_document under the hood. Would you mind replacing it with bookdown::word_document2 to allow users to cross-reference tables, figures, etc.?

Capture changes to figure captions

  • Use a knit figure hook to wrap fig.cap caption text and assign it a span with caption and the chunk name.
  • Pre-extract captions from the document after conversion to markdown
  • Re-insert them into the chunk options.
  • This requires extracting the chunk options as a list, rather than just the header

Unknown extension: styles

Hi,

Thank you for this package. It is a bit hard to offer a MWE, as I am testing it under linux (specifically Clearlinux). Installation of the package happens without errors, however it hangs expecting an extension. The standard Rmd file below:

---
title: "R Notebook"
output: redoc::redoc
---

This is an [R Markdown](http://rmarkdown.rstudio.com) Notebook. When you execute code within the notebook, the results appear beneath the code. 

Try executing this chunk by clicking the *Run* button within the chunk or by placing your cursor inside it and pressing *Ctrl+Shift+Enter*. 

```{r}
plot(cars)
```

Add a new chunk by clicking the *Insert Chunk* button on the toolbar or by pressing *Ctrl+Alt+I*.

When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the *Preview* button or press *Ctrl+Shift+K* to preview the HTML file).

The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike *Knit*, *Preview* does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.

Results in the error:

/usr/bin/pandoc +RTS -K512m -RTS teste.utf8.md --to docx+empty_paragraphs --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash+smart+fenced_divs+bracketed_spans --output teste.docx --highlight-style tango --lua-filter /home/luis/R/x86_64-generic-linux-gnu-library/3.6/redoc/lua-filters/protect-empty.lua --eol=lf 
output file: teste.knit.md

Unknown extension: styles
Erro: pandoc document conversion failed with error 1

It seems the lua filter is looking for an extension, and pandoc stops with error. The docx file is created, but I cannot convert it back to Rmd using dedoc (attached).

  • How can I help debug this?

Session Info
R version 3.6.0 (2019-04-26)
Platform: x86_64-generic-linux-gnu (64-bit)
Running under: Clear Linux OS

Matrix products: default
BLAS/LAPACK: /usr/lib64/haswell/libopenblas_haswellp-r0.3.6.so

locale:
 [1] LC_CTYPE=pt_BR.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=pt_BR.UTF-8        LC_COLLATE=pt_BR.UTF-8    
 [5] LC_MONETARY=pt_BR.UTF-8    LC_MESSAGES=pt_BR.UTF-8   
 [7] LC_PAPER=pt_BR.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=pt_BR.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets 
[6] methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1       rstudioapi_0.10  knitr_1.23      
 [4] xml2_1.2.0       magrittr_1.5     uuid_0.1-2      
 [7] R6_2.4.0         rlang_0.4.0      httr_1.4.0      
[10] tools_3.6.0      xfun_0.8         htmltools_0.3.6 
[13] yaml_2.2.0       digest_0.6.19    crayon_1.3.4    
[16] zip_2.0.2        whoami_1.3.0     officer_0.3.5   
[19] base64enc_0.1-3  evaluate_0.14    mime_0.7        
[22] rmarkdown_1.13   stringi_1.4.3    compiler_3.6.0  
[25] diffobj_0.2.3    redoc_0.1.0.9000 jsonlite_1.6    

Pandoc version 2.1.1

RStudio version 99.9

teste.docx

Inline headings

It would be a nice feature to be able to create inline headings - that is, headers below a certain level (say 3), appear at the start of the next paragraph rather than having their own line. I believe this is APA style and is doable in word styles.

This might migrate to officedown or elsewhere, depending on how de-rendering these works.

Flextables output doesn't appear without chunk option echo = TRUE

flextable() output appears to only show up in resulting .docx outputs if the chunk option is set to echo = TRUE. This is problematic for any sort of writing projects where the code needs to be hidden (e.g., scientific manuscripts). The same code renders acceptably using word_document. The flextable package is extremely useful for use with .docx outputs/collaborators and plays nice with the captioner package for cross-referencing in lieu of using bookdown::word_document2, so would be wonderful if supported (it may be supported already and I am just missing something).

Rmarkdown code

---
title: "Testing flextable behavior in redoc"
output:
  redoc::redoc: default
  word_document: default
---

`​``{r setup​}
library(flextable)
```

## Test

The following table won't show up in redoc:

```{r echoF, echo=FALSE}
flextable(head(cars))
```

But the next table will:

```{r echoT, echo=TRUE}
flextable(tail(cars))
```

Output

rendered_redoc.docx
rendered_word_document.docx

Please take a moment and consider if the issue is actually in knitr,
rmarkdown, officer or pandoc. Thanks!
-->


Session Info
R version 3.6.0 (2019-04-26)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/atlas-base/atlas/libblas.so.3.0
LAPACK: /usr/lib/atlas-base/atlas/liblapack.so.3.0

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C          
 [3] LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8    
 [5] LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
 [7] LC_PAPER=C.UTF-8       LC_NAME=C             
 [9] LC_ADDRESS=C           LC_TELEPHONE=C        
[11] LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

attached base packages:
[1] stats     graphics  grDevices utils     datasets 
[6] methods   base     

loaded via a namespace (and not attached):
 [1] zip_2.0.4         Rcpp_1.0.3        compiler_3.6.0   
 [4] base64enc_0.1-3   prettyunits_1.0.2 redoc_0.1.0.9000 
 [7] remotes_2.1.0     tools_3.6.0       uuid_0.1-2       
[10] testthat_2.3.1    digest_0.6.23     pkgbuild_1.0.6   
[13] pkgload_1.0.2     jsonlite_1.6      evaluate_0.14    
[16] memoise_1.1.0     rlang_0.4.2       whoami_1.3.0     
[19] cli_2.0.0         rstudioapi_0.10   diffobj_0.2.3    
[22] curl_4.3          yaml_2.2.0        xfun_0.11        
[25] httr_1.4.1        officer_0.3.6     withr_2.1.2      
[28] knitr_1.26        xml2_1.2.2        desc_1.2.0       
[31] fs_1.3.1          devtools_2.2.1    rprojroot_1.3-2  
[34] glue_1.3.1        R6_2.4.1          processx_3.4.1   
[37] fansi_0.4.0       rmarkdown_2.0     sessioninfo_1.1.1
[40] callr_3.4.0       magrittr_1.5      backports_1.1.5  
[43] ps_1.3.0          ellipsis_0.3.0    htmltools_0.4.0  
[46] usethis_1.5.1     assertthat_0.2.1  mime_0.8         
[49] stringi_1.4.3     crayon_1.3.4  

Pandoc version (get with rmarkdown::pandoc_version): 2.3.1

RStudio version (if applicable): Test on RStudio Cloud and on RStudio V 1.2.1335

Import non-redoc docx files.

A convenience wrapper for converting non-redoc files will probably be useful. It can go beyond pandoc_convert() and do some things like setting up the YAML headers.

One possibility is that undoc() does this anyway with a warning/message.

Convert file diffs to track changes

Using something like wdiff, git diff --word-diff, or maybe post-processing of diffObj representation, see if we can convert markdown diffs to criticmarkup or pandoc track changes format so file diffs can be converted to Word track changes.

Make yaml parser parse all yaml blocks, not just front matter

redoc/R/parser.R

Lines 221 to 226 in 12a7884

# TODO Make yaml parser yaml blocks, not just front matter
validate_front_matter <- function(delimiters) {
if (length(delimiters) >= 2 &&
(delimiters[2] - delimiters[1] > 1) &&
grepl("^---\\s*$", input_lines[delimiters[1]])) {
# verify that it's truly front matter (not preceded by other content)


This issue was generated by todo based on a TODO comment in 12a7884. It's been assigned to @noamross because they committed the code.

Set line wrap behavior in `options()` so it applied to RStudio Add-ins

When I use redoc, unwanted line breaks are inserted that break up paragraphs in seemingly arbitrary ways for my new Rmarkdown document.

Here is what I do: In Rstudio I use File -> New File -> R Markdown and then select the redoc template. Before rendering this file using the knit button (knit to redoc) in R Studio, I add a paragraph of lorem ipsum text. This lorem ipsum paragraph is only on line 24 before rendering. Here is the file that I have before rendering to word:
example.txt

After rendering the file I use the redoc add-in in Rstudio "dedoc to new file" which produces the following file exampleDeDoc.txt

In the second file, you can see that the loerm ipsum text now spans lines 24-29 because, that is, unwanted line breaks have been inserted.

Please take a moment and consider if the issue is actually in knitr,
rmarkdown, officer or pandoc. Thanks!
-->


Session Info
R version 3.5.3 (2019-03-11)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1         rstudioapi_0.10    knitr_1.23        
 [4] xml2_1.2.0         magrittr_1.5       uuid_0.1-2        
 [7] R6_2.4.0           rlang_0.3.4        httr_1.4.0        
[10] tools_3.5.3        xfun_0.6.3         htmltools_0.3.6   
[13] yaml_2.2.0         digest_0.6.19      crayon_1.3.4      
[16] zip_2.0.1          whoami_1.3.0       officer_0.3.4     
[19] base64enc_0.1-3    evaluate_0.14      mime_0.6          
[22] rmarkdown_1.12     stringi_1.4.3      compiler_3.5.3    
[25] diffobj_0.2.2.9003 redoc_0.1.0.9000   jsonlite_1.6 

Pandoc version (get with rmarkdown::pandoc_version): 2.5

RStudio version (if applicable): Version 1.2.1335

Error in word_document when called by roundtrip_active_file

This is my first time trying to use the package, I just installed it from GitHub today.

I'm calling it with the RStudio Addin "Render and Update" and I get the following error:

redoc:::roundtrip_active_file()
# Error in word_document(...) : unused argument (roundtrip = TRUE)

I updated from rmarkdown 1.16 to the latest sources on GitHub and still get the error.

I'm not sure if this is the right way to first render a document. If not, I'd be grateful for instructions!


Session Info
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2       rstudioapi_0.10  knitr_1.25       xml2_1.2.2       magrittr_1.5     uuid_0.1-2      
 [7] R6_2.4.0         rlang_0.4.0      httr_1.4.1       tools_3.6.1      packrat_0.4.8-1  xfun_0.10       
[13] htmltools_0.3.6  yaml_2.2.0       digest_0.6.21    crayon_1.3.4     zip_2.0.4        whoami_1.3.0    
[19] officer_0.3.5    base64enc_0.1-3  evaluate_0.14    mime_0.7         rmarkdown_1.16.1 stringi_1.4.3   
[25] compiler_3.6.1   diffobj_0.2.3    redoc_0.1.0.9000 jsonlite_1.6    

Pandoc version (get with rmarkdown::pandoc_version): 2.6

RStudio version (if applicable): 1.2.5001

Setting and extracting document features

I'd like to be able to set some major features in the YAML header: margins, line numbering, spacing, font family and size. Note that the last three aren't document-level features but in common use hold across the document. They should be able to set by modifying the main style.

Similarly, it would be great to extract this information from the document and then insert it into the YAML header (possibly as a tracked change). This can be challenging as these aren't always set where you want them. We can extract margins and line numbering from the body-level section characteristics. For font/spacing features, most people don't set styles, but just select all the document text and make changes, resulting in lots of small style changes. To get these, we'll have to guess by calculating the dominant style, as a fraction of paragraphs/text runs in the document.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.