davidgohel / officer

:cop: officer: office documents from R
https://ardata-fr.github.io/officeverse/
Other
602 stars 107 forks source link

How to avoid printing less-than sign as &lt #333

Closed xlucpu closed 4 years ago

xlucpu commented 4 years ago

I am using officer R package to output a summarization table. In this table I have a column of P values which sometimes there are some <0.05 values there. However, the less-than sign of "<" will be printed as "&lt" in the output WORD file.

I tried replace "<" as "<" using comtable$p <- gsub("<","\\\\<",comtable$p) but it get me '\&lt' in the output file.

comtable$p <- gsub("<","\\\\<",comtable$p)
    table_subtitle <- colnames(comtable)

    title_name <- paste0("Table *. ", gsub(".txt", "", outFile, fixed = TRUE))
    mynote <- "Note: ..."

    my_doc <- officer::read_docx()
    my_doc %>%
      officer::body_add_par(value = title_name, style = "table title") %>%
      officer::body_add_table(value = comtable, style = "table_template") %>%
      officer::body_add_par(value = mynote) %>%
      print(target = file.path(res.path,paste0("TABLE ", gsub(".txt", "", outFile, fixed = TRUE), ".docx")))

Any solutions? Many thanks advanced!

davidgohel commented 4 years ago

Could you provide sessionInfo() and especially a reprex as required in the template form? Thanks

xlucpu commented 4 years ago

Below is my sessinInfo:

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936  LC_CTYPE=Chinese (Simplified)_China.936   
[3] LC_MONETARY=Chinese (Simplified)_China.936 LC_NUMERIC=C                              
[5] LC_TIME=Chinese (Simplified)_China.936    

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_1.0.2         MOVICS_0.99.1       Biobase_2.48.0      BiocGenerics_0.34.0

loaded via a namespace (and not attached):
  [1] mitools_2.4                                         graphlayouts_0.7.0                                 
  [3] GSVA_1.36.2                                         lattice_0.20-41                                    
  [5] haven_2.3.1                                         FEM_3.15.0                                         
  [7] vctrs_0.3.4                                         graphite_1.34.0                                    
  [9] fastICA_1.2-2                                       usethis_1.6.1                                      
 [11] mgcv_1.8-33                                         beanplot_1.2                                       
 [13] DSS_2.36.0                                          blob_1.2.1                                         
 [15] survival_3.2-3                                      nloptr_1.2.2.2                                     
 [17] later_1.1.0.1                                       DBI_1.1.0                                          
 [19] R.utils_2.10.1                                      rappdirs_0.3.1                                     
 [21] jstable_0.9.6                                       jpeg_0.1-8.1                                       
 [23] zlibbioc_1.34.0                                     htmlwidgets_1.5.1                                  
 [25] GlobalOptions_0.1.2                                 irlba_2.3.3                                        
 [27] tidygraph_1.2.0                                     illuminaio_0.30.0                                  
 [29] Rcpp_1.0.5                                          readr_1.3.1                                        
 [31] KernSmooth_2.23-17                                  promises_1.1.1                                     
 [33] gdata_2.18.0                                        DelayedArray_0.14.1                                
 [35] methylumi_2.34.0                                    limma_3.44.3                                       
 [37] vegan_2.5-6                                         pkgload_1.1.0                                      
 [39] graph_1.66.0                                        RcppParallel_5.0.2                                 
 [41] Hmisc_4.4-1                                         ChAMPdata_2.20.0                                   
 [43] geneLenDataBase_1.24.0                              fs_1.5.0                                           
 [45] fastmatch_1.1-0                                     digest_0.6.25                                      
 [47] png_0.1-7                                           maftools_2.4.12                                    
 [49] nor1mix_1.3-0                                       scatterpie_0.1.4                                   
 [51] cowplot_1.1.0                                       DOSE_3.14.0                                        
 [53] nleqslv_3.3.2                                       ggraph_2.0.3                                       
 [55] pkgconfig_2.0.3                                     GO.db_3.11.4                                       
 [57] gridBase_0.4-7                                      DelayedMatrixStats_1.10.1                          
 [59] minqa_1.2.4                                         iterators_1.0.12                                   
 [61] DMRcate_2.2.2                                       clusterProfiler_3.16.1                             
 [63] SummarizedExperiment_1.18.2                         circlize_0.4.10                                    
 [65] modeltools_0.2-23                                   GetoptLong_1.0.2                                   
 [67] xfun_0.16                                           zoo_1.8-8                                          
 [69] tidyselect_1.1.0                                    reshape2_1.4.4                                     
 [71] purrr_0.3.4                                         DNAcopy_1.62.0                                     
 [73] labelled_2.6.0                                      viridisLite_0.3.0                                  
 [75] rtracklayer_1.48.0                                  marray_1.66.0                                      
 [77] pkgbuild_1.1.0                                      rlang_0.4.7                                        
 [79] glue_1.4.2                                          mogsa_1.22.1                                       
 [81] ensembldb_2.12.1                                    RColorBrewer_1.1-2                                 
 [83] registry_0.5-1                                      matrixStats_0.56.0                                 
 [85] europepmc_0.4                                       stringr_1.4.0                                      
 [87] pkgmaker_0.31.1                                     sva_3.36.0                                         
 [89] ggsignif_0.6.0                                      aricode_1.0.0                                      
 [91] svd_0.5                                             DESeq2_1.28.1                                      
 [93] httpuv_1.5.4                                        class_7.3-17                                       
 [95] preprocessCore_1.50.0                               pamr_1.56.1                                        
 [97] corpcor_1.6.9                                       isva_1.9                                           
 [99] DO.db_2.9                                           annotate_1.66.0                                    
