}}\preformatted{```\{r\}
#| tab.id: bookmark_id
#| tab.cap: caption text
flextable(head(cars))
```
}\if{html}{\out{
}}
\code{tab.id} is the caption id or bookmark, \code{tab.cap} is the caption
text. There are many options that can replace \code{set_caption()}
features. The following knitr chunk options are available:\tabular{lcc}{
\strong{label} \tab \strong{name} \tab \strong{value} \cr
Word stylename to use for table captions. \tab tab.cap.style \tab NULL \cr
caption id/bookmark \tab tab.id \tab NULL \cr
caption \tab tab.cap \tab NULL \cr
display table caption on top of the table or not \tab tab.topcaption \tab TRUE \cr
caption table sequence identifier. \tab tab.lp \tab "tab:" \cr
prefix for numbering chunk (default to "Table "). \tab tab.cap.pre \tab Table \cr
suffix for numbering chunk (default to ": "). \tab tab.cap.sep \tab " :" \cr
title number depth \tab tab.cap.tnd \tab 0 \cr
separator to use between title number and table number. \tab tab.cap.tns \tab "-" \cr
caption prefix formatting properties \tab tab.cap.fp_text \tab fp_text_lite(bold = TRUE) \cr
}
See \link{knit_print.flextable} for more details.
}
\section{Formatting the caption}{
To create captions in R Markdown using the 'flextable' package and 'officer'
package, you can utilize the \code{as_paragraph()} function. This approach is
recommended when your captions require complex content, such as a combination of
different text styles or the inclusion of images and equations.
The caption is constructed as a paragraph consisting of multiple chunks. Each
chunk represents a specific portion of the caption with its desired formatting,
such as red bold text or Arial italic text.
By default, if no specific formatting is specified (using either "a string" or
\code{as_chunk("a string")}), the \code{fp_text_default()} function sets the font settings
for the caption, including the font family, boldness, italics, color, etc. The
default values can be modified using the \code{set_flextable_defaults()} function.
However, it is recommended to explicitly use \code{as_chunk()} to define the desired
formatting.
It's important to note that the style properties of the caption will not
override the formatting of the individual elements within it. Therefore, you
need to explicitly specify the font to be used for the caption.
Here's an example of how to set a caption for a flextable in R Markdown using
the 'officer' package:
\if{html}{\out{}}\preformatted{library(flextable)
library(officer)
ftab <- flextable(head(cars)) \%>\%
set_caption(
as_paragraph(
as_chunk("caption", props = fp_text_default(font.family = "Cambria"))
), word_stylename = "Table Caption"
)
print(ftab, preview = "docx")
}\if{html}{\out{
}}
In this example, the \code{set_caption()} function sets the caption for the
flextable. The caption is created using \code{as_paragraph()} with a single chunk
created using \code{as_chunk("caption", props = fp_text_default(font.family = "Cambria"))}. The \code{word_stylename} parameter is used to specify the table
caption style in the resulting Word document. Finally, the \code{print()} function
generates the flextable with the caption, and \code{preview = "docx"} displays a
preview of the resulting Word document.
}
\section{Using 'Quarto'}{
In 'Quarto', captions and cross-references are handled differently
compared to 'R Markdown', where flextable takes care of the job.
In Quarto, the responsibility for managing captions lies with the Quarto
framework itself. Consequently, the \code{set_caption()} function in 'flextable'
is not as useful in a 'Quarto' document. The formatting and numbering of
captions are determined by Quarto rather than flextable. Please refer to
the Quarto documentation for more information on how to work with captions
in Quarto.
}
\examples{
ftab <- flextable(head(iris))
ftab <- set_caption(ftab, "my caption")
ftab
library(officer)
autonum <- run_autonum(seq_id = "tab", bkm = "mtcars")
ftab <- flextable(head(mtcars))
ftab <- set_caption(ftab, caption = "mtcars data", autonum = autonum)
ftab
}
\seealso{
\code{\link[=flextable]{flextable()}}
}
flextable/man/merge_v.Rd 0000644 0001762 0000144 00000004234 14565457154 014731 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/merge_flextable.R
\name{merge_v}
\alias{merge_v}
\title{Merge flextable cells vertically}
\usage{
merge_v(x, j = NULL, target = NULL, part = "body", combine = FALSE)
}
\arguments{
\item{x}{\code{flextable} object}
\item{j}{column to used to find consecutive values to be merged. Columns
from orignal dataset can also be used.}
\item{target}{columns names where cells have to be merged.}
\item{part}{partname of the table where merge has to be done.}
\item{combine}{If the value is TRUE, the columns defined by \code{j} will
be combined into a single column/value and the consecutive values of
this result will be used. Otherwise, the columns are inspected one
by one to perform cell merges.}
}
\description{
Merge flextable cells vertically when consecutive cells have
identical values. Text of formatted values are used to compare
values if available.
Two options are available, either a column-by-column algorithm or an
algorithm where the combinations of these columns are used once for all
target columns.
}
\examples{
ft_merge <- flextable(mtcars)
ft_merge <- merge_v(ft_merge, j = c("gear", "carb"))
ft_merge
data_ex <- structure(list(srdr_id = c(
"175124", "175124", "172525", "172525",
"172545", "172545", "172609", "172609", "172609"
), substances = c(
"alcohol",
"alcohol", "alcohol", "alcohol", "cannabis",
"cannabis", "alcohol\n cannabis\n other drugs",
"alcohol\n cannabis\n other drugs",
"alcohol\n cannabis\n other drugs"
), full_name = c(
"TAU", "MI", "TAU", "MI (parent)", "TAU", "MI",
"TAU", "MI", "MI"
), article_arm_name = c(
"Control", "WISEteens",
"Treatment as usual", "Brief MI (b-MI)", "Assessed control",
"Intervention", "Control", "Computer BI", "Therapist BI"
)), row.names = c(
NA,
-9L
), class = c("tbl_df", "tbl", "data.frame"))
ft_1 <- flextable(data_ex)
ft_1 <- theme_box(ft_1)
ft_2 <- merge_v(ft_1,
j = "srdr_id",
target = c("srdr_id", "substances")
)
ft_2
}
\seealso{
Other flextable merging function:
\code{\link{merge_at}()},
\code{\link{merge_h}()},
\code{\link{merge_h_range}()},
\code{\link{merge_none}()}
}
\concept{flextable merging function}
flextable/man/before.Rd 0000644 0001762 0000144 00000002135 14476430471 014537 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/borders.R
\name{before}
\alias{before}
\title{Is an element before a match with entries}
\usage{
before(x, entries)
}
\arguments{
\item{x}{an atomic vector of values to be tested}
\item{entries}{a sequence of items to be searched in \code{x}.}
}
\description{
return a logical vector of the same length as x, indicating
if elements are located before a set of entries to match or not.
}
\examples{
library(flextable)
library(officer)
dat <- data.frame(
stringsAsFactors = FALSE,
check.names = FALSE,
Level = c("setosa", "versicolor", "virginica", "", "Total"),
Freq = as.integer(c(50, 50, 50, 0, 150)),
`\% Valid` = c(
100 / 3,
100 / 3, 100 / 3, NA, 100
),
`\% Valid Cum.` = c(100 / 3, 100 * 2 / 3, 100, NA, 100),
`\% Total` = c(
100 / 3,
100 / 3, 100 / 3, 0, 100
),
`\% Total Cum.` = c(
100 / 3,
100 * 2 / 3, 100, 100, 100
)
)
ft <- flextable(dat)
ft <- hline(ft,
i = ~ before(Level, "Total"),
border = fp_border_default(width = 2)
)
ft
}
\seealso{
\code{\link[=hline]{hline()}}
}
flextable/man/plot.flextable.Rd 0000644 0001762 0000144 00000003167 14600642405 016215 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/printers.R
\name{plot.flextable}
\alias{plot.flextable}
\title{Plot a flextable}
\usage{
\method{plot}{flextable}(x, ...)
}
\arguments{
\item{x}{a flextable object}
\item{...}{additional arguments passed to \code{\link[=gen_grob]{gen_grob()}}.}
}
\description{
plots a flextable as a grid grob object
and display the result in a new graphics window.
'ragg' or 'svglite' or 'ggiraph' graphical device drivers
should be used to ensure a correct rendering.
}
\section{caption}{
It's important to note that captions are not part of the table itself.
This means when exporting a table to PNG or SVG formats (image formats),
the caption won't be included. Captions are intended for document outputs
like Word, HTML, or PDF, where tables are embedded within the document
itself.
}
\examples{
library(gdtools)
library(ragg)
register_liberationsans()
set_flextable_defaults(font.family = "Liberation Sans")
ftab <- as_flextable(cars)
tf <- tempfile(fileext = ".png")
agg_png(
filename = tf, width = 1.7, height = 3.26, unit = "in",
background = "transparent", res = 150
)
plot(ftab)
dev.off()
}
\seealso{
Other flextable print function:
\code{\link{as_raster}()},
\code{\link{df_printer}()},
\code{\link{flextable_to_rmd}()},
\code{\link{gen_grob}()},
\code{\link{htmltools_value}()},
\code{\link{knit_print.flextable}()},
\code{\link{print.flextable}()},
\code{\link{save_as_docx}()},
\code{\link{save_as_html}()},
\code{\link{save_as_image}()},
\code{\link{save_as_pptx}()},
\code{\link{save_as_rtf}()},
\code{\link{to_html.flextable}()}
}
\concept{flextable print function}
flextable/man/fit_to_width.Rd 0000644 0001762 0000144 00000002052 14470463166 015757 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/flextable_sizes.R
\name{fit_to_width}
\alias{fit_to_width}
\title{Fit a flextable to a maximum width}
\usage{
fit_to_width(x, max_width, inc = 1L, max_iter = 20, unit = "in")
}
\arguments{
\item{x}{flextable object}
\item{max_width}{maximum width to fit in inches}
\item{inc}{the font size decrease for each step}
\item{max_iter}{maximum iterations}
\item{unit}{unit for max_width, one of "in", "cm", "mm".}
}
\description{
decrease font size for each cell incrementally until
it fits a given max_width.
}
\examples{
ft_1 <- qflextable(head(mtcars))
ft_1 <- width(ft_1, width = 1)
ft_1
ft_2 <- fit_to_width(ft_1, max_width = 4)
ft_2
}
\seealso{
Other flextable dimensions:
\code{\link{autofit}()},
\code{\link{dim.flextable}()},
\code{\link{dim_pretty}()},
\code{\link{flextable_dim}()},
\code{\link{height}()},
\code{\link{hrule}()},
\code{\link{ncol_keys}()},
\code{\link{nrow_part}()},
\code{\link{set_table_properties}()},
\code{\link{width}()}
}
\concept{flextable dimensions}
flextable/man/chunk_dataframe.Rd 0000644 0001762 0000144 00000004443 14375473105 016414 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/05_content.R
\name{chunk_dataframe}
\alias{chunk_dataframe}
\title{Create a chunk representation suitable for flextable}
\usage{
chunk_dataframe(...)
}
\arguments{
\item{...}{values to set.}
}
\value{
a data.frame with an additional class "chunk" that makes it
suitable for beeing used in \code{\link[=as_paragraph]{as_paragraph()}}
}
\description{
This function is to be used by external packages
that want to provide an object that can be inserted as a chunk
object in paragraphs of a flextable object.
}
\section{text pattern with default values}{
\if{html}{\out{}}\preformatted{chunk_dataframe(txt = c("any text", "other text"))
}\if{html}{\out{
}}
}
\section{text pattern with bold set to TRUE}{
\if{html}{\out{}}\preformatted{chunk_dataframe(
txt = c("any text", "other text"),
bold = c(TRUE, TRUE))
}\if{html}{\out{
}}
}
\section{text pattern with control over all formatting properties}{
\if{html}{\out{}}\preformatted{chunk_dataframe(
txt = c("any text", "other text"),
font.size = c(12, 10),
italic = c(FALSE, TRUE),
bold = c(FALSE, TRUE),
underlined = c(FALSE, TRUE),
color = c("black", "red"),
shading.color = c("transparent", "yellow"),
font.family = c("Arial", "Arial"),
hansi.family = c("Arial", "Arial"),
eastasia.family = c("Arial", "Arial"),
cs.family = c("Arial", "Arial"),
vertical.align = c("top", "bottom") )
}\if{html}{\out{
}}
}
\section{text with url pattern}{
\if{html}{\out{}}\preformatted{chunk_dataframe(
txt = c("any text", "other text"),
url = rep("https://www.google.fr", 2),
font.size = c(12, 10),
italic = c(FALSE, TRUE),
bold = c(FALSE, TRUE),
underlined = c(FALSE, TRUE),
color = c("black", "red"),
shading.color = c("transparent", "yellow"),
font.family = c("Arial", "Arial"),
hansi.family = c("Arial", "Arial"),
eastasia.family = c("Arial", "Arial"),
cs.family = c("Arial", "Arial"),
vertical.align = c("top", "bottom") )
}\if{html}{\out{
}}
}
\section{images pattern}{
\if{html}{\out{}}\preformatted{chunk_dataframe(width = width, height = height, img_data = files )
}\if{html}{\out{
}}
}
\keyword{internal}
flextable/man/colformat_int.Rd 0000644 0001762 0000144 00000002221 14565457154 016137 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/formatters.R
\name{colformat_int}
\alias{colformat_int}
\title{Format integer cells}
\usage{
colformat_int(
x,
i = NULL,
j = NULL,
big.mark = get_flextable_defaults()$big.mark,
na_str = get_flextable_defaults()$na_str,
nan_str = get_flextable_defaults()$nan_str,
prefix = "",
suffix = ""
)
}
\arguments{
\item{x}{a flextable object}
\item{i}{rows selection}
\item{j}{columns selection.}
\item{big.mark}{see \code{\link[=format]{format()}}}
\item{na_str, nan_str}{string to be used for NA and NaN values}
\item{prefix, suffix}{string to be used as prefix or suffix}
}
\description{
Format integer cells in a flextable.
}
\examples{
z <- flextable(head(mtcars))
j <- c("vs", "am", "gear", "carb")
z <- colformat_int(x = z, j = j, prefix = "# ")
z
}
\seealso{
Other cells formatters:
\code{\link{colformat_char}()},
\code{\link{colformat_date}()},
\code{\link{colformat_datetime}()},
\code{\link{colformat_double}()},
\code{\link{colformat_image}()},
\code{\link{colformat_lgl}()},
\code{\link{colformat_num}()},
\code{\link{set_formatter}()}
}
\concept{cells formatters}
flextable/man/bold.Rd 0000644 0001762 0000144 00000002000 14566144245 014205 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/styles.R
\name{bold}
\alias{bold}
\title{Set bold font}
\usage{
bold(x, i = NULL, j = NULL, bold = TRUE, part = "body")
}
\arguments{
\item{x}{a flextable object}
\item{i}{rows selection}
\item{j}{columns selection}
\item{bold}{boolean value}
\item{part}{partname of the table (one of 'all', 'body', 'header', 'footer')}
}
\description{
change font weight of selected rows and columns of a flextable.
}
\examples{
ft <- flextable(head(iris))
ft <- bold(ft, bold = TRUE, part = "header")
}
\seealso{
Other sugar functions for table style:
\code{\link{align}()},
\code{\link{bg}()},
\code{\link{color}()},
\code{\link{empty_blanks}()},
\code{\link{font}()},
\code{\link{fontsize}()},
\code{\link{highlight}()},
\code{\link{italic}()},
\code{\link{keep_with_next}()},
\code{\link{line_spacing}()},
\code{\link{padding}()},
\code{\link{rotate}()},
\code{\link{tab_settings}()},
\code{\link{valign}()}
}
\concept{sugar functions for table style}
flextable/man/as_raster.Rd 0000644 0001762 0000144 00000002506 14515040434 015250 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/printers.R
\name{as_raster}
\alias{as_raster}
\title{Transform a flextable into a raster}
\usage{
as_raster(x, ...)
}
\arguments{
\item{x}{a flextable object}
\item{...}{additional arguments passed to other functions}
}
\description{
save a flextable as an image and return the corresponding
raster. This function has been implemented to let flextable be printed
on a ggplot object.
The function is no longer very useful since \code{\link[=gen_grob]{gen_grob()}} exists and
will be deprecated in a future version.
}
\note{
This function requires package 'magick'.
}
\examples{
ft <- qflextable(head(mtcars))
\dontrun{
if (require("ggplot2") && require("magick")) {
print(qplot(speed, dist, data = cars, geom = "point"))
grid::grid.raster(as_raster(ft))
}
}
}
\seealso{
Other flextable print function:
\code{\link{df_printer}()},
\code{\link{flextable_to_rmd}()},
\code{\link{gen_grob}()},
\code{\link{htmltools_value}()},
\code{\link{knit_print.flextable}()},
\code{\link{plot.flextable}()},
\code{\link{print.flextable}()},
\code{\link{save_as_docx}()},
\code{\link{save_as_html}()},
\code{\link{save_as_image}()},
\code{\link{save_as_pptx}()},
\code{\link{save_as_rtf}()},
\code{\link{to_html.flextable}()}
}
\concept{flextable print function}
\keyword{internal}
flextable/man/fmt_pct.Rd 0000644 0001762 0000144 00000001553 14570173725 014735 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/summarizor.R
\name{fmt_pct}
\alias{fmt_pct}
\title{Format numerical data as percentages}
\usage{
fmt_pct(x)
}
\arguments{
\item{x}{numeric values}
}
\description{
The function formats numeric vectors as percentages.
}
\examples{
library(flextable)
df <- data.frame(zz = .45)
ft_1 <- flextable(df)
ft_1 <- mk_par(
x = ft_1, j = 1, part = "body",
value = as_paragraph(as_chunk(zz, formatter = fmt_pct))
)
ft_1 <- autofit(ft_1)
ft_1
}
\seealso{
\code{\link[=tabulator]{tabulator()}}, \code{\link[=mk_par]{mk_par()}}
Other text formatter functions:
\code{\link{fmt_2stats}()},
\code{\link{fmt_avg_dev}()},
\code{\link{fmt_dbl}()},
\code{\link{fmt_header_n}()},
\code{\link{fmt_int}()},
\code{\link{fmt_n_percent}()},
\code{\link{fmt_signif_after_zeros}()}
}
\concept{text formatter functions}
flextable/man/as_flextable.tabulator.Rd 0000644 0001762 0000144 00000007040 14565457153 017727 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/as_flextable_tabulator.R
\name{as_flextable.tabulator}
\alias{as_flextable.tabulator}
\title{Transform a 'tabulator' object into a flextable}
\usage{
\method{as_flextable}{tabulator}(
x,
separate_with = character(0),
big_border = fp_border_default(width = 1.5),
small_border = fp_border_default(width = 0.75),
rows_alignment = "left",
columns_alignment = "center",
label_rows = x$rows,
spread_first_col = FALSE,
expand_single = FALSE,
sep_w = 0.05,
unit = "in",
...
)
}
\arguments{
\item{x}{result from \code{\link[=tabulator]{tabulator()}}}
\item{separate_with}{columns used to sepatate the groups
with an horizontal line.}
\item{big_border, small_border}{big and small border properties defined
by a call to \code{\link[=fp_border_default]{fp_border_default()}} or \code{\link[=fp_border]{fp_border()}}.}
\item{rows_alignment, columns_alignment}{alignments to apply to
columns corresponding to \code{rows} and \code{columns}; see arguments
\code{rows} and \code{columns} in \code{\link[=tabulator]{tabulator()}}.}
\item{label_rows}{labels to use for the first column names, i.e.
the \emph{row} column names. It must be a named vector, the values will
be matched based on the names.}
\item{spread_first_col}{if TRUE, first row is spread as a new line separator
instead of being a column. This helps to reduce the width and allows for
clear divisions.}
\item{expand_single}{if FALSE (the default), groups with only one
row will not be expanded with a title row. If TRUE,
single row groups and multi-row groups are all
restructured.}
\item{sep_w}{blank column separators'width to be used. If 0,
blank column separators will not be used.}
\item{unit}{unit of argument \code{sep_w}, one of "in", "cm", "mm".}
\item{...}{unused argument}
}
\description{
\code{\link[=tabulator]{tabulator()}} object can be transformed as a flextable
with method \code{\link[=as_flextable]{as_flextable()}}.
}
\examples{
\dontrun{
library(flextable)
set_flextable_defaults(digits = 2, border.color = "gray")
if (require("stats")) {
dat <- aggregate(breaks ~ wool + tension,
data = warpbreaks, mean
)
cft_1 <- tabulator(
x = dat,
rows = "wool",
columns = "tension",
`mean` = as_paragraph(as_chunk(breaks)),
`(N)` = as_paragraph(
as_chunk(length(breaks))
)
)
ft_1 <- as_flextable(cft_1, sep_w = .1)
ft_1
}
if (require("stats")) {
set_flextable_defaults(
padding = 1, font.size = 9,
border.color = "orange"
)
ft_2 <- as_flextable(cft_1, sep_w = 0)
ft_2
}
if (require("stats")) {
set_flextable_defaults(
padding = 6, font.size = 11,
border.color = "white",
font.color = "white",
background.color = "#333333"
)
ft_3 <- as_flextable(
x = cft_1, sep_w = 0,
rows_alignment = "center",
columns_alignment = "right"
)
ft_3
}
init_flextable_defaults()
}
}
\seealso{
\code{\link[=summarizor]{summarizor()}}, \code{\link[=as_grouped_data]{as_grouped_data()}}
Other as_flextable methods:
\code{\link{as_flextable}()},
\code{\link{as_flextable.data.frame}()},
\code{\link{as_flextable.gam}()},
\code{\link{as_flextable.glm}()},
\code{\link{as_flextable.grouped_data}()},
\code{\link{as_flextable.htest}()},
\code{\link{as_flextable.kmeans}()},
\code{\link{as_flextable.lm}()},
\code{\link{as_flextable.merMod}()},
\code{\link{as_flextable.pam}()},
\code{\link{as_flextable.summarizor}()},
\code{\link{as_flextable.table}()},
\code{\link{as_flextable.tabular}()},
\code{\link{as_flextable.xtable}()}
}
\concept{as_flextable methods}
flextable/man/continuous_summary.Rd 0000644 0001762 0000144 00000001540 14476430470 017256 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/as_flextable.R
\name{continuous_summary}
\alias{continuous_summary}
\title{Continuous columns summary}
\usage{
continuous_summary(
dat,
columns = NULL,
by = character(0),
hide_grouplabel = TRUE,
digits = 3
)
}
\arguments{
\item{dat}{a data.frame}
\item{columns}{continuous variables to be summarized. If NULL all
continuous variables are summarized.}
\item{by}{discrete variables to use as groups when summarizing.}
\item{hide_grouplabel}{if TRUE, group label will not be rendered, only
level/value will be rendered.}
\item{digits}{the desired number of digits after the decimal point}
}
\description{
create a data.frame summary for continuous variables
}
\examples{
ft_1 <- continuous_summary(iris, names(iris)[1:4],
by = "Species",
hide_grouplabel = FALSE
)
ft_1
}
flextable/man/save_as_pptx.Rd 0000644 0001762 0000144 00000003340 14515040463 015760 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/printers.R
\name{save_as_pptx}
\alias{save_as_pptx}
\title{Save flextable objects in a 'PowerPoint' file}
\usage{
save_as_pptx(..., values = NULL, path)
}
\arguments{
\item{...}{flextable objects, objects, possibly named. If named objects, names are
used as slide titles.}
\item{values}{a list (possibly named), each element is a flextable object. If named objects, names are
used as slide titles. If provided, argument \code{...} will be ignored.}
\item{path}{PowerPoint file to be created}
}
\value{
a string containing the full name of the generated file
}
\description{
sugar function to save flextable objects in
an PowerPoint file.
This feature is available to simplify the work of users by avoiding
the need to use the 'officer' package. If it doesn't suit your needs,
then use the API offered by 'officer' which allows simple and
complicated things.
}
\note{
The PowerPoint format ignores captions (see \code{\link[=set_caption]{set_caption()}}).
}
\examples{
ft1 <- flextable(head(iris))
tf <- tempfile(fileext = ".pptx")
save_as_pptx(ft1, path = tf)
ft2 <- flextable(head(mtcars))
tf <- tempfile(fileext = ".pptx")
save_as_pptx(`iris table` = ft1, `mtcars table` = ft2, path = tf)
}
\seealso{
Other flextable print function:
\code{\link{as_raster}()},
\code{\link{df_printer}()},
\code{\link{flextable_to_rmd}()},
\code{\link{gen_grob}()},
\code{\link{htmltools_value}()},
\code{\link{knit_print.flextable}()},
\code{\link{plot.flextable}()},
\code{\link{print.flextable}()},
\code{\link{save_as_docx}()},
\code{\link{save_as_html}()},
\code{\link{save_as_image}()},
\code{\link{save_as_rtf}()},
\code{\link{to_html.flextable}()}
}
\concept{flextable print function}
flextable/man/compose.Rd 0000644 0001762 0000144 00000005010 14476430471 014735 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/compose.R
\name{compose}
\alias{compose}
\alias{mk_par}
\title{Define displayed values and mixed content}
\usage{
compose(x, i = NULL, j = NULL, value, part = "body", use_dot = FALSE)
mk_par(x, i = NULL, j = NULL, value, part = "body", use_dot = FALSE)
}
\arguments{
\item{x}{a flextable object}
\item{i}{rows selection}
\item{j}{column selection}
\item{value}{a call to function \code{\link[=as_paragraph]{as_paragraph()}}.}
\item{part}{partname of the table (one of 'all', 'body', 'header', 'footer')}
\item{use_dot}{by default \code{use_dot=FALSE}; if \code{use_dot=TRUE},
\code{value} is evaluated within a data.frame augmented of a column named \code{.}
containing the \code{j}th column.}
}
\description{
Modify flextable displayed values with eventually
mixed content paragraphs.
Function is handling complex formatting as image insertion with
\code{\link[=as_image]{as_image()}}, superscript with \code{\link[=as_sup]{as_sup()}}, formated
text with \code{\link[=as_chunk]{as_chunk()}} and several other \emph{chunk} functions.
Function \code{mk_par} is another name for \code{compose} as
there is an unwanted \strong{conflict with package 'purrr'}.
If you only need to add some content at the end
or the beginning of paragraphs and keep existing
content as it is, functions \code{\link[=append_chunks]{append_chunks()}} and
\code{\link[=prepend_chunks]{prepend_chunks()}} should be prefered.
}
\examples{
ft_1 <- flextable(head(cars, n = 5), col_keys = c("speed", "dist", "comment"))
ft_1 <- mk_par(
x = ft_1, j = "comment",
i = ~ dist > 9,
value = as_paragraph(
colorize(as_i("speed: "), color = "gray"),
as_sup(sprintf("\%.0f", speed))
)
)
ft_1 <- set_table_properties(ft_1, layout = "autofit")
ft_1
# using `use_dot = TRUE` ----
set.seed(8)
dat <- iris[sample.int(n = 150, size = 10), ]
dat <- dat[order(dat$Species), ]
ft_2 <- flextable(dat)
ft_2 <- mk_par(ft_2,
j = ~ . - Species,
value = as_paragraph(
minibar(.,
barcol = "white",
height = .1
)
), use_dot = TRUE
)
ft_2 <- theme_vader(ft_2)
ft_2 <- autofit(ft_2)
ft_2
}
\seealso{
\code{\link[=fp_text_default]{fp_text_default()}}, \code{\link[=as_chunk]{as_chunk()}}, \code{\link[=as_b]{as_b()}}, \code{\link[=as_word_field]{as_word_field()}}, \code{\link[=labelizor]{labelizor()}}
Other functions for mixed content paragraphs:
\code{\link{append_chunks}()},
\code{\link{as_paragraph}()},
\code{\link{prepend_chunks}()}
}
\concept{functions for mixed content paragraphs}
flextable/man/line_spacing.Rd 0000644 0001762 0000144 00000002236 14566144245 015733 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/styles.R
\name{line_spacing}
\alias{line_spacing}
\title{Set text alignment}
\usage{
line_spacing(x, i = NULL, j = NULL, space = 1, part = "body")
}
\arguments{
\item{x}{a flextable object}
\item{i}{rows selection}
\item{j}{columns selection}
\item{space}{space between lines of text, 1 is single line spacing, 2 is double line spacing.}
\item{part}{partname of the table (one of 'all', 'body', 'header', 'footer')}
}
\description{
change text alignment of selected rows and columns of a flextable.
}
\examples{
ft <- flextable(head(mtcars)[, 3:6])
ft <- line_spacing(ft, space = 1.6, part = "all")
ft <- set_table_properties(ft, layout = "autofit")
ft
}
\seealso{
Other sugar functions for table style:
\code{\link{align}()},
\code{\link{bg}()},
\code{\link{bold}()},
\code{\link{color}()},
\code{\link{empty_blanks}()},
\code{\link{font}()},
\code{\link{fontsize}()},
\code{\link{highlight}()},
\code{\link{italic}()},
\code{\link{keep_with_next}()},
\code{\link{padding}()},
\code{\link{rotate}()},
\code{\link{tab_settings}()},
\code{\link{valign}()}
}
\concept{sugar functions for table style}
flextable/man/paginate.Rd 0000644 0001762 0000144 00000005744 14476430471 015076 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/paginate.R
\name{paginate}
\alias{paginate}
\title{Paginate tables}
\usage{
paginate(
x,
init = NULL,
hdr_ftr = TRUE,
group = character(),
group_def = c("rle", "nonempty")
)
}
\arguments{
\item{x}{flextable object}
\item{init}{init value for keep_with_next property, it default
value is \code{get_flextable_defaults()$keep_with_next}.}
\item{hdr_ftr}{if TRUE (default), prevent breaks between table body
and header and between table body and footer.}
\item{group}{name of a column to use for finding groups}
\item{group_def}{algorithm to be used to identify groups
that should not be split into two pages, one of 'rle', 'nonempty':
\itemize{
\item 'rle': runs of equal values are used to define the groups,
to be used with \code{\link[=tabulator]{tabulator()}}.
\item 'nonempty': non empty value start a new group,
to be used with \code{\link[=as_flextable.tabular]{as_flextable.tabular()}}.
}}
}
\value{
updated flextable object
}
\description{
Prevents breaks between tables rows you want to stay together.
This feature only applies to Word and RTF output.
}
\details{
The pagination of tables allows you to control their position
in relation to page breaks.
For small tables, a simple setting is usually used that indicates
that all rows should be displayed together:
\if{html}{\out{}}\preformatted{paginate(x, init = TRUE, hdr_ftr = TRUE)
}\if{html}{\out{
}}
For large tables, it is recommended to use a setting that
indicates that all rows of the header should be bound to
the first row of the table to avoid the case where the header
is displayed alone at the bottom of the page and then repeated
on the next one:
\if{html}{\out{}}\preformatted{paginate(x, init = FALSE, hdr_ftr = TRUE)
}\if{html}{\out{
}}
For tables that present groups that you don't want to be presented
on two pages, you must use a parameterization involving the notion
of group and an algorithm for determining the groups.
\if{html}{\out{}}\preformatted{paginate(x, group = "grp", group_def = "rle")
}\if{html}{\out{
}}
}
\examples{
\dontshow{
data.table::setDTthreads(1)
}
library(data.table)
library(flextable)
init_flextable_defaults()
multi_fun <- function(x) {
list(mean = mean(x), sd = sd(x))
}
dat <- as.data.table(ggplot2::diamonds)
dat <- dat[clarity \%in\% c("I1", "SI1", "VS2")]
dat <- dat[, unlist(lapply(.SD, multi_fun),
recursive = FALSE
),
.SDcols = c("z", "y"),
by = c("cut", "color", "clarity")
]
tab <- tabulator(
x = dat, rows = c("cut", "color"),
columns = "clarity",
`z stats` = as_paragraph(as_chunk(fmt_avg_dev(z.mean, z.sd, digit2 = 2))),
`y stats` = as_paragraph(as_chunk(fmt_avg_dev(y.mean, y.sd, digit2 = 2)))
)
ft_1 <- as_flextable(tab)
ft_1 <- autofit(x = ft_1, add_w = .05) |>
paginate(group = "cut", group_def = "rle")
save_as_docx(ft_1, path = tempfile(fileext = ".docx"))
save_as_rtf(ft_1, path = tempfile(fileext = ".rtf"))
}
flextable/man/add_footer_row.Rd 0000644 0001762 0000144 00000005431 14565457153 016301 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/augment_rows.R
\name{add_footer_row}
\alias{add_footer_row}
\title{Add footer labels}
\usage{
add_footer_row(x, top = TRUE, values = character(0), colwidths = integer(0))
}
\arguments{
\item{x}{a flextable object}
\item{top}{should the row be inserted at the top or the bottom.}
\item{values}{values to add. It can be a \code{list}, a \code{character()} vector
or a call to \code{\link[=as_paragraph]{as_paragraph()}}.
If it is a list, it can be a named list with the names of the columns of the
original data.frame or the \code{colkeys}; this is the recommended method because
it allows to keep the original data types and therefore allows to perform
conditional formatting. If a character, columns of the original data.frame
stored in the flextable object are changed to \code{character()}; this is often
not an issue with footer and header but can be inconvenient if adding
rows into body as it will change data types to character and prevent
efficient conditional formatting.}
\item{colwidths}{the number of columns to merge in the row for each label}
}
\description{
Add a row of new columns labels in footer part.
Labels can be spanned along multiple columns, as merged cells.
Labels are associated with a number of columns
to merge that default to one if not specified.
In this case, you have to make sure that the
number of labels is equal to the number of columns displayed.
The function can add only one single row by call.
Labels can be formatted with \code{\link[=as_paragraph]{as_paragraph()}}.
}
\examples{
library(flextable)
ft01 <- fp_text_default(color = "red")
ft02 <- fp_text_default(color = "orange")
pars <- as_paragraph(
as_chunk(c("(1)", "(2)"), props = ft02), " ",
as_chunk(
c(
"My tailor is rich",
"My baker is rich"
),
props = ft01
)
)
ft_1 <- flextable(head(mtcars))
ft_1 <- add_footer_row(ft_1,
values = pars,
colwidths = c(5, 6), top = FALSE
)
ft_1 <- add_footer_row(ft_1,
values = pars,
colwidths = c(3, 8), top = TRUE
)
ft_1
ft_2 <- flextable(head(airquality))
ft_2 <- add_footer_row(ft_2,
values = c("Measure", "Time"),
colwidths = c(4, 2), top = TRUE
)
ft_2 <- theme_box(ft_2)
ft_2
}
\seealso{
\code{\link[=flextable]{flextable()}}, \code{\link[=set_caption]{set_caption()}}
Other functions for row and column operations in a flextable:
\code{\link{add_body}()},
\code{\link{add_body_row}()},
\code{\link{add_footer}()},
\code{\link{add_footer_lines}()},
\code{\link{add_header}()},
\code{\link{add_header_row}()},
\code{\link{delete_columns}()},
\code{\link{delete_part}()},
\code{\link{delete_rows}()},
\code{\link{separate_header}()},
\code{\link{set_header_footer_df}},
\code{\link{set_header_labels}()}
}
\concept{functions for row and column operations in a flextable}
flextable/man/border_inner_h.Rd 0000644 0001762 0000144 00000002213 14565457153 016256 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/borders.R
\name{border_inner_h}
\alias{border_inner_h}
\title{Set inner borders}
\usage{
border_inner_h(x, border = NULL, part = "body")
}
\arguments{
\item{x}{a flextable object}
\item{border}{border properties defined by a call to \code{\link[=fp_border]{fp_border()}}}
\item{part}{partname of the table (one of 'all', 'body', 'header', 'footer')}
}
\description{
The function is applying a border to inner content of one
or all parts of a flextable.
}
\examples{
library(officer)
std_border <- fp_border(color = "orange", width = 1)
dat <- iris[c(1:5, 51:55, 101:105), ]
ft <- flextable(dat)
ft <- border_remove(x = ft)
# add inner horizontal borders
ft <- border_inner_h(ft, border = std_border)
ft
}
\seealso{
Other borders management:
\code{\link{border_inner}()},
\code{\link{border_inner_v}()},
\code{\link{border_outer}()},
\code{\link{border_remove}()},
\code{\link{hline}()},
\code{\link{hline_bottom}()},
\code{\link{hline_top}()},
\code{\link{surround}()},
\code{\link{vline}()},
\code{\link{vline_left}()},
\code{\link{vline_right}()}
}
\concept{borders management}
flextable/man/delete_columns.Rd 0000644 0001762 0000144 00000002227 14565457154 016307 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/augment_rows.R
\name{delete_columns}
\alias{delete_columns}
\title{Delete flextable columns}
\usage{
delete_columns(x, j = NULL)
}
\arguments{
\item{x}{a \code{flextable} object}
\item{j}{columns selection}
}
\description{
The function removes one or more columns
from a 'flextable'.
}
\details{
Deleting one or more columns will result in the deletion
of any span parameters that may have been set previously.
They will have to be redone after this operation or
performed only after this deletion.
}
\examples{
ft <- flextable(head(iris))
ft <- delete_columns(ft, j = "Species")
ft
}
\seealso{
Other functions for row and column operations in a flextable:
\code{\link{add_body}()},
\code{\link{add_body_row}()},
\code{\link{add_footer}()},
\code{\link{add_footer_lines}()},
\code{\link{add_footer_row}()},
\code{\link{add_header}()},
\code{\link{add_header_row}()},
\code{\link{delete_part}()},
\code{\link{delete_rows}()},
\code{\link{separate_header}()},
\code{\link{set_header_footer_df}},
\code{\link{set_header_labels}()}
}
\concept{functions for row and column operations in a flextable}
flextable/man/information_data_paragraph.Rd 0000644 0001762 0000144 00000002434 14552463753 020646 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/read_structure.R
\name{information_data_paragraph}
\alias{information_data_paragraph}
\title{paragraph related information of a flextable}
\usage{
information_data_paragraph(x)
}
\arguments{
\item{x}{a flextable object}
}
\value{
a data.frame containing information about paragraphs:
\itemize{
\item formatting properties,
\item part (\code{.part}), row (\code{.row_id}) and column (\code{.col_id}).
}
}
\description{
This function takes a flextable object and returns a data.frame containing
information about each paragraph within the flextable. The data.frame includes
details about formatting properties and position within the
row and column.
}
\section{don't use this}{
These data structures should not be used, as they
represent an interpretation of the underlying data
structures, which may evolve over time.
\strong{They are exported to enable two packages that exploit
these structures to make a transition, and should not
remain available for long.}
}
\examples{
ft <- as_flextable(iris)
x <- information_data_paragraph(ft)
head(x)
}
\seealso{
Other information data functions:
\code{\link{information_data_cell}()},
\code{\link{information_data_chunk}()}
}
\concept{information data functions}
\keyword{internal}
flextable/man/as_flextable.pam.Rd 0000644 0001762 0000144 00000002421 14565457153 016505 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/as_flextable.R
\name{as_flextable.pam}
\alias{as_flextable.pam}
\title{Transform a 'pam' object into a flextable}
\usage{
\method{as_flextable}{pam}(x, digits = 4, ...)
}
\arguments{
\item{x}{a \code{\link[cluster:pam]{cluster::pam()}} object}
\item{digits}{number of digits for the numeric columns}
\item{...}{unused argument}
}
\description{
produce a flextable describing a
pam object. The function is only using package 'broom'
that provides the data presented in the resulting flextable.
}
\examples{
if (require("cluster")) {
dat <- as.data.frame(scale(mtcars[1:7]))
cl <- pam(dat, 3)
ft <- as_flextable(cl)
ft
}
}
\seealso{
Other as_flextable methods:
\code{\link{as_flextable}()},
\code{\link{as_flextable.data.frame}()},
\code{\link{as_flextable.gam}()},
\code{\link{as_flextable.glm}()},
\code{\link{as_flextable.grouped_data}()},
\code{\link{as_flextable.htest}()},
\code{\link{as_flextable.kmeans}()},
\code{\link{as_flextable.lm}()},
\code{\link{as_flextable.merMod}()},
\code{\link{as_flextable.summarizor}()},
\code{\link{as_flextable.table}()},
\code{\link{as_flextable.tabular}()},
\code{\link{as_flextable.tabulator}()},
\code{\link{as_flextable.xtable}()}
}
\concept{as_flextable methods}
flextable/man/fmt_2stats.Rd 0000644 0001762 0000144 00000004051 14570173724 015362 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/summarizor.R
\name{fmt_2stats}
\alias{fmt_2stats}
\alias{fmt_summarizor}
\title{Format content for data generated with summarizor()}
\usage{
fmt_2stats(stat, num1, num2, cts, pcts, ...)
fmt_summarizor(stat, num1, num2, cts, pcts, ...)
}
\arguments{
\item{stat}{a character column containing the name of statictics}
\item{num1}{a numeric statistic to display such as a mean or a median}
\item{num2}{a numeric statistic to display such as a standard
deviation or a median absolute deviation.}
\item{cts}{a count to display}
\item{pcts}{a percentage to display}
\item{...}{unused arguments}
}
\description{
This function was written to allow easy demonstrations
of flextable's ability to produce table summaries (with \code{\link[=summarizor]{summarizor()}}).
It assumes that we have either a quantitative variable, in which
case we will display the mean and the standard deviation, or a
qualitative variable, in which case we will display the count and the
percentage corresponding to each modality.
}
\examples{
library(flextable)
z <- summarizor(iris, by = "Species")
tab_1 <- tabulator(
x = z,
rows = c("variable", "stat"),
columns = "Species",
blah = as_paragraph(
as_chunk(
fmt_summarizor(
stat = stat,
num1 = value1, num2 = value2,
cts = cts, pcts = percent
)
)
)
)
ft_1 <- as_flextable(x = tab_1, separate_with = "variable")
ft_1 <- labelizor(
x = ft_1, j = "stat",
labels = c(
mean_sd = "Moyenne (ecart-type)",
median_iqr = "Mediane (IQR)",
range = "Etendue",
missing = "Valeurs manquantes"
)
)
ft_1 <- autofit(ft_1)
ft_1
}
\seealso{
\code{\link[=summarizor]{summarizor()}}, \code{\link[=tabulator]{tabulator()}}, \code{\link[=mk_par]{mk_par()}}
Other text formatter functions:
\code{\link{fmt_avg_dev}()},
\code{\link{fmt_dbl}()},
\code{\link{fmt_header_n}()},
\code{\link{fmt_int}()},
\code{\link{fmt_n_percent}()},
\code{\link{fmt_pct}()},
\code{\link{fmt_signif_after_zeros}()}
}
\concept{text formatter functions}
flextable/man/border_outer.Rd 0000644 0001762 0000144 00000002202 14565457153 015770 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/borders.R
\name{border_outer}
\alias{border_outer}
\title{Set outer borders}
\usage{
border_outer(x, border = NULL, part = "all")
}
\arguments{
\item{x}{a flextable object}
\item{border}{border properties defined by a call to \code{\link[=fp_border]{fp_border()}}}
\item{part}{partname of the table (one of 'all', 'body', 'header', 'footer')}
}
\description{
The function is applying a border to outer cells of one
or all parts of a flextable.
}
\examples{
library(officer)
big_border <- fp_border(color = "red", width = 2)
dat <- iris[c(1:5, 51:55, 101:105), ]
ft <- flextable(dat)
ft <- border_remove(x = ft)
# add outer borders
ft <- border_outer(ft, part = "all", border = big_border)
ft
}
\seealso{
Other borders management:
\code{\link{border_inner}()},
\code{\link{border_inner_h}()},
\code{\link{border_inner_v}()},
\code{\link{border_remove}()},
\code{\link{hline}()},
\code{\link{hline_bottom}()},
\code{\link{hline_top}()},
\code{\link{surround}()},
\code{\link{vline}()},
\code{\link{vline_left}()},
\code{\link{vline_right}()}
}
\concept{borders management}
flextable/man/df_printer.Rd 0000644 0001762 0000144 00000004337 14515040434 015425 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/df_printer.R
\name{df_printer}
\alias{df_printer}
\title{data.frame automatic printing as a flextable}
\usage{
df_printer(dat, ...)
}
\arguments{
\item{dat}{the data.frame}
\item{...}{unused argument}
}
\description{
Create a summary from a data.frame as a flextable. This function
is to be used in an R Markdown document.
To use that function, you must declare it in the part \code{df_print} of the 'YAML'
header of your R Markdown document:
\if{html}{\out{}}\preformatted{---
df_print: !expr function(x) flextable::df_printer(x)
---
}\if{html}{\out{
}}
We notice an unexpected behavior with bookdown. When using bookdown it
is necessary to use \code{\link[=use_df_printer]{use_df_printer()}} instead in a setup run chunk:
\if{html}{\out{}}\preformatted{use_df_printer()
}\if{html}{\out{
}}
}
\details{
'knitr' chunk options are available to customize the output:
\itemize{
\item \code{ft_max_row}: The number of rows to print. Default to 10.
\item \code{ft_split_colnames}: Should the column names be split
(with non alpha-numeric characters). Default to FALSE.
\item \code{ft_short_strings}: Should the character column be shorten.
Default to FALSE.
\item \code{ft_short_size}: Maximum length of character column if
\code{ft_short_strings} is TRUE. Default to 35.
\item \code{ft_short_suffix}: Suffix to add when character values are shorten.
Default to "...".
\item \code{ft_do_autofit}: Use autofit() before rendering the table.
Default to TRUE.
\item \code{ft_show_coltype}: Show column types.
Default to TRUE.
\item \code{ft_color_coltype}: Color to use for column types.
Default to "#999999".
}
}
\examples{
df_printer(head(mtcars))
}
\seealso{
Other flextable print function:
\code{\link{as_raster}()},
\code{\link{flextable_to_rmd}()},
\code{\link{gen_grob}()},
\code{\link{htmltools_value}()},
\code{\link{knit_print.flextable}()},
\code{\link{plot.flextable}()},
\code{\link{print.flextable}()},
\code{\link{save_as_docx}()},
\code{\link{save_as_html}()},
\code{\link{save_as_image}()},
\code{\link{save_as_pptx}()},
\code{\link{save_as_rtf}()},
\code{\link{to_html.flextable}()}
}
\concept{flextable print function}
flextable/man/tabulator.Rd 0000644 0001762 0000144 00000010450 14441705246 015266 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/as_flextable_tabulator.R
\name{tabulator}
\alias{tabulator}
\alias{summary.tabulator}
\title{Tabulation of aggregations}
\usage{
tabulator(
x,
rows,
columns,
datasup_first = NULL,
datasup_last = NULL,
hidden_data = NULL,
row_compose = list(),
...
)
\method{summary}{tabulator}(object, ...)
}
\arguments{
\item{x}{an aggregated data.frame}
\item{rows}{column names to use in rows dimensions}
\item{columns}{column names to use in columns dimensions}
\item{datasup_first}{additional data that will be merged with
table and placed after the columns presenting
the row dimensions.}
\item{datasup_last}{additional data that will be merged with
table and placed at the end of the table.}
\item{hidden_data}{additional data that will be merged with
table, the columns are not presented but can be used
with \code{\link[=compose]{compose()}} or \code{\link[=mk_par]{mk_par()}} function.}
\item{row_compose}{a list of call to \code{\link[=as_paragraph]{as_paragraph()}} - these
calls will be applied to the row dimensions (the name is
used to target the displayed column).}
\item{...}{named arguments calling function \code{\link[=as_paragraph]{as_paragraph()}}.
The names are used as labels and the values are evaluated
when the flextable is created.}
\item{object}{an object returned by function
\code{tabulator()}.}
}
\value{
an object of class \code{tabulator}.
}
\description{
It tabulates a data.frame representing an aggregation
which is then transformed as a flextable with
\link[=as_flextable.tabulator]{as_flextable}. The function
allows to define any display with the syntax of flextable in
a table whose layout is showing dimensions of the aggregation
across rows and columns.
\if{html}{\out{
}}
}
\section{Methods (by generic)}{
\itemize{
\item \code{summary(tabulator)}: call \code{summary()} to get
a data.frame describing mappings between variables
and their names in the flextable. This data.frame contains
a column named \code{col_keys} where are stored the names that
can be used for further selections.
}}
\note{
This is very first version of the function; be aware it
can evolve or change.
}
\examples{
\dontrun{
set_flextable_defaults(digits = 2, border.color = "gray")
library(data.table)
# example 1 ----
if (require("stats")) {
dat <- aggregate(breaks ~ wool + tension,
data = warpbreaks, mean
)
cft_1 <- tabulator(
x = dat, rows = "wool",
columns = "tension",
`mean` = as_paragraph(as_chunk(breaks)),
`(N)` = as_paragraph(as_chunk(length(breaks), formatter = fmt_int))
)
ft_1 <- as_flextable(cft_1)
ft_1
}
# example 2 ----
if (require("ggplot2")) {
multi_fun <- function(x) {
list(mean = mean(x), sd = sd(x))
}
dat <- as.data.table(ggplot2::diamonds)
dat <- dat[cut \%in\% c("Fair", "Good", "Very Good")]
dat <- dat[, unlist(lapply(.SD, multi_fun),
recursive = FALSE
),
.SDcols = c("z", "y"),
by = c("cut", "color")
]
tab_2 <- tabulator(
x = dat, rows = "color",
columns = "cut",
`z stats` = as_paragraph(as_chunk(fmt_avg_dev(z.mean, z.sd, digit2 = 2))),
`y stats` = as_paragraph(as_chunk(fmt_avg_dev(y.mean, y.sd, digit2 = 2)))
)
ft_2 <- as_flextable(tab_2)
ft_2 <- autofit(x = ft_2, add_w = .05)
ft_2
}
# example 3 ----
# data.table version
dat <- melt(as.data.table(iris),
id.vars = "Species",
variable.name = "name", value.name = "value"
)
dat <- dat[,
list(
avg = mean(value, na.rm = TRUE),
sd = sd(value, na.rm = TRUE)
),
by = c("Species", "name")
]
# dplyr version
# library(dplyr)
# dat <- iris \%>\%
# pivot_longer(cols = -c(Species)) \%>\%
# group_by(Species, name) \%>\%
# summarise(avg = mean(value, na.rm = TRUE),
# sd = sd(value, na.rm = TRUE),
# .groups = "drop")
tab_3 <- tabulator(
x = dat, rows = c("Species"),
columns = "name",
`mean (sd)` = as_paragraph(
as_chunk(avg),
" (", as_chunk(sd), ")"
)
)
ft_3 <- as_flextable(tab_3)
ft_3
init_flextable_defaults()
}
}
\seealso{
\code{\link[=as_flextable.tabulator]{as_flextable.tabulator()}}, \code{\link[=summarizor]{summarizor()}},
\code{\link[=as_grouped_data]{as_grouped_data()}}, \code{\link[=tabulator_colnames]{tabulator_colnames()}}
}
flextable/man/color.Rd 0000644 0001762 0000144 00000004245 14566144245 014420 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/styles.R
\name{color}
\alias{color}
\title{Set font color}
\usage{
color(x, i = NULL, j = NULL, color, part = "body", source = j)
}
\arguments{
\item{x}{a flextable object}
\item{i}{rows selection}
\item{j}{columns selection}
\item{color}{color to use as font color. If a function, function need to return
a character vector of colors.}
\item{part}{partname of the table (one of 'all', 'body', 'header', 'footer')}
\item{source}{if color is a function, source is specifying the dataset column to be used
as argument to \code{color}. This is only useful if j is colored with values contained in
other columns.}
}
\description{
Change text color of selected rows and
columns of a flextable. A function can be used instead of
fixed colors.
When \code{color} is a function, it is possible to color cells based on values
located in other columns, using hidden columns (those not used by
argument \code{colkeys}) is a common use case. The argument \code{source}
has to be used to define what are the columns to be used for the color
definition and the argument \code{j} has to be used to define where to apply
the colors and only accept values from \code{colkeys}.
}
\examples{
ft <- flextable(head(mtcars))
ft <- color(ft, color = "orange", part = "header")
ft <- color(ft,
color = "red",
i = ~ qsec < 18 & vs < 1
)
ft
if (require("scales")) {
scale <- scales::col_numeric(domain = c(-1, 1), palette = "RdBu")
x <- as.data.frame(cor(iris[-5]))
x <- cbind(
data.frame(
colname = colnames(x),
stringsAsFactors = FALSE
),
x
)
ft_2 <- flextable(x)
ft_2 <- color(ft_2, j = x$colname, color = scale)
ft_2 <- set_formatter_type(ft_2)
ft_2
}
}
\seealso{
Other sugar functions for table style:
\code{\link{align}()},
\code{\link{bg}()},
\code{\link{bold}()},
\code{\link{empty_blanks}()},
\code{\link{font}()},
\code{\link{fontsize}()},
\code{\link{highlight}()},
\code{\link{italic}()},
\code{\link{keep_with_next}()},
\code{\link{line_spacing}()},
\code{\link{padding}()},
\code{\link{rotate}()},
\code{\link{tab_settings}()},
\code{\link{valign}()}
}
\concept{sugar functions for table style}
flextable/man/as_flextable.htest.Rd 0000644 0001762 0000144 00000002315 14565457153 017061 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/as_flextable.R
\name{as_flextable.htest}
\alias{as_flextable.htest}
\title{Transform a 'htest' object into a flextable}
\usage{
\method{as_flextable}{htest}(x, ...)
}
\arguments{
\item{x}{htest object}
\item{...}{unused argument}
}
\description{
produce a flextable describing an
object oof class \code{htest}.
}
\examples{
if (require("stats")) {
M <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
dimnames(M) <- list(
gender = c("F", "M"),
party = c("Democrat", "Independent", "Republican")
)
ft_1 <- as_flextable(chisq.test(M))
ft_1
}
}
\seealso{
Other as_flextable methods:
\code{\link{as_flextable}()},
\code{\link{as_flextable.data.frame}()},
\code{\link{as_flextable.gam}()},
\code{\link{as_flextable.glm}()},
\code{\link{as_flextable.grouped_data}()},
\code{\link{as_flextable.kmeans}()},
\code{\link{as_flextable.lm}()},
\code{\link{as_flextable.merMod}()},
\code{\link{as_flextable.pam}()},
\code{\link{as_flextable.summarizor}()},
\code{\link{as_flextable.table}()},
\code{\link{as_flextable.tabular}()},
\code{\link{as_flextable.tabulator}()},
\code{\link{as_flextable.xtable}()}
}
\concept{as_flextable methods}
flextable/man/flextable_html_dependency.Rd 0000644 0001762 0000144 00000000737 14476430471 020473 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/html_str.R
\name{flextable_html_dependency}
\alias{flextable_html_dependency}
\title{htmlDependency for flextable objects}
\usage{
flextable_html_dependency()
}
\description{
When using loops in an R Markdown for HTML document, the
htmlDependency object for flextable must also be added at least once.
}
\examples{
if (require("htmltools")) {
div(flextable_html_dependency())
}
}
\keyword{internal}
flextable/man/set_flextable_defaults.Rd 0000644 0001762 0000144 00000015301 14571560656 020011 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/defaults.R
\name{set_flextable_defaults}
\alias{set_flextable_defaults}
\alias{init_flextable_defaults}
\title{Modify flextable defaults formatting properties}
\usage{
set_flextable_defaults(
font.family = NULL,
font.size = NULL,
font.color = NULL,
text.align = NULL,
padding = NULL,
padding.bottom = NULL,
padding.top = NULL,
padding.left = NULL,
padding.right = NULL,
border.color = NULL,
border.width = NULL,
background.color = NULL,
line_spacing = NULL,
table.layout = NULL,
cs.family = NULL,
eastasia.family = NULL,
hansi.family = NULL,
decimal.mark = NULL,
big.mark = NULL,
digits = NULL,
pct_digits = NULL,
na_str = NULL,
nan_str = NULL,
fmt_date = NULL,
fmt_datetime = NULL,
extra_css = NULL,
scroll = NULL,
table_align = "center",
split = NULL,
keep_with_next = NULL,
tabcolsep = NULL,
arraystretch = NULL,
float = NULL,
fonts_ignore = NULL,
theme_fun = NULL,
post_process_all = NULL,
post_process_pdf = NULL,
post_process_docx = NULL,
post_process_html = NULL,
post_process_pptx = NULL,
...
)
init_flextable_defaults()
}
\arguments{
\item{font.family}{single character value. When format is Word, it specifies the font to
be used to format characters in the Unicode range (U+0000-U+007F). If you
want to use non ascii characters in Word, you should also set \code{hansi.family}
to the same family name.}
\item{font.size}{font size (in point) - 0 or positive integer value.}
\item{font.color}{font color - a single character value specifying
a valid color (e.g. "#000000" or "black").}
\item{text.align}{text alignment - a single character value, expected value
is one of 'left', 'right', 'center', 'justify'.}
\item{padding}{padding (shortcut for top, bottom, left and right padding)}
\item{padding.bottom, padding.top, padding.left, padding.right}{paragraph paddings - 0 or
positive integer value.}
\item{border.color}{border color - single character value
(e.g. "#000000" or "black").}
\item{border.width}{border width in points.}
\item{background.color}{cell background color - a single character value specifying a
valid color (e.g. "#000000" or "black").}
\item{line_spacing}{space between lines of text, 1 is single line spacing, 2 is double line spacing.}
\item{table.layout}{'autofit' or 'fixed' algorithm. Default to 'autofit'.}
\item{cs.family}{optional and only for Word. Font to be used to format
characters in a complex script Unicode range. For example, Arabic
text might be displayed using the "Arial Unicode MS" font.}
\item{eastasia.family}{optional and only for Word. Font to be used to
format characters in an East Asian Unicode range. For example,
Japanese text might be displayed using the "MS Mincho" font.}
\item{hansi.family}{optional and only for Word. Font to be used to format
characters in a Unicode range which does not fall into one of the
other categories.}
\item{decimal.mark, big.mark, na_str, nan_str}{\link{formatC} arguments used by \code{\link[=colformat_num]{colformat_num()}},
\code{\link[=colformat_double]{colformat_double()}}, and \code{\link[=colformat_int]{colformat_int()}}.}
\item{digits}{\link{formatC} argument used by \code{\link[=colformat_double]{colformat_double()}}.}
\item{pct_digits}{number of digits for percentages.}
\item{fmt_date, fmt_datetime}{formats for date and datetime columns as
documented in \code{\link[=strptime]{strptime()}}. Default to '\%Y-\%m-\%d' and '\%Y-\%m-\%d \%H:\%M:\%S'.}
\item{extra_css}{css instructions to be integrated with the table.}
\item{scroll}{NULL or a list if you want to add a scroll-box.
See \strong{scroll} element of argument \code{opts_html} in function \code{\link[=set_table_properties]{set_table_properties()}}.}
\item{table_align}{default flextable alignment, supported values are 'left', 'center'
and 'right'.}
\item{split}{Word option 'Allow row to break across pages' can be
activated when TRUE.}
\item{keep_with_next}{default initialization value used by the \code{\link[=paginate]{paginate()}}
function corresponding to the Word option "keep rows together" that will
be defined in the array.}
\item{tabcolsep}{space between the text and the left/right border of its containing
cell.}
\item{arraystretch}{height of each row relative to its default
height, the default value is 1.5.}
\item{float}{type of floating placement in the PDF document, one of:
\itemize{
\item 'none' (the default value), table is placed after the preceding
paragraph.
\item 'float', table can float to a place in the text where it fits best
\item 'wrap-r', wrap text around the table positioned to the right side of the text
\item 'wrap-l', wrap text around the table positioned to the left side of the text
\item 'wrap-i', wrap text around the table positioned inside edge-near the binding
\item 'wrap-o', wrap text around the table positioned outside edge-far from the binding
}}
\item{fonts_ignore}{if TRUE, pdf-engine pdflatex can be used instead of
xelatex or lualatex. If pdflatex is used, fonts will be ignored because they are
not supported by pdflatex, whereas with the xelatex and lualatex engines they are.}
\item{theme_fun}{a single character value (the name of the theme function
to be applied) or a theme function (input is a flextable, output is a flextable).}
\item{post_process_all}{Post-processing function
that will allow you to customize the the table. It will be executed before
call to post_process_pdf(), post_process_docx(),
post_process_html(), post_process_pptx().}
\item{post_process_pdf, post_process_docx, post_process_html, post_process_pptx}{Post-processing functions
that will allow you to customize the display by output type (pdf, html, docx, pptx).
They are executed just before printing the table.}
\item{...}{unused or deprecated arguments}
}
\value{
a list containing previous default values.
}
\description{
The current formatting properties (see \code{\link[=get_flextable_defaults]{get_flextable_defaults()}})
are automatically applied to every flextable you produce.
Use \code{set_flextable_defaults()} to override them. Use \code{init_flextable_defaults()}
to re-init all values with the package defaults.
}
\examples{
ft_1 <- qflextable(head(airquality))
ft_1
old <- set_flextable_defaults(
font.color = "#AA8855",
border.color = "#8855AA"
)
ft_2 <- qflextable(head(airquality))
ft_2
do.call(set_flextable_defaults, old)
}
\seealso{
Other functions related to themes:
\code{\link{get_flextable_defaults}()},
\code{\link{theme_alafoli}()},
\code{\link{theme_apa}()},
\code{\link{theme_booktabs}()},
\code{\link{theme_box}()},
\code{\link{theme_tron}()},
\code{\link{theme_tron_legacy}()},
\code{\link{theme_vader}()},
\code{\link{theme_vanilla}()},
\code{\link{theme_zebra}()}
}
\concept{functions related to themes}
flextable/man/as_paragraph.Rd 0000644 0001762 0000144 00000003400 14375473105 015720 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/05_content.R
\name{as_paragraph}
\alias{as_paragraph}
\title{Concatenate chunks in a flextable}
\usage{
as_paragraph(..., list_values = NULL)
}
\arguments{
\item{...}{chunk elements that are defining paragraph. If a character is used,
it is transformed to a chunk object with function \code{\link[=as_chunk]{as_chunk()}}.}
\item{list_values}{a list of chunk elements that are defining paragraph. If
specified argument \code{...} is unused.}
}
\description{
The function is concatenating text and images within paragraphs of
a flextable object, this function is to be used with functions such as \code{\link[=compose]{compose()}},
\code{\link[=add_header_lines]{add_header_lines()}}, \code{\link[=add_footer_lines]{add_footer_lines()}}.
This allows the concatenation of formatted pieces of text (chunks) that
represent the content of a paragraph.
The cells of a flextable contain each a single paragraph. This paragraph
is made of chunks that can be text, images or plots, equations and links.
}
\examples{
library(flextable)
ft <- flextable(airquality[sample.int(150, size = 10), ])
ft <- compose(ft,
j = "Wind",
value = as_paragraph(
as_chunk(Wind, props = fp_text_default(color = "orange")),
" ",
minibar(value = Wind, max = max(airquality$Wind), barcol = "orange", bg = "black", height = .15)
),
part = "body"
)
ft <- autofit(ft)
ft
}
\seealso{
\code{\link[=as_chunk]{as_chunk()}}, \code{\link[=minibar]{minibar()}},
\code{\link[=as_image]{as_image()}}, \code{\link[=hyperlink_text]{hyperlink_text()}}
Other functions for mixed content paragraphs:
\code{\link{append_chunks}()},
\code{\link{compose}()},
\code{\link{prepend_chunks}()}
}
\concept{functions for mixed content paragraphs}
flextable/man/colformat_image.Rd 0000644 0001762 0000144 00000002473 14565457154 016440 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/formatters.R
\name{colformat_image}
\alias{colformat_image}
\title{Format cells as images}
\usage{
colformat_image(
x,
i = NULL,
j = NULL,
width,
height,
na_str = get_flextable_defaults()$na_str,
nan_str = get_flextable_defaults()$nan_str,
prefix = "",
suffix = ""
)
}
\arguments{
\item{x}{a flextable object}
\item{i}{rows selection}
\item{j}{columns selection.}
\item{width, height}{size of the png file in inches}
\item{na_str, nan_str}{string to be used for NA and NaN values}
\item{prefix, suffix}{string to be used as prefix or suffix}
}
\description{
Format image paths as images in a flextable.
}
\examples{
img.file <- file.path(R.home("doc"), "html", "logo.jpg")
dat <- head(iris)
dat$Species <- as.character(dat$Species)
dat[c(1, 3, 5), "Species"] <- img.file
myft <- flextable(dat)
myft <- colformat_image(
myft,
i = c(1, 3, 5),
j = "Species", width = .20, height = .15
)
ft <- autofit(myft)
ft
}
\seealso{
Other cells formatters:
\code{\link{colformat_char}()},
\code{\link{colformat_date}()},
\code{\link{colformat_datetime}()},
\code{\link{colformat_double}()},
\code{\link{colformat_int}()},
\code{\link{colformat_lgl}()},
\code{\link{colformat_num}()},
\code{\link{set_formatter}()}
}
\concept{cells formatters}
flextable/man/keep_with_next.Rd 0000644 0001762 0000144 00000003006 14566144245 016311 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/styles.R
\name{keep_with_next}
\alias{keep_with_next}
\title{Set Word 'Keep with next' instructions}
\usage{
keep_with_next(x, i = NULL, value = TRUE, part = "body")
}
\arguments{
\item{x}{a flextable object}
\item{i}{rows selection}
\item{value}{TRUE or FALSE. When applied to a group, all rows
except the last one should be flagged with attribute 'Keep with next'.}
\item{part}{partname of the table (one of 'all', 'body', 'header', 'footer')}
}
\description{
The 'Keep with next' functionality in 'Word', applied
to the rows of a table, ensures that the rows with that attribute
stays together and does not break across multiple pages.
This function allows much better control of breaks between
pages than the global \code{keep_with_next} parameter.
}
\examples{
library(flextable)
dat <- iris[c(1:25, 51:75, 101:125), ]
ft <- qflextable(dat)
ft <- keep_with_next(
x = ft,
i = c(1:24, 26:49, 51:74),
value = TRUE
)
save_as_docx(ft, path = tempfile(fileext = ".docx"))
}
\seealso{
\code{\link[=paginate]{paginate()}}
Other sugar functions for table style:
\code{\link{align}()},
\code{\link{bg}()},
\code{\link{bold}()},
\code{\link{color}()},
\code{\link{empty_blanks}()},
\code{\link{font}()},
\code{\link{fontsize}()},
\code{\link{highlight}()},
\code{\link{italic}()},
\code{\link{line_spacing}()},
\code{\link{padding}()},
\code{\link{rotate}()},
\code{\link{tab_settings}()},
\code{\link{valign}()}
}
\concept{sugar functions for table style}
flextable/man/figures/ 0000755 0001762 0000144 00000000000 14571444477 014460 5 ustar ligges users flextable/man/figures/README-diamonds-dataset-1.png 0000644 0001762 0000144 00000144112 14571444444 021475 0 ustar ligges users PNG
IHDR soâ gAMA a sRGB 3PLTEGpL b tRNS i8O
",ģ IDATx]隭2xiChɟnJ:Yd}/K^|+ V 33
y4= 6v
l= ;;x6iOgUoa6= XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXVg ~nF7?s
,`S8QGuܥ|[pH.B*M5{4y9
p&
iXKX5*|Y熞OD7
Ηp7q(4i[EΙ df_D>
lNq,4i;e >qOw74*c4i`fڵB˵S``|bQsQ>~A|V*uJ9lN oVѱ'k*es^~v@ @ib8
v(F6= 𭦝|)
JɐB8mp9ei YyهдxZ/?9
,@i@zM>KDz9a`9bj5:ܪ;Ǒмu*RXy]c{qqۏap헟PGi40,SZhuڷirCʣ>Owû|łup
o~'@KY&xa>=
4_~p@#@ N
oi@̣n7M
Ei@@ԑlaINyҀQZO4i# 9=l >=!@/[8
B&Ľ@ԑ18
t@
^J%"
ty^2<2ie!Ht
%NJ SN:.lu\ԑ18
+
i ]{ydM*a
Sve˂~'@g:Ҁ=
pp4AXz^;}\(W7CC'aoZ|geP{F
4KY4AHnjb6DEQ7Qܢ-8!;ھbΡ3"o4i6` H:H)H"[^|L&}.e/:XңroD4pN+
/{]@@i rs_D\Ls;7m?PVxg}u:PQH!ԑ18
t>ح˽UaPV:A阤o4Ow7n!]T,58QJ))]2WRwd :Hl:0*o]7 q.`}/qzQB>Nā:
tӀn 18
tcy`{g%ATY*j
}m2KOWToD4FI
VoӾ HXXzɗq|{zFo㻼ÞӰ(ĨhL"Rl*qĹ{
Kl9Mײkzq#b
ph!-X gf|{v)Mٌʢ#[ytNG@p2?i =0iQ{<|Y{ܶ!X6nKˍE
UI[4Ŋc`o-AAC<~bq#(x$i?
|=b'=y9C7(çH k# lVRcKqU b;XRno !\`gP=)8հc
P`5{D=Hd):6V *XbDP>[puJ!S(^DcJ b o !\SA&_1N*!fw<"+zLGq*Vl20urz3:&Bt;p"
MV%X17u.^Z(TA%6_GmN_2fGC{oWlxtʿcbyݺ%S8NDNJY<+I r\#lad')Mx^j6úW.]H9Tt(̀W}]\Q҆Ѳ|N/?ፆ7X/@x8NJW8+V%Y\XT4 R@Nڗ,U2Sb2&d7="$
qF=Fk/uY$'T2fJQsoD[@ ̊MK@!d IkBFhؼ~5[ZwPYh@n82+Aloݙ0 \tVAx'@ \HDb8a0we(f4Eȗ ;i}M0
fL2FxnJ.zHPx4
ȺJ#0`WT_fx68pp}N `VxJ?C"]B c5'W8v6Pi`^
dO^"DdUm8)7+ 9Oñݎh:@.D
t0P4DjT]=p5ω*f? X"Vdv;LnRc8>'^9"P g.D#a-tЀ@tM1lo+N1oi +ۤ]cH> ~ƥb^y?Ԋ7p@i@\,$(r!]92~ġdڸxѠͳB}/BwuS
q
<
)M#w%.?lË8?ånߤe讥y=>Q@ؠh(op s\GX[KeKpF^l
SGI}>l9i)A)+w͝Bz/ bܷ 8
zp3I ( tn%\S({°4` F(pE0
|P|>7q(4%K/гq[!~TƉoЃh{+H@ D˖ F29Zd'
I"
`\DE5uSs-Bp/+/(ƏtM_ 7{xE beM4"b8=( Wc?Z0X;U15b;`Tj
ݮҀB) ^\7ky]
ĺp8i$b@TɊ%x\u"UMBYBa(nV@dd'kMeyvF'e8}
}Vn
+baNFj*HU1Y bEcAĊښ@Eh>@|Sw
@6+wJX1Et~9C nP'v A F!g33k 5
C?mMR
èVPQ°wLOc2c 7 \ѽ=~_GACO#AT+x{k ad02(t~-Fe
7Ƞlr~A,8 PV WmkB ) @ P yk;mu翞Qڊ_VW4v"
|O++.e@~ @))}7ʊi;_X5NF
;eڦ2a f'zk2 vD?7KlY@ B(ke}hOP :ϥM?. @!;5vF2. (roAste
sf/⽁he
QWN@2
.}m|8ZP) aܼo滈qX@`|=T jTL-2-X.Gv P