forked from davidgohel/officedown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
167 lines (106 loc) · 5.32 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
library(htmltools)
taghl <- function(x){
span(x, style="color:#7b1b47;")
}
```
[![Travis build status](https://travis-ci.org/davidgohel/officedown.svg?branch=master)](https://travis-ci.org/davidgohel/officedown)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/davidgohel/officedown?branch=master&svg=true)](https://ci.appveyor.com/project/davidgohel/officedown)
[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![CRAN status](https://www.r-pkg.org/badges/version/officedown)](https://cran.r-project.org/package=officedown)
> `officedown` is bringing some [officer](https://cran.r-project.org/package=officer) features into R markdown documents.
1. Pimp your R markdown documents... to produce Word documents.
The package is to be used when you want to use R Markdown documents to produce Microsoft Word
documents but also want options for landscape orientation, with narrow margins, with
formatted text, when some paragraphs have to be centered.
2. Add vector graphics into your PowerPoint document. This feature let's you add
[rvg](https://cran.r-project.org/package=rvg) in you presentation.
## Usage
use RStudio Menu to create a document from `officedown` template.
![](tools/rstudio_new_rmd.gif)
It will create an R markdown document, parameter `output` is to be set to `officedown::rdocx_document`.
Also package `officedown` need to be loaded.
`````
---
date: "`r Sys.Date()`"
author: "David Gohel"
title: "Document title"
output:
officedown::rdocx_document
---
````{r setup}
library(officedown)
````
`````
Tags have been made to make less verbose and easier use.
Some are expected parameters (i.e. `CHUNK_TEXT`, `BLOCK_MULTICOL_STOP`). These parameters
need to be defined as inline yaml.
### Chunks
Chunks are to be used in a paragraph in an R markdown document.
| Output type | Tag name | R function | Has args |
|-------------|-------------------|------------------------|----------|
| chunk | CHUNK_PAGEBREAK | chunk_page_break | no |
| chunk | CHUNK_TEXT | chunk_styled_text | yes |
| chunk | CHUNK_TEXT_STYLE | chunk_text_stylenamed | yes |
| chunk | CHUNK_COLUMNBREAK | chunk_column_break | no |
| chunk | | add_paragraph_settings | yes |
<pre>This text will be followed by a break page.`r taghl("<!---CHUNK_PAGEBREAK--->")`
<code>``r taghl("r add_paragraph_settings(align='center', paddings = list(t= 120, b= 20))")``</code>
This paragraph will be centered and wil have a 120 pts top padding and 20 bottom padding.
Text can be styles: `r taghl("<!---CHUNK_TEXT{str: 'officedown', color: 'orange'}--->")` is really cool.
</pre>
### Blocks
Blocks are to be used as a paragraph in an R markdown document.
| Output type | Tag name | R function | Has args |
|-------------|-------------------|------------------------|----------|
| block | BLOCK_TOC | block_toc | yes |
| block | BLOCK_POUR_DOCX | block_pour_docx | yes |
<pre>The following will be transformed as a table of content:
`r taghl("<!---BLOCK_TOC--->")`
And the following will pour the content of an external docx file into the produced document:
`r taghl("<!---BLOCK_POUR_DOCX{docx_file:'path/to/docx'}--->")`</pre>
### Sections blocks
Section blocks are also blocks but they need to be used in pairs:
* landscape orientation
| Tag name | R function | Has args |
|-----------------------|--------------------------|----------|
| BLOCK_LANDSCAPE_START | block_section_continuous | no |
| BLOCK_LANDSCAPE_STOP | block_section_landscape | no |
<pre>The following will be in a separated section with landscape orientation
`r taghl("<!---BLOCK_LANDSCAPE_START--->")`
Blah blah blah.
`r taghl("<!---BLOCK_LANDSCAPE_STOP--->")`</pre>
* section with columns
| Tag name | R function | Has args |
|-----------------------|--------------------------|----------|
| BLOCK_MULTICOL_START | block_section_continuous | no |
| BLOCK_MULTICOL_STOP | block_section_columns | yes |
<pre>
The following will be in a separated section with 2 columns:
`r taghl("<!---BLOCK_MULTICOL_START--->")`
Blah blah blah on column 1.
`r taghl("<!---CHUNK_COLUMNBREAK--->")`
Blah blah blah on column 2.
`r taghl("<!---BLOCK_MULTICOL_STOP{widths: [3,3], space: 0.2, sep: true}--->")`
</pre>
## Working with officedown
## Installation
You can install officedown from github with:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("davidgohel/officedown")
```
Supported formats require some minimum [pandoc](https://pandoc.org/installing.html) versions:
| R Markdown output | pandoc version | comment |
|---------------------:|:--------------:|:--------------------------------------:|
| Microsoft Word | >= 2.0 | require a recent RStudio (> june 2018) |
| Microsoft PowerPoint | >= 2.4 | require pandoc installation |