Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add line breaks?

Tags:

r

officer

I'm trying to add line breaks using body_replace_all_text or body_add_par but am having no joy. Using \r\n shows correctly in OSX TextEdit, but not in Word.

An example:

library(officer)
library(tidyverse)

read_docx() %>% 
  body_add_par("Oneline\r\n\r\nAnother line") %>% 
  print(target = "example.docx")

is there a right way to do this?

like image 288
bjw Avatar asked Sep 06 '25 03:09

bjw


1 Answers

You will have to call body_add_par each time you want to add a paragraph (a paragraph of text ends with a new line):

library(officer)
library(tidyverse)

read_docx() %>% 
  body_add_par("Oneline") %>% 
  body_add_par("Another line") %>% 
  print(target = "example.docx")
like image 69
David Gohel Avatar answered Sep 10 '25 03:09

David Gohel