2

Revised a second time!!

There is an example .rmd that comes with the officedown package and in that are chunks that show how you can use the officer package placeholder ("ph") tags within the chunk options, which is great. Here is a minimum reproducible example:

---
title: YAML Title
output: 
  officedown::rpptx_document
---

```{r echo=FALSE}
library(officedown)
```

## Slide 1 Title
```{r echo=FALSE, layout="Title and Content", ph=officer::ph_location_type(type="ftr")}
test <- data.frame(1)
test
```

The problem now is that if I try to insert a string instead of a data frame in the footer ("ftr"), then that string is instead placed in the body of the pptx slide, please see the example below.

---
title: YAML Title
output: 
  officedown::rpptx_document
---

```{r echo=FALSE}
library(officedown)
```

## Slide 1 Title
```{r echo=FALSE, layout="Title and Content", ph=officer::ph_location_type(type="ftr")}
"Some footer text"
```

And so now I'm very close but need help to get a string to appear in the footer. I tried a hack of making a single cell data frame with the string I want in that cell but that did not work either.

Thank you for reading!

Revised thanks to commenters!

I am trying to use officedown combined with the officer package to write out a footer to a slide. I thought to create a code chunk in the .Rmd with code that I know works in a .R script using officer.

Using the example code below, it successfully creates 2 slides. However, on the second slide I would like to have a footer with the text "a footer". Instead on the second slide only the title appears. Is there a way to insert a footer using officedown?

The reasons I thought it might be possible was after reading this on the officedown page: "The package also enhances PowerPoint productions with R Markdown by providing a mechanism for placing results according to the slide template contained in the PowerPoint document used as "reference_doc" " - https://davidgohel.github.io/officedown/

Thank you for taking a look and here is the revised example code.

---
title: YAML Title
output: 
  officedown::rpptx_document
---

```{r setup, include=FALSE}
library(officedown)
library(officer)
```

## Slide 1 Title
```{r echo=FALSE}
my_pres <- read_pptx()
my_pres <- add_slide(my_pres, layout = "Title and Content", master = "Office Theme")
my_pres <- ph_with(my_pres, value = "a footer", location = ph_location_type(type = "ftr"))
```
  • What do you mean by "it's not working"? – stefan Sep 11 '20 at 06:31
  • ... remove the `:` at the end of `.. rpptx_document`. – stefan Sep 11 '20 at 06:34
  • Edits made, thanks for reading @stefan! – user3693572 Sep 11 '20 at 15:57
  • 2
    Great edit. Now I understand what you are trying to achieve. However, I'm afraid that's not the way officedown works. officedown enhances the features of Rmarkdown to make docx or pptx documents. Your Rmd makes a pptx with a title slide and and a content slide. The code chunk creates a second pptx based on the default officer template and adds a slide to this pptx with a footer "a footer". Simply add print(my_pres, "test.pptx") to your code chunk and you will see what I mean. Knitting will then add two pptx files to your working dir. One from the Rmd, and one from your code chunk. – stefan Sep 11 '20 at 17:43

0 Answers0