Skip to content

Commit

Permalink
change: headers_flextable_at_bkm() and footers_flextable_at_bkm()
Browse files Browse the repository at this point in the history
… are defunct
  • Loading branch information
davidgohel committed Mar 6, 2024
1 parent 4cff456 commit ae707a0
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 82 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: flextable
Type: Package
Title: Functions for Tabular Reporting
Version: 0.9.5
Version: 0.9.6.001
Authors@R: c(
person("David", "Gohel", role = c("aut", "cre"),
email = "david.gohel@ardata.fr"),
Expand Down
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,3 @@ importFrom(utils,packageVersion)
importFrom(utils,tail)
importFrom(uuid,UUIDgenerate)
importFrom(xml2,as_xml_document)
importFrom(xml2,xml_find_first)
importFrom(xml2,xml_parent)
importFrom(xml2,xml_replace)
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# flextable 0.9.6

## Changes

- `headers_flextable_at_bkm()` and `footers_flextable_at_bkm()` are defunct.

# flextable 0.9.5

## new features
Expand Down
55 changes: 1 addition & 54 deletions R/body_add_flextable.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,63 +158,10 @@ body_add_flextable <- function(x, value,
#' @param split set to TRUE if you want to activate Word
#' option 'Allow row to break across pages'.
#' @importFrom officer cursor_bookmark
#' @importFrom xml2 xml_replace as_xml_document xml_find_first xml_parent
#' @importFrom xml2 as_xml_document
body_replace_flextable_at_bkm <- function(x, bookmark, value, align = "center", split = FALSE) {
x <- cursor_bookmark(x, bookmark)
x <- body_add_flextable(x = x, value = value, pos = "on", align = align, split = split)
x
}

#' @export
#' @title Add flextable at a bookmark location in document's header
#' @description replace in the header of a document a paragraph containing a bookmark by a flextable.
#' A bookmark will be considered as valid if enclosing words
#' within a paragraph; i.e., a bookmark along two or more paragraphs is invalid,
#' a bookmark set on a whole paragraph is also invalid, but bookmarking few words
#' inside a paragraph is valid.
#' @param x an rdocx object
#' @param bookmark bookmark id
#' @param value a flextable object
#' @keywords internal
headers_flextable_at_bkm <- function(x, bookmark, value) {
stopifnot(inherits(x, "rdocx"), inherits(value, "flextable"))
.Deprecated(new = "use `prop_section(header_default = block_list(your_flextable))`")
str <- gen_raw_wml(value, doc = x)
xml_elt <- as_xml_document(str)
for (header in x$headers) {
node <- xml_find_first(header$get(), sprintf('//w:bookmarkStart[@w:name="%s"]', bookmark))
if (!inherits(node, "xml_missing")) {
node <- xml_parent(node)
xml_replace(node, xml_elt)
}
}

x
}

#' @export
#' @title Add flextable at a bookmark location in document's footer
#' @description replace in the footer of a document a paragraph containing a bookmark by a flextable.
#' A bookmark will be considered as valid if enclosing words
#' within a paragraph; i.e., a bookmark along two or more paragraphs is invalid,
#' a bookmark set on a whole paragraph is also invalid, but bookmarking few words
#' inside a paragraph is valid.
#' @param x an rdocx object
#' @param bookmark bookmark id
#' @param value a flextable object
#' @keywords internal
footers_flextable_at_bkm <- function(x, bookmark, value) {
stopifnot(inherits(x, "rdocx"), inherits(value, "flextable"))
.Deprecated(new = "use `prop_section(footer_default = block_list(your_flextable))`")
str <- gen_raw_wml(value, doc = x)
xml_elt <- as_xml_document(str)
for (footer in x$footers) {
node <- xml_find_first(footer$get(), sprintf('//w:bookmarkStart[@w:name="%s"]', bookmark))
if (!inherits(node, "xml_missing")) {
node <- xml_parent(node)
xml_replace(node, xml_elt)
}
}

x
}
17 changes: 17 additions & 0 deletions R/zz-defunct.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#' @export
#' @title Add flextable at a bookmark location in document's header
#' @description Function is now defunct, use [prop_section()] instead.
#' @param ... unused
#' @keywords internal
headers_flextable_at_bkm <- function(...) {
.Defunct(new = "prop_section", package = "officer")
}

#' @export
#' @title Add flextable at a bookmark location in document's footer
#' @description Function is now defunct, use [prop_section()] instead.
#' @param ... unused
#' @keywords internal
footers_flextable_at_bkm <- function(...) {
.Defunct(new = "prop_section", package = "officer")
}
16 changes: 4 additions & 12 deletions man/footers_flextable_at_bkm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions man/headers_flextable_at_bkm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ae707a0

Please sign in to comment.