From 7a87ccb703a8be061729a9ece8de79a3fda8ad16 Mon Sep 17 00:00:00 2001 From: David Gohel Date: Sun, 10 Dec 2023 18:39:26 +0100 Subject: [PATCH] fix: `as_flextable.data.frame()` supports 'data.table' --- .github/workflows/R-CMD-check.yaml | 4 ++-- DESCRIPTION | 2 +- NEWS.md | 1 + R/df_printer.R | 7 +++++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index aeb933e3..d5c40805 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -21,8 +21,8 @@ jobs: config: - {os: windows-latest, r: 'release', pandoc: '2.19'} - {os: macOS-latest, r: 'release', pandoc : '2.19'} - - {os: ubuntu-20.04, r: 'release', pandoc : '2.19', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - - {os: ubuntu-20.04, r: 'release', pandoc : '2.9.2.1', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: ubuntu-20.04, r: 'release', pandoc : '2.19'} + - {os: ubuntu-20.04, r: 'release', pandoc : '2.9.2.1'} - {os: ubuntu-latest, r: 'devel', pandoc : '2.19'} env: diff --git a/DESCRIPTION b/DESCRIPTION index e54e9c10..42eae62e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: flextable Type: Package Title: Functions for Tabular Reporting -Version: 0.9.5.001 +Version: 0.9.5.002 Authors@R: c( person("David", "Gohel", role = c("aut", "cre"), email = "david.gohel@ardata.fr"), diff --git a/NEWS.md b/NEWS.md index 3052a78a..c42876cf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ ## Issues - `summarizor()` don't stop anymore if table only contain discrete columns. +- `as_flextable.data.frame()` supports 'data.table' # flextable 0.9.4 diff --git a/R/df_printer.R b/R/df_printer.R index 6e7a5b27..76d4630b 100644 --- a/R/df_printer.R +++ b/R/df_printer.R @@ -246,6 +246,13 @@ as_flextable.data.frame <- function(x, show_coltype = TRUE, color_coltype = "#999999", ...) { + + if (inherits(x, "data.table")) { + x <- as.data.frame(x) + } else if (inherits(x, "tbl_df")) { + x <- as.data.frame(x) + } + if (nrow(x) == 1) { singlerow_df_printer( dat = x,