Using the officer
package in R, when working with a PowerPoint you can add text with the function ph_with_text
. However, it's not clear how to add multiple bullets of text or how to set the level of indentation. I would like to achieve the following structure:
- Question 1
- Answer 1
- Answer 2
- Question 2
- Answer 1
- Answer 2
I have tried two methods which both produce very wrong results. I have tried taking my text and adding \n
and \n\t
to create linebreaks and tabs (like how I would create the structure in PowerPoint.
doc = read_pptx()
doc = add_slide(layout = "Title and Content", master = "Office Theme")
doc = ph_with_text(doc,type = "body",
str = "Question 1\n\tAnswer 1\n\tAnswer 2\nQuestion 2\n\tAnswer 1\n\tAnswer 2",
index = 1)
This creates the bullets, but not the depth. There's a whitespace tab after each bullet before each answer. Additionally, these are not new bullets, if I manually edit the file and press tab on one bullet point, every point after is also shifted. Clearly the correct structure hasn't been acheived.
I have also tried just calling ph_with_text
repeatedly.
doc = add_slide(layout = "Title and Content", master = "Office Theme")
doc = ph_with_text(doc,type = "body", str = "Question 1", index = 1)
doc = ph_with_text(doc,type = "body", str = "Answer 1", index = 1)
doc = ph_with_text(doc,type = "body", str = "Answer 2", index = 1)
doc = ph_with_text(doc,type = "body", str = "Question 2", index = 1)
doc = ph_with_text(doc,type = "body", str = "Answer 1", index = 1)
doc = ph_with_text(doc,type = "body", str = "Answer 2", index = 1)
But this ends up overlaying the text on the same line and it's an unreadable mess.
How do I, via officer
, add text to a slide achieving multiple bullets and indented sub-elements?