Skip to content

Commit

Permalink
Merge pull request #95 from atusy/deprecate
Browse files Browse the repository at this point in the history
deprecate functions masking flextable's implementations...
  • Loading branch information
atusy authored Sep 20, 2023
2 parents 4587af7 + b03b9aa commit 88dd535
Show file tree
Hide file tree
Showing 32 changed files with 829 additions and 551 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/rhub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# R-hub's genetic GitHub Actions workflow file. It's canonical location is at
# https://github.com/r-hub/rhub2/blob/v1/inst/workflow/rhub.yaml
# You can update this file to a newer version using the rhub2 package:
#
# rhub2::rhub_setup()
#
# It is unlikely that you need to modify this file manually.

name: R-hub
run-name: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }} (${{ github.event.inputs.id }})

on:
workflow_dispatch:
inputs:
config:
description: 'A comma separated list of R-hub platforms to use.'
type: string
default: 'linux,windows,macos'
name:
description: 'Run name. You can leave this empty now.'
type: string
id:
description: 'Unique ID. You can leave this empty now.'
type: string

jobs:

setup:
runs-on: ubuntu-latest
outputs:
containers: ${{ steps.rhub-setup.outputs.containers }}
platforms: ${{ steps.rhub-setup.outputs.platforms }}

steps:
# NO NEED TO CHECKOUT HERE
- uses: r-hub/rhub2/actions/rhub-setup@v1
with:
config: ${{ github.event.inputs.config }}
id: rhub-setup

linux-containers:
needs: setup
if: ${{ needs.setup.outputs.containers != '[]' }}
runs-on: ubuntu-latest
name: ${{ matrix.config.label }}
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.setup.outputs.containers) }}
container:
image: ${{ matrix.config.container }}

steps:
- uses: actions/checkout@v3
- uses: r-hub/rhub2/actions/rhub-check@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}

other-platforms:
needs: setup
if: ${{ needs.setup.outputs.platforms != '[]' }}
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.label }}
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.setup.outputs.platforms) }}

steps:
- uses: actions/checkout@v3
- uses: r-hub/rhub2/actions/rhub-setup-r@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
- uses: r-hub/rhub2/actions/rhub-check@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ export("%>%")
export(as_flextable)
export(as_paragraph_md)
export(colformat_md)
export(flextable)
export(footnote_options)
export(separate_header)
export(span_header)
export(split_header)
export(with_blanks)
importFrom(flextable,as_flextable)
importFrom(flextable,flextable)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# ftExtra 0.6.1

* Deprecated functions masking the corresponding ones from the **flextable** package (#95)

* Renamed `separate_header` to `split_header` (#95)

* Fixed a wrong escape regex in the `sep` parameter of `split_header`, `span_header`, and `separate_header` (#95)

# ftExtra 0.6.0

* Fix `footnote_options` not controlling reference symbols correctly. Formerly, only symbols in the cells used the `prefix` and the `suffix` arguments. Now, footnote texts also respects them (#88).
Expand Down
12 changes: 11 additions & 1 deletion R/as-flextable.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ as_flextable.grouped_df <- function(
x %>%
dplyr::ungroup() %>%
flextable::as_grouped_data(g) %>%
as_flextable(...)
flextable::as_flextable(...)
)
}

Expand Down Expand Up @@ -79,6 +79,16 @@ as_flextable.grouped_df <- function(
#' as_flextable()
#' @export
as_flextable.data.frame <- function(x, col_keys = names(x), ...) {
.Deprecated(
"flextable:::as_flextable.data.frame",
msg = paste(
"ftExtra:::as_flextable.data.frame is deprecated",
"and will be removed in the future release.",
"Consider using flextalbe's implementation by running",
'`.S3method("as_flextable", "data.frame",',
"flextable:::as_flextable.data.frame)`"
)
)
if (is.function(col_keys)) col_keys <- col_keys(x)
flextable::flextable(x, col_keys = col_keys, ...)
}
2 changes: 1 addition & 1 deletion R/footnote.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#'
#' @examples
#' # A examole flextable with unprocessed markdown footnotes
#' ft <- as_flextable(tibble::tibble(
#' ft <- flextable(tibble::tibble(
#' "header1^[note a]" = c("x^[note 1]", "y"),
#' "header2" = c("a", "b^[note 2]")
#' ))
Expand Down
4 changes: 4 additions & 0 deletions R/ftExtra.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
#' @importFrom magrittr %>%
#' @export
magrittr::`%>%`

#' @importFrom flextable flextable
#' @export
flextable::flextable
36 changes: 30 additions & 6 deletions R/header-transform.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ transform_header <- function(
flextable::fix_border_issues()
}

#' Separate the header based on delimiters
#' Split the header based on delimiters
#'
#' @note
#' `split_header` is a rename of `separate_header` and the latter will be removed in the future release.
#'
#' @param x A `flextable` object`
#' @inheritParams tidyr::separate
Expand All @@ -72,12 +75,12 @@ transform_header <- function(
#'
#' @examples
#' iris %>%
#' as_flextable() %>%
#' flextable() %>%
#' separate_header()
#' @export
separate_header <- function(
split_header <- function(
x,
sep = "[_\\.]",
sep = "[_.]",
theme_fun = NULL,
...
) {
Expand All @@ -86,6 +89,27 @@ separate_header <- function(
sep = sep, theme_fun = theme_fun, .fill = FALSE, .merge = FALSE, ...
)
}

#' @rdname split_header
#' @export
separate_header <- function(
x,
sep = "[_.]",
theme_fun = NULL,
...
) {
.Deprecated(
"split_header",
msg = paste(
"ftExtra::separate_header will be removed in the future release",
"to avoid masking `flextable::separate_header`.",
"Instead, use ftExtra::split_header which is a copy of",
"ftExtra::separate_header."
)
)
split_header(x, sep, theme_fun, ...)
}

#' Span the header based on delimiters
#'
#' @inherit separate_header
Expand All @@ -94,12 +118,12 @@ separate_header <- function(
#'
#' @examples
#' iris %>%
#' as_flextable() %>%
#' flextable() %>%
#' span_header()
#' @export
span_header <- function(
x,
sep = "[_\\.]",
sep = "[_.]",
theme_fun = NULL,
...
) {
Expand Down
4 changes: 4 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ drop_na <- function(x) {
last <- function(x) {
x[[length(x)]]
}

.Deprecated <- function(...) {
if (!getOption("ftExtra.ignore.deprecation", FALSE)) base::.Deprecated(...)
}
5 changes: 4 additions & 1 deletion R/with-blanks.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ insert_blanks <- function(after = NULL, before = NULL, data) {
names(data),
sprintf("..after%s", seq_along(.after)),
sprintf("..before%s", seq_along(.before))
)[order(c(seq(length(data)), .after, .before))]
)[order(c(seq_along(data), .after, .before))]
}

#' Specify blank columns easily via `col_keys`
Expand All @@ -20,6 +20,9 @@ insert_blanks <- function(after = NULL, before = NULL, data) {
#' as_flextable(col_keys = with_blanks(dplyr::ends_with("Width")))
#' @export
with_blanks <- function(after = NULL, before = NULL) {
.Deprecated(msg = paste(
"This is a result of deprecating ftExtra:::as_flextable.data.frame"
))
after <- rlang::enquo(after)
before <- rlang::enquo(before)
function(data) insert_blanks(after = after, before = before, data = data)
Expand Down
Loading

0 comments on commit 88dd535

Please sign in to comment.