flextable

alignment of a flextable on the page when rendering R Markdown to MS Word

你说的曾经没有我的故事 提交于 2020-06-27 13:08:59
问题 I've been having great luck with customizing flextable tables in my R Markdown documents. However, I am struggling to change the location of a table on the page. It seems the tables are centered on the page by default. I'd like one of my tables aligned to the left margin. How do I do that? 回答1: I have just added an option to enable that. Now you can use chunk option ft.align --- output: word_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = FALSE) ``` ```{r ft.align="left"

Table Cross-References in Bookdown with MS-Word Output?

大憨熊 提交于 2020-03-18 06:30:09
问题 How can I make table cross-references work in a bookdown document with all of the output formats pdf, docx, and html? Or maybe more specifically, how can I get table cross-references working for flextables ? Below is a minimal working example. The second table, using kable() , gets me almost all the way there. The problem is that the table rendering in docx output is completely unusable (not in this MWE, but in my actual use-case). I considered creating the table conditionally, using

R flextable conditional formatting based on pairs of rows

偶尔善良 提交于 2020-01-16 09:01:19
问题 I am trying to change the bg color of some cells in a flextable based on whether the values in the rows labeled Act (for actual) exceed the values in the corresponding rows (that is, same KPI ) labeled Plan . Those that exceed should get a green background, while those values that are below Plan should get a red background. (In a perfect world, I would be able to change the background color whether the cell was greater than or less than, depending upon a list I configured to say which

Using flextable in r markdown loop not producing tables

女生的网名这么多〃 提交于 2020-01-14 18:57:12
问题 I have many tables to create and am trying to create them in a loop. I'm using flextable with rmarkdown inside rstudio. Using print(theFlextable) command in a loop produces a list of text rather than the table. This happens for docx and html output types. If I don't use a loop flextable renders correctly. Here is a demo: --- title: "Demo" output: word_document --- ```{r setup, include=FALSE} library(flextable) ``` ## This Works ```{r iris, echo=F, message=F, error=F, results='asis'} ft<

Using flextable in r markdown loop not producing tables

牧云@^-^@ 提交于 2020-01-14 18:55:10
问题 I have many tables to create and am trying to create them in a loop. I'm using flextable with rmarkdown inside rstudio. Using print(theFlextable) command in a loop produces a list of text rather than the table. This happens for docx and html output types. If I don't use a loop flextable renders correctly. Here is a demo: --- title: "Demo" output: word_document --- ```{r setup, include=FALSE} library(flextable) ``` ## This Works ```{r iris, echo=F, message=F, error=F, results='asis'} ft<

In nested data frame, pass information from one list column to function applied in another

会有一股神秘感。 提交于 2020-01-11 12:33:36
问题 I am working on a report for which I have to export a large number of similar data frames into nice looking tables in Word. My goal is to achieve this in one go, using flextable to generate the tables and purrr / tidyverse to apply all the formatting procedures to all rows in a nested data frame. This is what my data frame looks like: df <- data.frame(school = c("A", "B", "A", "B", "A", "B"), students = c(round(runif(6, 1, 10), 0)), grade = c(1, 1, 2, 2, 3, 3)) I want to generate separate

In nested data frame, pass information from one list column to function applied in another

久未见 提交于 2020-01-11 12:33:13
问题 I am working on a report for which I have to export a large number of similar data frames into nice looking tables in Word. My goal is to achieve this in one go, using flextable to generate the tables and purrr / tidyverse to apply all the formatting procedures to all rows in a nested data frame. This is what my data frame looks like: df <- data.frame(school = c("A", "B", "A", "B", "A", "B"), students = c(round(runif(6, 1, 10), 0)), grade = c(1, 1, 2, 2, 3, 3)) I want to generate separate

R flextable - How to add a table-wide horizontal border under a merged cell

[亡魂溺海] 提交于 2019-12-25 16:00:49
问题 Is there a smart way to have a horizontal border table wide when you have merged cells? (In the example below, it is not yet table wide). Or should I write a function to calculate the correct index? library(flextable) library(officer) library(dplyr) myft <- flextable(head(mtcars), col_keys = c("am", "carb", "gear", "mpg", "drat" ))%>% theme_vanilla()%>% merge_v(j = c("am"))%>%border(border.bottom = fp_border(style = "solid", width=2), i=c(3,6), part="body") myft 回答1: Here is a code for what

R save FlexTable as html file in script

蹲街弑〆低调 提交于 2019-12-25 12:56:22
问题 I have a FlexTable produced with the ReporteRs package which I would like to export as .html. When I print the table to the viewer in RStudio I can do this by clicking on 'Export' and selecting 'Save as webpage'. How would I replicate this action in my script? I don't want to knit to a html document or produce a report just yet as at present I just want separate files for each of my draft tables which I can share with collaborators (but nicely formatted so they are easy to read). I have tried

Displaying multiple tables using Package officer and flextable

非 Y 不嫁゛ 提交于 2019-12-23 01:24:09
问题 I was wondering if it might be possible to display more than one flextable in the HTML format (on a single page) using flextable and officer ? library('flextable') library('officer') dat1 <- data.frame(Approaches = c("Y", "Y", "N"), Meets = c("N", "Y", "N"), row.names = c("Read", "Math", "Sci.")) dat2 <- data.frame(Read = "Y", Math = "N") def_par <- fp_par(text.align = "center") def_txt <- fp_text(bold = TRUE) ft <- flextable(dat1, cwidth = c(3.2, 3.2)) # Table #1 ft <- style(ft, pr_p = def