Search code examples
rms-wordofficer

Formatted arrow inside Word document paragraph


Would like to add arrows to a Word document paragraph using officer. Used to just be able to paste those into a paragraph using body_add_par. Spell check wasn't working in the resulting document. Managed to get spell-check working. Not quite sure anymore how I did that. Perhaps one of the things I tried after doing some Internet searches. Could also be product of software updates from IT. After I got the the spell-check working, I could no longer just paste the arrows though.

Attempts to add the arrows using programming have been unsuccessful. Thinking the code might wind up looking something like below. Not sure if I even have the right function though. The first of the slip_in_seqfield works. Thought it might be the basis for a solution. The second slip_in_seqfield is modeled after the first but does not work. Neither do all the variations of it I've tried. Not sure why. Felt like it would work.

If anyone knows how to do this, I'd appreciate some help.

Thanks.

 > sessionInfo()

R version 3.6.0 (2019-04-26)

Platform: x86_64-w64-mingw32/x64 (64-bit)

Running under: Windows Server 2008 x64 (build 6003) Service Pack 2



Matrix products: default



locale:

[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252

[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252   



attached base packages:

[1] stats     graphics  grDevices utils     datasets  methods   base    



other attached packages:

[1] sessioninfo_1.1.1 flextable_0.5.4   reshape2_1.4.3    stringr_1.4.0     tibble_2.1.3      devEMF_3.6-2    

 [7] survminer_0.4.4   ggpubr_0.2        ggplot2_3.1.1     survival_2.44-1.1 dplyr_0.8.1       magrittr_1.5    

[13] officer_0.3.4   



loaded via a namespace (and not attached):

[1] zoo_1.8-6         tidyselect_0.2.5  xfun_0.7          purrr_0.3.2       splines_3.6.0     lattice_0.20-38 

 [7] colorspace_1.4-1  generics_0.0.2    htmltools_0.3.6   yaml_2.2.0        base64enc_0.1-3   survMisc_0.5.5  

[13] rlang_0.3.4       pillar_1.4.1      glue_1.3.1        withr_2.1.2       gdtools_0.1.8     uuid_0.1-2      

[19] plyr_1.8.4        munsell_0.5.0     gtable_0.3.0      zip_2.0.2         evaluate_0.14     knitr_1.23      

[25] broom_0.5.2       Rcpp_1.0.1        xtable_1.8-4      scales_1.0.0      backports_1.1.4   cmprsk_2.2-8    

[31] km.ci_0.5-2       gridExtra_2.3     digest_0.6.19     stringi_1.4.3     KMsurv_0.1-5      grid_3.6.0      

[37] cli_1.1.0         tools_3.6.0       lazyeval_0.2.2    crayon_1.3.4      tidyr_0.8.3       pkgconfig_2.0.2 

[43] Matrix_1.2-17     data.table_1.12.2 xml2_1.2.0        assertthat_0.2.1  rmarkdown_1.13    rstudioapi_0.10 

[49] R6_2.4.0          nlme_3.1-140      compiler_3.6.0  
library(officer)
library(magrittr)

read_docx() %>%
body_add_fpar(
    fpar(
      "This is a test paragraph with a proper ",
      "\u2B62",
      " (arrow).")
) %>%
slip_in_seqfield(str = "SYMBOL 100 \u005Cf Wingdings") %>%
slip_in_seqfield(str = "SYMBOL 34 \u2B62 Wingdings 3") %>%
print(target = "output.docx")

Solution

  • Since you're not adding formatting here, why not just use body_add_par:

    read_docx() %>%
        body_add_par("This is a test paragraph with a proper \u2B62 (arrow).") %>% 
        print(target = "output.docx")