hughjonesd / huxtable

An R package to create styled tables in multiple output formats, with a friendly, modern interface.
http://hughjonesd.github.io/huxtable
Other
321 stars 28 forks source link

Align Columns Not Working As Expected in Knitted Doc #95

Closed rosnertm closed 5 years ago

rosnertm commented 5 years ago

Describe the bug I've been having issues aligning columns in a huxtable in a knitted word document. I first reported this problem on StackOverflow and was asked to report it here.

I still cannot get Huxtable to work, but now the problem is a bit different. Now, everything aligns as expected in the RStudio console, but it does not translate to my Word document. For the non-reproducible example in the Stack Overflow question, everything is acting the same in the word doc ('left' and 'center' lead to center alignment; 'right' leads to right alignment.) I am also now getting this error message, which I don't recall seeing before:

In knit_print.huxtable(x, ...) : Falling back to markdown for Word document. Many features will not be supported.

With my reproducible example (below), everything works fine in the RStudio console, but all specified alignments still result in right alignment in the word doc, and I get the same error message thrown.

Note that I did not update R, RStudio, or the Huxtable package since asking my original question in Stack Overflow. In addition, adding the following in the setup options leads to identical results:

if (guess_knitr_output_format() == "docx") options(huxtable.print = print_md)

Minimal Reproducible Example

---
title: "Huxtable Test"
output: word_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = T)
knitr::opts_chunk$set(message = FALSE)
knitr::opts_chunk$set(warning = F)
library(huxtable)

data("ToothGrowth")

ht <- as_hux(table(ToothGrowth$supp, ToothGrowth$dose))
caption(ht) <- "This is a test"
ht[1,1] <- "Supplement Type" ## add proper col names
ht[1,2] <- "Dose0.5" 
ht[1,3] <- "Dose1"
ht[1,4] <- "Dose2"
align(ht)[,1] <- 'left'
ht

Expected behavior I expected the first column (Supplement Type) to be left-aligned. Instead, it is right aligned (see attached picture).

huxtable test

System details Output of packageVersion("huxtable"): 4.3.0 R version: 3.5.1 Rstudio version: 1.1.456

hughjonesd commented 5 years ago

Are you trying to print a huxtable in a Word document directly from within rmarkdown? If so, that won't work - though if you upgrade to github master, it should. With 4.3.0, you still need to use as_flextable before printing to Word. See the introduction vignette section "Output to different formats".

rosnertm commented 5 years ago

Ah, okay. Sorry for missing that! Thanks for your help.

hughjonesd commented 5 years ago

If you want to try out the GitHub version and report your experience that would be helpful! You’ll need the latest rstudio or at least a pandoc > 2.0.0 -- Sent from Gmail Mobile

rosnertm commented 5 years ago

I'll look into it! It might take a bit of time for me to get to that (the data I'm working with shouldn't be put online, so learning github is not my highest priority, though it is something I'm personally interested in.) I'll let you know here when I'm done so :) Thanks again!

hughjonesd commented 5 years ago

You just need to run

remotes::install_github(“hughjonesd/huxtable”)

No learning required. Install remotes first if you need to.

On Fri, 14 Dec 2018 at 21:42, rosnertm notifications@github.com wrote:

I'll look into it! It might take a bit of time for me to get to that (the data I'm working with shouldn't be put online, so learning github is not my highest priority, though it is something I'm personally interested in.) I'll let you know here when I'm done so :) Thanks again!

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/hughjonesd/huxtable/issues/95#issuecomment-447473851, or mute the thread https://github.com/notifications/unsubscribe-auth/AFjJ91CU7u-Gg3Zaq3ZIxriuxnzYhpQqks5u5A1SgaJpZM4ZNpRe .

-- Sent from Gmail Mobile