Given the comment, polish and insert the object at the given location in the document.
add_sparkle(
docx,
comment_id,
value,
...,
lock = FALSE,
polish_error_continue = TRUE
)
add_sparkles_pattern(
docx,
docx_text_pattern = fixed("{{insert}}", ignore_case = TRUE),
comment_text_func,
...,
overwrite_previous_content = FALSE,
force_repolishing = FALSE,
polish_error_continue = TRUE
)a `docx_container`
the id of the comment to replace
content to be polished and added to the document
arguments passed to comment_text_func and polish_content methods
Should content added be "locked", meaning they are un-editable. Default is FALSE.
boolean indicating whether to throw an error or just inform when polishing fails.
pattern to match on commented docx text to identify which comments are sparkle comments.
The default interpretation is a regular expression, as described in vignette("regular-expressions"). Use stringr::regex() for finer control of the matching behavior.
Match a fixed string (i.e. by comparing only bytes), using stringr::fixed(). This is fast, but approximate. Generally, for matching human text, you'll want stringr::coll() which respects character matching rules for the specified locale.
Match character, word, line and sentence boundaries with stringr::boundary(). An empty pattern, "", is equivalent to boundary("character")
Function to parse a `sparkle_comment` object to identify what content to add. The first argument is "comment", which is the `sparkle_comment`. The `sparkle_comment` is generated from `get_comment_id()` as called within the `add_sparkles_pattern()`.
should previously entered content that match the pattern be updated. Defaults to FALSE.
If content hash matches previously inserted content hash, should re-polishing occur?
a `docx_container` with sparkle
library(ggplot2)
temp_word_1 <- tempfile(fileext = ".docx")
temp_word_2 <- tempfile(fileext = ".docx")
## Initial addition of content
load_docx(system.file("example_docx/basic_sparkle_doc_with_comments.docx", package = "sparkle")) |>
add_sparkle(0, mtcars[1:2,1:3]) |>
add_sparkle(2, ggplot(diamonds, aes(x = carat)) + geom_histogram()) |>
add_sparkle(4, 1.0) |>
save_docx(temp_word_1)
#> `stat_bin()` using `bins = 30`. Pick better value `binwidth`.
if(interactive()){
shell.exec(temp_word_1)
}
## update content
load_docx(temp_word_1) |>
add_sparkle(0, mtcars[3:5,1:10]) |>
add_sparkle(2, ggplot(diamonds, aes(x = carat, y = price)) + geom_point()) |>
add_sparkle(4, "test test 1234 test") |>
save_docx(temp_word_2)
if(interactive()){
shell.exec(temp_word_2)
}