From d83f4061ea2377ded8fcc2a39cab51cf2a7c52e6 Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Mon, 18 Apr 2022 16:31:48 +0900 Subject: [PATCH 1/4] apply colformat_md on content rather than dataset --- R/colformat.R | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/R/colformat.R b/R/colformat.R index d96cf1e..3150c27 100644 --- a/R/colformat.R +++ b/R/colformat.R @@ -48,13 +48,15 @@ colformat_md <- function(x, } dataset <- x[[part]]$dataset - col <- names(tidyselect::eval_select(rlang::expr(c(!!.j)), dataset)) + content <- x[[part]][["content"]][["content"]][["data"]] + nm <- colnames(content) + col <- tidyselect::eval_select(rlang::expr(c(!!.j)), dataset[nm]) if (length(col) == 0) { return(x) } - texts <- unlist(dataset[col], use.names = FALSE) + texts <- purrr::map_chr(content[, col], paragraph2txt) # Must evaluate outside add_footnotes due to lazy evaluation of arguments ft <- flextable::compose(x, @@ -80,3 +82,14 @@ colformat_md <- function(x, where <- function(...) { tidyselect::vars_select_helpers$where(...) } + +paragraph2txt <- function(x) { + if (all(is.na(x$txt))) return(NA_character_) + + txt <- x[["txt"]] + img <- x[["img_data"]] + has_img <- !purrr::map_lgl(img, is.null) & !is.na(img) + txt[has_img] <- sprintf("![](%s)", img[has_img]) + + paste(txt[!is.na(txt)], collapse = "") +} From 2520d1020fae30b4d2055f0a3bf8027fefa24594 Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Mon, 18 Apr 2022 16:40:49 +0900 Subject: [PATCH 2/4] update NEWS --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index cc73575..ed2ac5c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # ftExtra 0.3.0.9999 * `as_paragraph_md` supports empty string, `""`, as an input (#68). +* `colformat_md` applies on actual content of flextable rather than input dataset (#72). # ftExtra 0.3.0 From 7343400374601155209a0d66a07de3bff9f6f00e Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Mon, 18 Apr 2022 16:45:06 +0900 Subject: [PATCH 3/4] update documents --- docs/404.html | 122 ++-- docs/LICENSE-text.html | 116 +--- docs/LICENSE.html | 135 ++--- docs/articles/format_columns.html | 688 ++++++++++++----------- docs/articles/group-rows.html | 546 +++++++++--------- docs/articles/index.html | 126 +---- docs/articles/transform-headers.html | 269 ++++----- docs/authors.html | 163 ++---- docs/index.html | 155 ++--- docs/news/index.html | 401 ++++++------- docs/pkgdown.css | 83 +-- docs/pkgdown.js | 4 +- docs/pkgdown.yml | 6 +- docs/reference/as_flextable_methods.html | 344 +++++------- docs/reference/as_paragraph_md.html | 242 +++----- docs/reference/colformat_md.html | 260 +++------ docs/reference/footnote_options.html | 200 ++----- docs/reference/index.html | 169 ++---- docs/reference/reexports.html | 136 ++--- docs/reference/separate_header.html | 204 +++---- docs/reference/span_header.html | 194 ++----- docs/reference/with_blanks.html | 174 ++---- docs/sitemap.xml | 63 +++ man/as_flextable_methods.Rd | 1 + 24 files changed, 1931 insertions(+), 2870 deletions(-) create mode 100644 docs/sitemap.xml diff --git a/docs/404.html b/docs/404.html index 8551d5f..2f91119 100644 --- a/docs/404.html +++ b/docs/404.html @@ -1,66 +1,27 @@ - - - - + + + + - Page not found (404) • ftExtra - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - - - -
-
- + +
+ + + - - -
+
+
-
+ + - - diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 3232a77..0ccc7cc 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -1,66 +1,12 @@ - - - - - - - -License • ftExtra - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -License • ftExtra - + + - - - -
-
- -
- -
+
+
-
- +
- - + + diff --git a/docs/LICENSE.html b/docs/LICENSE.html index 530158e..6d10fd7 100644 --- a/docs/LICENSE.html +++ b/docs/LICENSE.html @@ -1,66 +1,12 @@ - - - - - - - -MIT License • ftExtra - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -MIT License • ftExtra - + + - - - -
-
- -
- -
+
+
-
- +
- - + + diff --git a/docs/articles/format_columns.html b/docs/articles/format_columns.html index efe65bd..fd988fe 100644 --- a/docs/articles/format_columns.html +++ b/docs/articles/format_columns.html @@ -19,6 +19,8 @@ + +
+
@@ -101,31 +97,36 @@

Format columns as markdown

This vignette introduces how to format columns in flextable.

-
-

-Why markdown?

-

The flextable package is an excellent package that allows fine controls on styling tables, and export it to variety of formats (HTML, MS Word, PDF). Especially, when output format is MS Word, this package is the best solution in R.

-

On the other hand, styling texts with the flextable package often require large efforts. The following example subscripts numeric values in chemical formulas.

+library(flextable) +library(ftExtra)
+
+

Why markdown? +

+

The flextable package is an excellent package that +allows fine controls on styling tables, and export it to variety of +formats (HTML, MS Word, PDF). Especially, when output format is MS Word, +this package is the best solution in R.

+

On the other hand, styling texts with the flextable +package often require large efforts. The following example subscripts +numeric values in chemical formulas.

-df <- data.frame(Oxide = c("SiO2", "Al2O3"), stringsAsFactors = FALSE)
-ft <- flextable::flextable(df)
+df <- data.frame(Oxide = c("SiO2", "Al2O3"), stringsAsFactors = FALSE)
+ft <- flextable::flextable(df)
 
