Skip to content

Package recommendations for outputting table with cell formatting

8 messages · Patrick (Malone Quantitative), Dennis Fisher, Jeff Newmiller +3 more

#
R 4.0.2
OS X

Colleagues

I have the unfortunate need to create a large number of tables (destined for a Word document).  I need to color cells depending on the contents, e.g., blue if the value is < 0.5, red if the value is > 1.5.  
If the output went initially to Excel, that would work; outputting directly to Word would be even better.
I expect that several packages can accomplish this.  I am looking for recommendations as to which package (or combination) of packages is best to accomplish this.

Dennis

Dennis Fisher MD
P < (The "P Less Than" Company)
Phone / Fax: 1-866-PLessThan (1-866-753-7784)
www.PLessThan.com
#
Will this need to be done many times? If not, it might be just as easy
to apply conditional formatting to cells after they're already in
Excel.
On Fri, Oct 23, 2020 at 8:28 PM Dennis Fisher <fisher at plessthan.com> wrote:

  
    
#
Patrick

Doing this in Excel is certainly an option.  But I would like to learn how to do it in R.

Dennis

Dennis Fisher MD
P < (The "P Less Than" Company)
Phone / Fax: 1-866-PLessThan (1-866-753-7784)
www.PLessThan.com
#
I would go straight to Word using flextable (table layout) and officer (Word-specific formatting) within an rmarkdown document (e.g. bookdown:: word_document2 to manage overall structure and generate captions). Officer without rmarkdown may be able to generate true Word captions with bookmarks to cross-reference, but it is more tedious to set up than rmarkdown.
On October 23, 2020 5:28:26 PM PDT, Dennis Fisher <fisher at plessthan.com> wrote:

  
    
#
This comes with no guarantee since i have only tried one or two packages
mentioned but have a look at <a href="
https://rfortherestofus.com/2019/11/how-to-make-beautiful-tables-in-r/"> R
Tables</a>.
On Fri, 23 Oct 2020 at 20:28, Dennis Fisher <fisher at plessthan.com> wrote:

            

  
    
#
To John and everyone else,

Please add Hmisc::latex to your  how-to-make-beautiful-tables-in-r document.
We first included latex() in S in 1995, and it is still actively
maintained and improved.

Rich

Here are the first few lines of ?latex

Convert an S object to LaTeX, and Related Utilities

Description:

     ?latex? converts its argument to a ?.tex? file appropriate for
     inclusion in a LaTeX2e document.  ?latex? is a generic function
     that calls one of ?latex.default?, ?latex.function?, ?latex.list?.

     ?latex.default? does appropriate rounding and decimal alignment
     and produces a file containing a LaTeX tabular environment to
     print the matrix or data.frame ?x? as a table.

     ?latex.function? prepares an S function for printing by issuing
     ?sed? commands that are similar to those in the ?S.to.latex?
     procedure in the ?s.to.latex? package (Chambers and Hastie, 1993).
     ?latex.function? can also produce ?verbatim? output or output that
     works with the ?Sweavel? LaTeX style at <URL:
     http://biostat.mc.vanderbilt.edu/SweaveTemplate>.
On Fri, Oct 23, 2020 at 11:11 PM John Kane <jrkrideau at gmail.com> wrote:
#
That latex() function is the best thing since sliced bread, Coca Cola, etc.!

Thanks
On Fri, Oct 23, 2020 at 9:24 PM Richard M. Heiberger <rmh at temple.edu> wrote:

            
#
Blast it,  *I forgot that and I usually load Hmisc as a default.*
On Fri, 23 Oct 2020 at 23:24, Richard M. Heiberger <rmh at temple.edu> wrote: