0

I'm trying to highlight a set of words, for example word1 and word2 from an imported word document using the officer package in R. I am now stuck after setting the text properties for the word. How do I get officer to highlight the words in the colors?

I've read the data file using read_docx(filename). I've also set the text properties using fp_text() and ftext().

my_doc <- read_docx(file.path(filepath,myfile)) 

color1 <- fp_text(color = "blue", font.size = 10, bold = FALSE,
        italic = FALSE, underlined = FALSE, font.family = "Arial",
        vertical.align = "baseline", shading.color = "transparent")
ftext("word1", color1)
color2 <- fp_text(color = "red", font.size = 10, bold = FALSE,
        italic = FALSE, underlined = FALSE, font.family = "Arial",
        vertical.align = "baseline", shading.color = "transparent")
ftext("word2", color1)
David Gohel
  • 9,180
  • 2
  • 16
  • 34

1 Answers1

0

You have to set the highlight color with argument shading.color:

color1 <- fp_text(shading.color = "yellow")
David Gohel
  • 9,180
  • 2
  • 16
  • 34
  • Thanks!! Also, how would I replace my word document which I loaded in using officer with the highlighted and color texts? – Winson Yang Feb 14 '19 at 01:39