-ft %>%
-  flextable::compose(
+ft %>%
+  flextable::compose(
     i = 1, j = "Oxide",
-    value = flextable::as_paragraph(
-      "SiO", as_sub("2")
+    value = flextable::as_paragraph(
+      "SiO", as_sub("2")
     )
-  ) %>%
-  flextable::compose(
+  ) %>%
+  flextable::compose(
     i = 2, j = "Oxide",
-    value = flextable::as_paragraph(
-      "Al", as_sub("2"), "O", as_sub("3")
+    value = flextable::as_paragraph(
+      "Al", as_sub("2"), "O", as_sub("3")
     )
   )
-
+

The ftExtra package provides easy solution by introducing markdown. As markdown texts self-explain their formats by plain texts, what users have to do is manipulations of character columns with their favorite tools such as the famous dplyr and stringr packages.

+

The ftExtra package provides easy solution by +introducing markdown. As markdown texts self-explain their formats by +plain texts, what users have to do is manipulations of character columns +with their favorite tools such as the famous dplyr and +stringr packages.

  1. Preprocess a data frame to decorate texts with markdown syntax.
  2. -
  3. Convert the data frame into a flextable object with the flextable function or as_flextable function.
  4. +
  5. Convert the data frame into a flextable object with the +flextable function or as_flextable +function.
  6. Format markdown columns with colformat_md

The following example elegantly simplifies the prior example.

-df <- data.frame(Oxide = c("SiO2", "Fe2O3"), stringsAsFactors = FALSE)
+df <- data.frame(Oxide = c("SiO2", "Fe2O3"), stringsAsFactors = FALSE)
 
-df %>%
-  dplyr::mutate(Oxide = stringr::str_replace_all(Oxide, "([2-9]+)", "~\\1~")) %>%
-  flextable::flextable() %>%
+df %>%
+  dplyr::mutate(Oxide = stringr::str_replace_all(Oxide, "([2-9]+)", "~\\1~")) %>%
+  flextable::flextable() %>%
   ftExtra::colformat_md()
-
+

The colformat_md function is smart enough to detect character columns, so users can start without learning its arguments. Of course, it is possible to chose columns.

-

Another workflow is to read a markdown-formatted table from a external file. Again, markdown is by design a plain text, and can easily be embed in any formats such as CSV and Excel. So users can do something like

+

The colformat_md function is smart enough to detect +character columns, so users can start without learning its arguments. Of +course, it is possible to chose columns.

+

Another workflow is to read a markdown-formatted table from a +external file. Again, markdown is by design a plain text, and can easily +be embed in any formats such as CSV and Excel. So users can do something +like

-readr::read_csv("example.csv") %>%
-  flextable::flextable() %>%
+readr::read_csv("example.csv") %>%
+  flextable::flextable() %>%
   ftExtra::colformat_md()
-

By default, the ftExtra package employs Pandoc’s markdown, which is also employed by R Markdown. This enables consistent user experience when using the ftExtra package in R Markdown.

+

By default, the ftExtra package employs Pandoc’s +markdown, which is also employed by R Markdown. This enables consistent +user experience when using the ftExtra package in R +Markdown.

-
-

-Basic examples

-

The example below shows that colformat_md() function parses markdown texts in the flextable object.

+
+

Basic examples +

+

The example below shows that colformat_md() function +parses markdown texts in the flextable object.

-data.frame(
-  a = c("**bold**", "*italic*"),
-  b = c("^superscript^", "~subscript~"),
-  c = c("`code`", "[underline]{.underline}"),
-  d = c("*[**~ft~^Extra^**](https://ftextra.atusy.net/) is*",
+data.frame(
+  a = c("**bold**", "*italic*"),
+  b = c("^superscript^", "~subscript~"),
+  c = c("`code`", "[underline]{.underline}"),
+  d = c("*[**~ft~^Extra^**](https://ftextra.atusy.net/) is*",
         "[Cool]{.underline shading.color='skyblue'}"),
   stringsAsFactors = FALSE
-) %>%
-  as_flextable() %>%
+) %>%
+  as_flextable() %>%
   colformat_md()
-
+

The table header can also be formatted by specifying part = "header" or "all" to colformat_md()

+

The table header can also be formatted by specifying +part = "header" or "all" to +colformat_md()

Supported syntax are

  • bold
  • @@ -476,23 +499,25 @@

    Notes:

    • other syntax may result in unexpected behaviors.
    • -
    • multiple paragraphs are collapsed to a single paragraph with a separator given to the .sep argument (default: "\n\n").
    • +
    • multiple paragraphs are collapsed to a single paragraph with a +separator given to the .sep argument (default: +"\n\n").

-
-

-Footnotes

+
+

Footnotes +

An easy way to add a footnote is inline footnote.

-data.frame(
+data.frame(
   package = "ftExtra",
   description = "Extensions for 'Flextable'^[Supports of footnotes]",
   stringsAsFactors = FALSE
-) %>%
-  as_flextable() %>%
-  colformat_md() %>%
-  flextable::autofit(add_w = 0.5)
-
+

Reference symbols can be configured by footnote_options(). Of course, markdown can be used inside footnotes as well.

+

Reference symbols can be configured by +footnote_options(). Of course, markdown can be used inside +footnotes as well.

-data.frame(
+data.frame(
   package = "ftExtra^[Short of *flextable extra*]",
   description = "Extensions for 'Flextable'^[Supports of footnotes]",
   stringsAsFactors = FALSE
-) %>%
-  as_flextable() %>%
+) %>%
+  as_flextable() %>%
   colformat_md(
     .footnote_options = footnote_options(ref = "i",
                                          prefix = '[',
@@ -569,9 +596,9 @@ 

start = 2, inline = TRUE, sep = "; ") - ) %>% - flextable::autofit(add_w = 0.5)

-
+

In order to add multiple footnotes to a cell, use normal footnotes syntax.

+

In order to add multiple footnotes to a cell, use normal footnotes +syntax.

-data.frame(x = 
+data.frame(x = 
 "foo[^a]^,^ [^b]
 
 [^a]: aaa
 
 [^b]: bbb",
 stringsAsFactors = FALSE
-) %>%
-  as_flextable() %>%
+) %>%
+  as_flextable() %>%
   colformat_md()
-
+
-
-

-Images

-

Images can be inserted optionally with width and/or height attributes. Specifying one of them changes the other while keeping the aspect ratio.

+
+

Images +

+

Images can be inserted optionally with width and/or height +attributes. Specifying one of them changes the other while keeping the +aspect ratio.

-data.frame(
-  R = sprintf("![](%s)", file.path( R.home("doc"), "html", "logo.jpg" )),
+data.frame(
+  R = sprintf("![](%s)", file.path( R.home("doc"), "html", "logo.jpg" )),
   stringsAsFactors = FALSE
-) %>%
-  as_flextable() %>%
-  colformat_md() %>%
-  flextable::autofit()
-
+

The R logo is distributed by The R Foundation with the CC-BY-SA 4.0 license.

+

The R logo is distributed by The R Foundation with the CC-BY-SA 4.0 +license.

-
-

-Line breaks

+
+

Line breaks +

By default, soft line breaks becomes spaces.

-data.frame(linebreak = c("a\nb"), stringsAsFactors = FALSE) %>%
-  as_flextable() %>%
+data.frame(linebreak = c("a\nb"), stringsAsFactors = FALSE) %>%
+  as_flextable() %>%
   colformat_md()
-
+

Pandoc’s markdown supports hard line breaks by adding a backslash or double spaces at the end of a line.

+

Pandoc’s markdown supports hard line breaks by adding a backslash or +double spaces at the end of a line.

-data.frame(linebreak = c("a\\\nb"), stringsAsFactors = FALSE) %>%
-  as_flextable() %>%
+data.frame(linebreak = c("a\\\nb"), stringsAsFactors = FALSE) %>%
+  as_flextable() %>%
   colformat_md()
-
+

It is also possible to make \n as a hard line break by extending Pandoc’s Markdown.

+

It is also possible to make \n as a hard line break by +extending Pandoc’s Markdown.

-data.frame(linebreak = c("a\nb"), stringsAsFactors = FALSE) %>%
-  as_flextable() %>%
+data.frame(linebreak = c("a\nb"), stringsAsFactors = FALSE) %>%
+  as_flextable() %>%
   colformat_md(md_extensions = "+hard_line_breaks")
-
+

Markdown treats continuous linebreaks as a separator of blocks such as paragraphs. However, flextable package lacks the support for multiple paragraphs in a cell. To workaround, colformat_md collapses them to a single paragraph with a separator given to .sep (default: \n\n).

+

Markdown treats continuous linebreaks as a separator of blocks such +as paragraphs. However, flextable package lacks the +support for multiple paragraphs in a cell. To workaround, +colformat_md collapses them to a single paragraph with a +separator given to .sep (default: \n\n).

-data.frame(linebreak = c("a\n\nb"), stringsAsFactors = FALSE) %>%
-  as_flextable() %>%
+data.frame(linebreak = c("a\n\nb"), stringsAsFactors = FALSE) %>%
+  as_flextable() %>%
   colformat_md(.sep = "\n\n")
-
+
-
-

-Citations

-

Citations is experimentally supported. Note that there are no citation lists. It is expected to be produced by using R Markdown.

+
+

Citations +

+

Citations is experimentally supported. Note that there are no +citation lists. It is expected to be produced by using R Markdown.

First, create a ftExtra.bib file like below.

-
@Manual{R-ftExtra,
-  title = {ftExtra: Extensions for Flextable},
-  author = {Atsushi Yasumoto},
-  year = {2022},
-  note = {https://ftextra.atusy.net},
-}
+
@Manual{R-ftExtra,
+  title = {ftExtra: Extensions for Flextable},
+  author = {Atsushi Yasumoto},
+  year = {2022},
+  note = {https://ftextra.atusy.net},
+}

Second, specify it within the YAML front matter.

-
---
-bibliography: ftExtra.bib
----
+
---
+bibliography: ftExtra.bib
+---

Finally, cite the references within tables.

-data.frame(
-  Cite = c("@R-ftExtra", "[@R-ftExtra]", "[-@R-ftExtra]"),
+data.frame(
+  Cite = c("@R-ftExtra", "[@R-ftExtra]", "[-@R-ftExtra]"),
   stringsAsFactors = FALSE
-) %>%
-  as_flextable() %>%
-  colformat_md() %>%
-  flextable::autofit(add_w = 0.2)
-
+

If citation style such as Vancouver requires citations be numbered sequentially and consistently with the body, manually offset the number for example by colformat_md(.cite_offset = 5).

+

If citation style such as Vancouver requires citations be numbered +sequentially and consistently with the body, manually offset the number +for example by colformat_md(.cite_offset = 5).

-
-

-Math

+
+

Math +

The rendering of math is also possible.

-data.frame(math = "$e^{i\\theta} = \\cos \\theta + i \\sin \\theta$",
-           stringsAsFactors = FALSE) %>%
-  as_flextable() %>%
-  colformat_md() %>%
-  flextable::autofit(add_w = 0.2)
-
+

Note that results can be insufficient. This feature relies on Pandoc’s HTML writer, which

+

Note that results can be insufficient. This feature relies on +Pandoc’s HTML writer, which

-

render TeX math as far as possible using Unicode characters
https://pandoc.org/MANUAL.html#math-rendering-in-html

+

render TeX math as far as possible using Unicode characters
https://pandoc.org/MANUAL.html#math-rendering-in-html

-
-

-Emoji

-

Pandoc’s markdown provides an extension, emoji. To use it with colformat_md(), specify md_extensions="+emoji".

+
+

Emoji +

+

Pandoc’s markdown provides an extension, emoji. To use +it with colformat_md(), specify +md_extensions="+emoji".

-data.frame(emoji = c(":+1:"), stringsAsFactors = FALSE) %>%
-  as_flextable() %>%
+data.frame(emoji = c(":+1:"), stringsAsFactors = FALSE) %>%
+  as_flextable() %>%
   colformat_md(md_extensions = "+emoji")
-
+
-
-

-Other input formats

-

colformat_md supports variety of formats. They can even be HTML despite the name of the function.

+
+

Other input formats +

+

colformat_md supports variety of formats. They can even +be HTML despite the name of the function.

-data.frame(
+data.frame(
   x = "H<sub>2</sub>O",
   stringsAsFactors = FALSE
-) %>%
-  as_flextable() %>%
+) %>%
+  as_flextable() %>%
   colformat_md(.from = "html")
-
+

Note that multiple paragraphs are not supported if .from is not "markdown". Below is an example with commonmark.

+

Note that multiple paragraphs are not supported if .from +is not "markdown". Below is an example with commonmark.

-data.frame(
+data.frame(
   x = "foo\n\nbar",
   stringsAsFactors = FALSE
-) %>%
-  as_flextable() %>%
+) %>%
+  as_flextable() %>%
   colformat_md(.from = "commonmark")
-
+
+
-

This vignette introduces nice and easy way to display grouped data frame created by dplyr::group_by.

+

This vignette introduces nice and easy way to display grouped data +frame created by dplyr::group_by.

+library(ftExtra) +library(dplyr)
-grouped_iris <- iris %>%
-  group_by(Species) %>%
-  slice(1, 2)
+grouped_iris <- iris %>%
+  group_by(Species) %>%
+  slice(1, 2)
 
-grouped_mtcars <- mtcars %>%
-  mutate(model = rownames(mtcars)) %>%
-  head %>%
-  select(model, cyl, mpg, disp, am) %>%
-  group_by(am, cyl)
-
-

-Groups as titles

-
-

-Single grouping columns

+grouped_mtcars <- mtcars %>% + mutate(model = rownames(mtcars)) %>% + head %>% + select(model, cyl, mpg, disp, am) %>% + group_by(am, cyl)
+
+

Groups as titles +

+
+

Single grouping columns +

-grouped_iris %>% as_flextable()
-
+
-grouped_iris %>% as_flextable(hide_grouplabel = TRUE)
-
+
-
-

-Multiple grouping columns

+
+

Multiple grouping columns +

-grouped_mtcars %>% as_flextable()
-
+
-
-

-Groups as merged columns

-

By specifying as_flextable(groups_to = 'merged'), grouping variables are merged vertically. In this case, the default theme is changed to flextable::theme_vanilla because the booktab theme is not intuitive.

-
-

-Single grouping variable

+
+

Groups as merged columns +

+

By specifying as_flextable(groups_to = 'merged'), +grouping variables are merged vertically. In this case, the default +theme is changed to flextable::theme_vanilla because the +booktab theme is not intuitive.

+
+

Single grouping variable +

-grouped_iris %>%
-  as_flextable(groups_to = "merged")
-
+
-
-

-Multiple grouping variables

+
+

Multiple grouping variables +

-grouped_mtcars %>%
-  as_flextable(groups_to = "merged") %>%
-  flextable::theme_vanilla()
-
+
-
-

-Position of grouping variables

-

Grouping variables are moved to left by default. If you want to keep their positions, specify group_pos = 'asis'.

+
+

Position of grouping variables +

+

Grouping variables are moved to left by default. If you want to keep +their positions, specify group_pos = 'asis'.

-grouped_mtcars %>%
-  as_flextable(groups_to = "merged", groups_pos = "asis") %>%
-  flextable::theme_vanilla()
-
+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Articles • ftExtra - + + - - - -
-
- -
- -
+
+
Format columns as markdown
+
+
Group rows
+
+
Create multi level headers
+
+
-
- +
- - + + diff --git a/docs/articles/transform-headers.html b/docs/articles/transform-headers.html index ae068c1..fe65c8d 100644 --- a/docs/articles/transform-headers.html +++ b/docs/articles/transform-headers.html @@ -19,6 +19,8 @@ + +
+
@@ -101,14 +97,14 @@

Create multi level headers

This vignette introduces how to create multi level headers.

-
-

-Prepare flextable

+library(ftExtra)
+
+

Prepare flextable +

-ft <- iris[1:2, ] %>% as_flextable
+ft <- iris[1:2, ] %>% as_flextable
 ft
-
+
-
-

-Separate headers

-

The separate_header() function generates multi-level headers by separating original headers (row names) by delimiters.

+
+

Separate headers +

+

The separate_header() function generates multi-level +headers by separating original headers (row names) by delimiters.

-ft %>% separate_header()
-
+

The sep argument defines delimiters by regular expression. The default delimiters are . and _. Let’s see what happens when seop = "e"

+

The sep argument defines delimiters by regular +expression. The default delimiters are . and +_. Let’s see what happens when seop = "e"

-ft %>% separate_header(sep = "e")
-
+
-
-

-Span headers

-

The span_header() function also generates multi-level headers. Unlike the separate_header() function, the span_header() function merges adjacent headers if they have same values.

+
+

Span headers +

+

The span_header() function also generates multi-level +headers. Unlike the separate_header() function, the +span_header() function merges adjacent headers if they have +same values.

-ft %>% span_header()
-
+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Authors and Citation • ftExtra - + + - - - - -
-
-
- -
+
- @@ -152,22 +102,21 @@

Authors

-
- +
- - + + diff --git a/docs/index.html b/docs/index.html index 068cc04..6f68344 100644 --- a/docs/index.html +++ b/docs/index.html @@ -21,6 +21,8 @@ + +
-
- +
+ -

The ftExtra package provides helper functions for the flextable package:

+

The ftExtra package provides helper functions for the flextable +package:

  • colformat_md parses markdown texts in columns
  • @@ -102,61 +99,61 @@ span_header makes multi-level headers
  • and more!
-
-

-Installation

-
-

-from CRAN

+
+

Installation +

+
+

from CRAN +

-install.packages("ftExtra")
+install.packages("ftExtra")
-
-

-from GitHub

+
+

from GitHub +

-options(repos = c(atusy = 'https://atusy.r-universe.dev', getOption("repos")))
-install.packages("ftExtra")
+options(repos = c(atusy = 'https://atusy.r-universe.dev', getOption("repos"))) +install.packages("ftExtra")
-
-

-Example

+
+

Example +

-
-

-Parse markdown texts

+library(ftExtra)
+
+

Parse markdown texts +

-data.frame(
-  x = c("**bold**", "*italic*"),
-  y = c("^superscript^", "~subscript~"),
-  z = c("***~ft~^Extra^** is*", "*Cool*"),
+data.frame(
+  x = c("**bold**", "*italic*"),
+  y = c("^superscript^", "~subscript~"),
+  z = c("***~ft~^Extra^** is*", "*Cool*"),
   stringsAsFactors = FALSE
-) %>%
-  as_flextable() %>%
+) %>%
+  as_flextable() %>%
   colformat_md()

-
-

-Span headers

+
+

Span headers +

-iris %>%
-  head %>%
-  as_flextable() %>%
+iris %>%
+  head %>%
+  as_flextable() %>%
   span_header()

-
-

-Group rows

+
+

Group rows +

-library(dplyr, warn.conflicts = FALSE)
-iris %>%
-  group_by(Species) %>%
-  slice(1:2) %>%
-  as_flextable()
+library(dplyr, warn.conflicts = FALSE) +iris %>% + group_by(Species) %>% + slice(1:2) %>% + as_flextable()

@@ -165,50 +162,60 @@

- - + + diff --git a/docs/reference/as_paragraph_md.html b/docs/reference/as_paragraph_md.html index 1d75c89..d191cf1 100644 --- a/docs/reference/as_paragraph_md.html +++ b/docs/reference/as_paragraph_md.html @@ -1,67 +1,12 @@ - - - - - - - -Convert a character vector into markdown paragraph(s) — as_paragraph_md • ftExtra - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Convert a character vector into markdown paragraph(s) — as_paragraph_md • ftExtra - - + + - - -
-
- -
- -
+
@@ -138,100 +68,84 @@

Convert a character vector into markdown paragraph(s)

Parse markdown cells and returns the "paragraph" object.

-
as_paragraph_md(
-  x,
-  auto_color_link = "blue",
-  md_extensions = NULL,
-  pandoc_args = NULL,
-  replace_na = "",
-  .from = "markdown+autolink_bare_uris",
-  .footnote_options = NULL,
-  ...
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
x

A character vector.

auto_color_link

A color of the link texts.

md_extensions

Pandoc's extensions. Although it is prefixed with "md", extensions for any +

+
as_paragraph_md(
+  x,
+  auto_color_link = "blue",
+  md_extensions = NULL,
+  pandoc_args = NULL,
+  replace_na = "",
+  .from = "markdown+autolink_bare_uris",
+  .footnote_options = NULL,
+  ...
+)
+
+ +
+

Arguments

+
x
+

A character vector.

+
auto_color_link
+

A color of the link texts.

+
md_extensions
+

Pandoc's extensions. Although it is prefixed with "md", extensions for any formats specified to .from can be used. See -https://www.pandoc.org/MANUAL.html#extensions for details.

pandoc_args

Additional command line options to pass to pandoc

replace_na

A value to replace NA (default = "").

.from

Pandoc's --from argument (default: 'markdown+autolink_bare_uris').

.footnote_options

Options for footnotes generated by footnote_options().

...

Arguments passed to internal functions.

- - -

Examples

-
if (rmarkdown::pandoc_available("2.0.6")) { - library(flextable) - ft <- flextable( - data.frame( - x = c("**foo** bar", "***baz***", "*qux*"), - stringsAsFactors = FALSE - ) - ) - ft <- compose(ft, j = "x", i = 1:2, value = as_paragraph_md(x)) - autofit(ft) -} -
#> a flextable object. -#> col_keys: `x` -#> header has 1 row(s) -#> body has 3 row(s) -#> original dataset sample: -#> [1] "**foo** bar" "***baz***" "*qux*"
+https://www.pandoc.org/MANUAL.html#extensions for details.

+
pandoc_args
+

Additional command line options to pass to pandoc

+
replace_na
+

A value to replace NA (default = "").

+
.from
+

Pandoc's --from argument (default: 'markdown+autolink_bare_uris').

+
.footnote_options
+

Options for footnotes generated by footnote_options().

+
...
+

Arguments passed to internal functions.

+
+ +
+

Examples

+
if (rmarkdown::pandoc_available("2.0.6")) {
+  library(flextable)
+  ft <- flextable(
+    data.frame(
+      x = c("**foo** bar", "***baz***", "*qux*"),
+      stringsAsFactors = FALSE
+    )
+  )
+  ft <- compose(ft, j = "x", i = 1:2, value = as_paragraph_md(x))
+  autofit(ft)
+}
+#> a flextable object.
+#> col_keys: `x` 
+#> header has 1 row(s) 
+#> body has 3 row(s) 
+#> original dataset sample: 
+#> [1] "**foo** bar" "***baz***"   "*qux*"      
+
+
+

-
- +
- - + + diff --git a/docs/reference/colformat_md.html b/docs/reference/colformat_md.html index c87c48a..21f8223 100644 --- a/docs/reference/colformat_md.html +++ b/docs/reference/colformat_md.html @@ -1,67 +1,12 @@ - - - - - - - -Format character columns as markdown text — colformat_md • ftExtra - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Format character columns as markdown text — colformat_md • ftExtra - - + + - - -
-
- -
- -
+
@@ -138,111 +68,91 @@

Format character columns as markdown text

Format character columns as markdown text

-
colformat_md(
-  x,
-  j = where(is.character),
-  part = c("body", "header", "all"),
-  auto_color_link = "blue",
-  md_extensions = NULL,
-  pandoc_args = NULL,
-  replace_na = "",
-  .from = "markdown+autolink_bare_uris",
-  .footnote_options = footnote_options(),
-  .sep = "\n\n"
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
x

A flextable object

j

Columns to be treated as markdown texts. -Selection can be done by the semantics of dplyr::select().

part

One of "body", "header", and "all". If "all", formatting proceeds in the -order of "header" and "body".

auto_color_link

A color of the link texts.

md_extensions

Pandoc's extensions. Although it is prefixed with "md", extensions for any +

+
colformat_md(
+  x,
+  j = where(is.character),
+  part = c("body", "header", "all"),
+  auto_color_link = "blue",
+  md_extensions = NULL,
+  pandoc_args = NULL,
+  replace_na = "",
+  .from = "markdown+autolink_bare_uris",
+  .footnote_options = footnote_options(),
+  .sep = "\n\n"
+)
+
+ +
+

Arguments

+
x
+

A flextable object

+
j
+

Columns to be treated as markdown texts. +Selection can be done by the semantics of dplyr::select().

+
part
+

One of "body", "header", and "all". If "all", formatting proceeds in the +order of "header" and "body".

+
auto_color_link
+

A color of the link texts.

+
md_extensions
+

Pandoc's extensions. Although it is prefixed with "md", extensions for any formats specified to .from can be used. See -https://www.pandoc.org/MANUAL.html#extensions for details.

pandoc_args

Additional command line options to pass to pandoc

replace_na

A value to replace NA (default = "").

.from

Pandoc's --from argument (default: 'markdown+autolink_bare_uris').

.footnote_options

Options for footnotes generated by footnote_options().

.sep

A separator of paragraphs (default: "\n\n")

- - -

Examples

-
if (rmarkdown::pandoc_available("2.0.6")) { - d <- data.frame( - x = c("**bold**", "*italic*"), - y = c("^superscript^", "~subscript~"), - z = c("***^ft^~Extra~** is*", "*Cool*") - ) - colformat_md(flextable::flextable(d)) -} -
#> a flextable object. -#> col_keys: `x`, `y`, `z` -#> header has 1 row(s) -#> body has 2 row(s) -#> original dataset sample: -#> x y z -#> 1 **bold** ^superscript^ ***^ft^~Extra~** is* -#> 2 *italic* ~subscript~ *Cool*
+https://www.pandoc.org/MANUAL.html#extensions for details.

+
pandoc_args
+

Additional command line options to pass to pandoc

+
replace_na
+

A value to replace NA (default = "").

+
.from
+

Pandoc's --from argument (default: 'markdown+autolink_bare_uris').

+
.footnote_options
+

Options for footnotes generated by footnote_options().

+
.sep
+

A separator of paragraphs (default: "\n\n")

+
+ +
+

Examples

+
if (rmarkdown::pandoc_available("2.0.6")) {
+  d <- data.frame(
+    x = c("**bold**", "*italic*"),
+    y = c("^superscript^", "~subscript~"),
+    z = c("***^ft^~Extra~** is*", "*Cool*")
+  )
+  colformat_md(flextable::flextable(d))
+}
+#> a flextable object.
+#> col_keys: `x`, `y`, `z` 
+#> header has 1 row(s) 
+#> body has 2 row(s) 
+#> original dataset sample: 
+#>          x             y                    z
+#> 1 **bold** ^superscript^ ***^ft^~Extra~** is*
+#> 2 *italic*   ~subscript~               *Cool*
+
+
+
-
- +
- - + + diff --git a/docs/reference/footnote_options.html b/docs/reference/footnote_options.html index 07a243a..6246e64 100644 --- a/docs/reference/footnote_options.html +++ b/docs/reference/footnote_options.html @@ -1,67 +1,12 @@ - - - - - - - -Options for footnotes — footnote_options • ftExtra - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Options for footnotes — footnote_options • ftExtra - - + + - - -
-
- -
- -
+
@@ -138,79 +68,67 @@

Options for footnotes

Configure options for footnotes.

-
footnote_options(
-  ref = c("1", "a", "A", "i", "I", "*"),
-  prefix = "",
-  suffix = "",
-  start = 1L,
-  max = 26L,
-  inline = FALSE,
-  sep = "; "
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - -
ref

One of "1", "a", "A", "i", "I", or "*" to as a choice for a symbol to -cross-reference footnotes.

prefix, suffix

Pre- and suf-fixes for ref (default: "").

start

A starting number of footnotes.

max

A max number of footnotes.

inline

whether to add footnote on same line as previous footnote or not

sep

inline = T, character string to use as a separator between footnotes

- -

Value

+
+
footnote_options(
+  ref = c("1", "a", "A", "i", "I", "*"),
+  prefix = "",
+  suffix = "",
+  start = 1L,
+  max = 26L,
+  inline = FALSE,
+  sep = "; "
+)
+
+
+

Arguments

+
ref
+

One of "1", "a", "A", "i", "I", or "*" to as a choice for a symbol to +cross-reference footnotes.

+
prefix, suffix
+

Pre- and suf-fixes for ref (default: "").

+
start
+

A starting number of footnotes.

+
max
+

A max number of footnotes.

+
inline
+

whether to add footnote on same line as previous footnote or not

+
sep
+

inline = T, character string to use as a separator between footnotes

+
+
+

Value

An environment

+
-

Examples

-
o <- footnote_options("1", start = 1L) - -
+
+

Examples

+
o <- footnote_options("1", start = 1L)
+
+
+
+
-
- +
- - + + diff --git a/docs/reference/index.html b/docs/reference/index.html index dd86f8f..1710f33 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -1,66 +1,12 @@ - - - - - - - -Function reference • ftExtra - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Function reference • ftExtra + + - - - - -
-
- -
- -
+
- - - - - - - - - - -
-

All functions

+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+

All functions

+

as_flextable(<grouped_df>) as_flextable(<data.frame>)

method to convert object to flextable

+

as_paragraph_md()

Convert a character vector into markdown paragraph(s)

+

colformat_md()

Format character columns as markdown text

+

footnote_options()

Options for footnotes

+

separate_header()

Separate the header based on delimiters

+

span_header()

Span the header based on delimiters

+

with_blanks()

Specify blank columns easily via col_keys

- +
+
-
- +
- - + + diff --git a/docs/reference/reexports.html b/docs/reference/reexports.html index f3172b2..845906b 100644 --- a/docs/reference/reexports.html +++ b/docs/reference/reexports.html @@ -1,74 +1,23 @@ - - - - - - - -Objects exported from other packages — reexports • ftExtra - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Objects exported from other packages — reexports • ftExtra + flextable +as_flextable + magrittr +%&gt;% - - - - - - - - - + + -
-
- -
- -
+

These objects are imported from other packages. Follow the links below to see their documentation.

-
-
flextable

as_flextable

+
flextable
+

as_flextable

-
magrittr

%>%

-
-
+
magrittr
+

%>%

+ +
+
-
- +
- - + + diff --git a/docs/reference/separate_header.html b/docs/reference/separate_header.html index d490dfa..00b7c4d 100644 --- a/docs/reference/separate_header.html +++ b/docs/reference/separate_header.html @@ -1,67 +1,12 @@ - - - - - - - -Separate the header based on delimiters — separate_header • ftExtra - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Separate the header based on delimiters — separate_header • ftExtra - - + + - - -
-
- -
- -
+
@@ -138,82 +68,74 @@

Separate the header based on delimiters

Separate the header based on delimiters

-
separate_header(
-  x,
-  sep = "[_\\.]",
-  theme_fun = flextable::theme_booktabs,
-  ...
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - -
x

A flextable object`

sep

Separator between columns.

+
+
separate_header(
+  x,
+  sep = "[_\\.]",
+  theme_fun = flextable::theme_booktabs,
+  ...
+)
+
+ +
+

Arguments

+
x
+

A flextable object`

+
sep
+

Separator between columns.

If character, sep is interpreted as a regular expression. The default value is a regular expression that matches any sequence of non-alphanumeric values.

If numeric, sep is interpreted as character positions to split at. Positive values start at 1 at the far-left of the string; negative value start at -1 at the far-right of the string. The length of sep should be one less than -into.

theme_fun

deprecated, use set_flextable_defaults() instead.

...

Passed to theme_fun

- - -

Examples

-
iris %>% - as_flextable() %>% - separate_header() -
#> a flextable object. -#> col_keys: `Sepal.Length`, `Sepal.Width`, `Petal.Length`, `Petal.Width`, `Species` -#> header has 2 row(s) -#> body has 150 row(s) -#> original dataset sample: -#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species -#> 1 5.1 3.5 1.4 0.2 setosa -#> 2 4.9 3.0 1.4 0.2 setosa -#> 3 4.7 3.2 1.3 0.2 setosa -#> 4 4.6 3.1 1.5 0.2 setosa -#> 5 5.0 3.6 1.4 0.2 setosa
+into.

+
theme_fun
+

deprecated, use set_flextable_defaults() instead.

+
...
+

Passed to theme_fun

+
+ +
+

Examples

+
iris %>%
+  as_flextable() %>%
+  separate_header()
+#> a flextable object.
+#> col_keys: `Sepal.Length`, `Sepal.Width`, `Petal.Length`, `Petal.Width`, `Species` 
+#> header has 2 row(s) 
+#> body has 150 row(s) 
+#> original dataset sample: 
+#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
+#> 1          5.1         3.5          1.4         0.2  setosa
+#> 2          4.9         3.0          1.4         0.2  setosa
+#> 3          4.7         3.2          1.3         0.2  setosa
+#> 4          4.6         3.1          1.5         0.2  setosa
+#> 5          5.0         3.6          1.4         0.2  setosa
+
+
+
-
- +
- - + + diff --git a/docs/reference/span_header.html b/docs/reference/span_header.html index 20dcad6..6d4e5eb 100644 --- a/docs/reference/span_header.html +++ b/docs/reference/span_header.html @@ -1,67 +1,12 @@ - - - - - - - -Span the header based on delimiters — span_header • ftExtra - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Span the header based on delimiters — span_header • ftExtra - - + + - - -
-
- -
- -
+
@@ -138,77 +68,69 @@

Span the header based on delimiters

Span the header based on delimiters

-
span_header(x, sep = "[_\\.]", theme_fun = flextable::theme_booktabs, ...)
- -

Arguments

- - - - - - - - - - - - - - - - - - -
x

A flextable object`

sep

Separator between columns.

+
+
span_header(x, sep = "[_\\.]", theme_fun = flextable::theme_booktabs, ...)
+
+ +
+

Arguments

+
x
+

A flextable object`

+
sep
+

Separator between columns.

If character, sep is interpreted as a regular expression. The default value is a regular expression that matches any sequence of non-alphanumeric values.

If numeric, sep is interpreted as character positions to split at. Positive values start at 1 at the far-left of the string; negative value start at -1 at the far-right of the string. The length of sep should be one less than -into.

theme_fun

deprecated, use set_flextable_defaults() instead.

...

Passed to theme_fun

- - -

Examples

-
iris %>% - as_flextable() %>% - span_header() -
#> a flextable object. -#> col_keys: `Sepal.Length`, `Sepal.Width`, `Petal.Length`, `Petal.Width`, `Species` -#> header has 2 row(s) -#> body has 150 row(s) -#> original dataset sample: -#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species -#> 1 5.1 3.5 1.4 0.2 setosa -#> 2 4.9 3.0 1.4 0.2 setosa -#> 3 4.7 3.2 1.3 0.2 setosa -#> 4 4.6 3.1 1.5 0.2 setosa -#> 5 5.0 3.6 1.4 0.2 setosa
+into.

+
theme_fun
+

deprecated, use set_flextable_defaults() instead.

+
...
+

Passed to theme_fun

+
+ +
+

Examples

+
iris %>%
+  as_flextable() %>%
+  span_header()
+#> a flextable object.
+#> col_keys: `Sepal.Length`, `Sepal.Width`, `Petal.Length`, `Petal.Width`, `Species` 
+#> header has 2 row(s) 
+#> body has 150 row(s) 
+#> original dataset sample: 
+#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
+#> 1          5.1         3.5          1.4         0.2  setosa
+#> 2          4.9         3.0          1.4         0.2  setosa
+#> 3          4.7         3.2          1.3         0.2  setosa
+#> 4          4.6         3.1          1.5         0.2  setosa
+#> 5          5.0         3.6          1.4         0.2  setosa
+
+
+
-
- +
- - + + diff --git a/docs/reference/with_blanks.html b/docs/reference/with_blanks.html index af9338b..cee4d83 100644 --- a/docs/reference/with_blanks.html +++ b/docs/reference/with_blanks.html @@ -1,67 +1,12 @@ - - - - - - - -Specify blank columns easily via col_keys — with_blanks • ftExtra - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Specify blank columns easily via col_keys — with_blanks • ftExtra - - + + - - -
-
- -
- -
+
@@ -138,58 +68,56 @@

Specify blank columns easily via col_keys

Specify blank columns easily via col_keys

-
with_blanks(after = NULL, before = NULL)
- -

Arguments

- - - - - - -
after, before

Blank columns are added after/before the selected columns. -Selections can be done by the semantics of dplyr::select.

- - -

Examples

-
iris %>% - as_flextable(col_keys = with_blanks(dplyr::ends_with("Width"))) -
#> a flextable object. -#> col_keys: `Sepal.Length`, `Sepal.Width`, `..after1`, `Petal.Length`, `Petal.Width`, `..after2`, `Species` -#> header has 1 row(s) -#> body has 150 row(s) -#> original dataset sample: -#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species ..after1 ..after2 -#> 1 5.1 3.5 1.4 0.2 setosa -#> 2 4.9 3.0 1.4 0.2 setosa -#> 3 4.7 3.2 1.3 0.2 setosa -#> 4 4.6 3.1 1.5 0.2 setosa -#> 5 5.0 3.6 1.4 0.2 setosa
+
+
with_blanks(after = NULL, before = NULL)
+
+ +
+

Arguments

+
after, before
+

Blank columns are added after/before the selected columns. +Selections can be done by the semantics of dplyr::select.

+
+ +
+

Examples

+
iris %>%
+  as_flextable(col_keys = with_blanks(dplyr::ends_with("Width")))
+#> a flextable object.
+#> col_keys: `Sepal.Length`, `Sepal.Width`, `..after1`, `Petal.Length`, `Petal.Width`, `..after2`, `Species` 
+#> header has 1 row(s) 
+#> body has 150 row(s) 
+#> original dataset sample: 
+#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species ..after1 ..after2
+#> 1          5.1         3.5          1.4         0.2  setosa                  
+#> 2          4.9         3.0          1.4         0.2  setosa                  
+#> 3          4.7         3.2          1.3         0.2  setosa                  
+#> 4          4.6         3.1          1.5         0.2  setosa                  
+#> 5          5.0         3.6          1.4         0.2  setosa                  
+
+
+
-
- +
- - + + diff --git a/docs/sitemap.xml b/docs/sitemap.xml new file mode 100644 index 0000000..745254f --- /dev/null +++ b/docs/sitemap.xml @@ -0,0 +1,63 @@ + + + + /404.html + + + /LICENSE-text.html + + + /LICENSE.html + + + /articles/format_columns.html + + + /articles/group-rows.html + + + /articles/index.html + + + /articles/transform-headers.html + + + /authors.html + + + /format_columns.html + + + /index.html + + + /news/index.html + + + /reference/as_flextable_methods.html + + + /reference/as_paragraph_md.html + + + /reference/colformat_md.html + + + /reference/footnote_options.html + + + /reference/index.html + + + /reference/reexports.html + + + /reference/separate_header.html + + + /reference/span_header.html + + + /reference/with_blanks.html + + diff --git a/man/as_flextable_methods.Rd b/man/as_flextable_methods.Rd index 4b0ba4e..13ad09c 100644 --- a/man/as_flextable_methods.Rd +++ b/man/as_flextable_methods.Rd @@ -58,5 +58,6 @@ Other as_flextable methods: \code{\link[flextable]{as_flextable.grouped_data}()}, \code{\link[flextable]{as_flextable.htest}()}, \code{\link[flextable]{as_flextable.lm}()}, +\code{\link[flextable]{as_flextable.tabulator}()}, \code{\link[flextable]{as_flextable.xtable}()} } From 23d4e5f1cc646f02decf76288ebcfef83b68b439 Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Mon, 18 Apr 2022 22:57:11 +0900 Subject: [PATCH 4/4] build documents --- docs/articles/format_columns.html | 318 ++++++++++---------- docs/articles/group-rows.html | 424 +++++++++++++-------------- docs/articles/transform-headers.html | 202 ++++++------- docs/news/index.html | 2 + docs/pkgdown.yml | 2 +- 5 files changed, 475 insertions(+), 473 deletions(-) diff --git a/docs/articles/format_columns.html b/docs/articles/format_columns.html index fd988fe..66857ab 100644 --- a/docs/articles/format_columns.html +++ b/docs/articles/format_columns.html @@ -126,7 +126,7 @@

Why markdown?"Al", as_sub("2"), "O", as_sub("3") ) )

-
+
 grouped_iris %>% as_flextable(hide_grouplabel = TRUE)
-
+