[101] bsseq_1.24.4                                        jsonlite_1.7.0                                     
[103] XVector_0.28.0                                      ROC_1.64.0                                         
[105] clusterRepro_0.9                                    bit_4.0.4                                          
[107] mime_0.9                                            gridExtra_2.3                                      
[109] gplots_3.0.4                                        Rsamtools_2.4.0                                    
[111] stringi_1.4.6                                       ConsensusClusterPlus_1.52.0                        
[113] processx_3.4.4                                      wateRmelon_1.32.0                                  
[115] survey_4.0                                          quadprog_1.5-8                                     
[117] bitops_1.0-6                                        cli_2.0.2                                          
[119] RSQLite_2.2.0                                       tidyr_1.1.2                                        
[121] data.table_1.13.0                                   ChAMP_2.18.2                                       
[123] bumphunter_1.30.0                                   survminer_0.4.8                                    
[125] officer_0.3.14                                      rstudioapi_0.11                                    
[127] git2r_0.27.1                                        GenomicAlignments_1.24.0                           
[129] nlme_3.1-149                                        qvalue_2.20.0                                      
[131] locfit_1.5-9.4                                      VariantAnnotation_1.34.0                           
[133] ridge_2.7                                           coca_1.1.0                                         
[135] gridGraphics_0.5-0                                  survMisc_0.5.5                                     
[137] R.oo_1.24.0                                         Illumina450ProbeVariants.db_1.24.0                 
[139] dbplyr_1.4.4                                        entropy_1.2.1                                      
[141] sessioninfo_1.1.1                                   readxl_1.3.1                                       
[143] lifecycle_0.2.0                                     ExperimentHub_1.14.2                               
[145] munsell_0.5.0                                       cellranger_1.1.0                                   
[147] R.methodsS3_1.8.1                                   ggalluvial_0.12.2                                  
[149] caTools_1.18.0                                      codetools_0.2-16                                   
[151] GenomeInfoDb_1.24.2                                 ClassDiscovery_3.3.12                              
[153] triebeard_0.3.0                                     htmlTable_2.0.1                                    
[155] missMethyl_1.22.0                                   xtable_1.8-4                                       
[157] ggpmisc_0.3.6                                       BiocManager_1.30.10                                
[159] abind_1.4-5                                         farver_2.0.3                                       
[161] FNN_1.1.3                                           km.ci_0.5-2                                        
[163] AnnotationHub_2.20.2                                askpass_1.1                                        
[165] biovizBase_1.36.0                                   GenomicRanges_1.40.0                               
[167] IlluminaHumanMethylationEPICanno.ilm10b4.hg19_0.6.0 bibtex_0.4.2.2                                     
[169] GEOquery_2.56.0                                     patchwork_1.0.1                                    
[171] shinythemes_1.1.2                                   tibble_3.0.3                                       
[173] dichromat_2.0-0                                     cluster_2.1.0                                      
[175] dendextend_1.14.0                                   prettyGraphs_2.1.6                                 
[177] Matrix_1.2-18                                       ellipsis_0.3.1                                     
[179] ExPosition_2.8.23                                   prettyunits_1.1.1                                  
[181] CIMLR_1.0.0                                         ggridges_0.5.2                                     
[183] goseq_1.40.0                                        mclust_5.4.6                                       
[185] igraph_1.2.5                                        multtest_2.44.0                                    
[187] minfi_1.34.0                                        fgsea_1.14.0                                       
[189] remotes_2.2.0                                       testthat_2.3.2                                     
[191] htmltools_0.5.0                                     BiocFileCache_1.12.1                               
[193] yaml_2.2.1                                          NMF_0.23.0                                         
[195] GenomicFeatures_1.40.1                              plotly_4.9.2.1                                     
[197] interactiveDisplayBase_1.26.3                       XML_3.99-0.5                                       
[199] e1071_1.7-3                                         ggpubr_0.4.0                                       
[201] foreign_0.8-80                                      withr_2.2.0                                        
[203] PINSPlus_2.0.5                                      BiocParallel_1.22.0                                
[205] bit64_4.0.5                                         BiasedUrn_1.07                                     
[207] rngtools_1.5                                        doRNG_1.8.2                                        
[209] heatmap.plus_1.3                                    affyio_1.58.0                                      
[211] foreach_1.5.0                                       ProtGenerics_1.20.0                                
[213] Biostrings_2.56.0                                   combinat_0.0-8                                     
[215] GOSemSim_2.14.2                                     devtools_2.3.1                                     
[217] memoise_1.1.0                                       evaluate_0.14                                      
[219] globaltest_5.42.0                                   geepack_1.3-1                                      
[221] coxme_2.2-16                                        forcats_0.5.0                                      
[223] rio_0.5.16                                          geneplotter_1.66.0                                 
[225] permute_0.9-5                                       callr_3.4.4                                        
[227] ps_1.3.4                                            curl_4.3                                           
[229] fansi_0.4.1                                         urltools_1.7.3                                     
[231] GSEABase_1.50.1                                     edgeR_3.30.3                                       
[233] SNFtool_2.3.0                                       checkmate_2.0.0                                    
[235] org.Hs.eg.db_3.11.4                                 desc_1.2.0                                         
[237] Gviz_1.32.0                                         iClusterPlus_1.24.0                                
[239] CMScaller_0.99.2                                    impute_1.62.0                                      
[241] ggplot2_3.3.2                                       rjson_0.2.20                                       
[243] openxlsx_4.1.5                                      ggrepel_0.8.2                                      
[245] rstatix_0.6.0                                       oompaBase_3.2.9                                    
[247] lumi_2.40.0                                         clue_0.3-57                                        
[249] rprojroot_1.3-2                                     alluvial_0.1-2                                     
[251] tools_4.0.2                                         tableone_0.12.0                                    
[253] magrittr_1.5                                        RCurl_1.98-1.2                                     
[255] car_3.0-9                                           ggplotify_0.0.5                                    
[257] xml2_1.3.2                                          httr_1.4.2                                         
[259] assertthat_0.2.1                                    rmarkdown_2.3                                      
[261] boot_1.3-25                                         R6_2.4.1                                           
[263] Rhdf5lib_1.10.1                                     AnnotationFilter_1.12.0                            
[265] nnet_7.3-14                                         progress_1.2.2                                     
[267] genefilter_1.70.0                                   gtools_3.8.2                                       
[269] shape_1.4.4                                         statmod_1.4.34                                     
[271] corrplot_0.84                                       BiocVersion_3.11.1                                 
[273] HDF5Array_1.16.1                                    rhdf5_2.32.2                                       
[275] splines_4.0.2                                       flexclust_1.4-0                                    
[277] carData_3.0-4                                       colorspace_1.4-1                                   
[279] generics_0.0.2                                      oompaData_3.1.1                                    
[281] stats4_4.0.2                                        base64enc_0.1-3                                    
[283] pillar_1.4.6                                        IlluminaHumanMethylationEPICmanifest_0.3.0         
[285] tweenr_1.0.1                                        affy_1.66.0                                        
[287] InterSIM_2.2.0                                      uuid_0.1-4                                         
[289] rvcheck_0.1.8                                       GenomeInfoDbData_1.2.3                             
[291] plyr_1.8.6                                          gtable_0.3.0                                       
[293] bdsmatrix_1.3-4                                     zip_2.1.1                                          
[295] knitr_1.29                                          ComplexHeatmap_2.5.5                               
[297] latticeExtra_0.6-29                                 biomaRt_2.44.1                                     
[299] IRanges_2.22.2                                      fastmap_1.0.1                                      
[301] doParallel_1.0.15                                   AnnotationDbi_1.50.3                               
[303] broom_0.7.0                                         openssl_1.4.2                                      
[305] BSgenome_1.56.0                                     scales_1.1.1                                       
[307] backports_1.1.9                                     S4Vectors_0.26.1                                   
[309] base64_2.0                                          kpmt_0.1.0                                         
[311] lme4_1.1-23                                         enrichplot_1.8.1                                   
[313] ggforce_0.3.2                                       hms_0.5.3                                          
[315] scrime_1.3.5                                        shiny_1.5.0                                        
[317] RPMM_1.25                                           KMsurv_0.1-5                                       
[319] polyclip_1.10-0                                     grid_4.0.2                                         
[321] siggenes_1.62.0                                     lazyeval_0.2.2                                     
[323] Formula_1.2-3                                       JADE_2.0-3                                         
[325] crayon_1.3.4                                        MASS_7.3-52                                        
[327] downloader_0.4                                      viridis_0.5.1                                      
[329] IlluminaHumanMethylation450kmanifest_0.4.0          reshape_0.8.8                                      
[331] rpart_4.1-15                                        IntNMF_1.2.0                                       
[333] compiler_4.0.2     
davidgohel commented 4 years ago

What is comtable? How can I reproduce your example?

xlucpu commented 4 years ago

Thank you for this timely reply. Actually my question is just about the less-than sign. Because in the comtable, I have a value of "<0.001" but it represents as "& lt;0.001" in the output WORD file. Therefore I think you can just make a simple example with "<" or ">" sign to see what happened in the output WORD file? Or I can sent this comtable txt file to your email if you want.

davidgohel commented 4 years ago

It is. solved now

xlucpu commented 4 years ago

Thank you so much.

github-actions[bot] commented 2 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.