davidgohel / officer

:cop: officer: office documents from R
https://ardata-fr.github.io/officeverse/
Other
594 stars 107 forks source link

consistent use of term `id` across layout_properties(), ph_location_type(), plot_layout_properties() (#606) #608

Closed markheckmann closed 2 weeks ago

markheckmann commented 2 weeks ago

This PR closes the suggestions 1- 3 at the bottom of #606.

Suggestion 4 will be part of another PR.

Summary from NEWS.md:


1. layout_properties() gains a new type_idx column.

It is an index for placeholders of the same type on a layout. The index is sorted by ph position (top -> bottom, left -> right), for a user-friendly ordering logic (sorted by offy, then offx). (See change 2 below for a visual impression).

layout_properties(x, "Comparison")[, c(1:6, 8:9)]

    master_name       name   type type_idx id                   ph_label     offx      offy
22 Office Theme Comparison  title        1  2                    Title 1 0.500000 0.3003478
23 Office Theme Comparison   body        1  3         Text Placeholder 2 0.500000 1.6788200
24 Office Theme Comparison   body        2  5         Text Placeholder 4 5.079861 1.6788200
25 Office Theme Comparison   body        3  4      Content Placeholder 3 0.500000 2.3784722
26 Office Theme Comparison   body        4  6      Content Placeholder 5 5.079861 2.3784722
27 Office Theme Comparison     dt        1  7         Date Placeholder 6 0.500000 6.9513889
28 Office Theme Comparison    ftr        1  8       Footer Placeholder 7 3.416667 6.9513889
29 Office Theme Comparison sldNum        1  9 Slide Number Placeholder 8 7.166667 6.9513889

2. plot_layout_properties(): with more ph info by default

The function now prints the ph label, type, type index, and layout name by default. The new args type = T/F and id = T/F allow to show or hide them. The type index also has an intuitive order (top->bottom, left->right). Previously, the indexing was done along the ph ids, which may result in an arbitrary index order.

plot_layout_properties(x, "Comparison")

image

3. ph_location_type() gains new type_idx argument.

type_idx will replace the id arg. id is preserved for now to avoid a breaking change, but throws a deprecation warning. The arg name is changed to avoid confusion with the id column from layout_properties() which has another meaning.

In the example below, both args (type_idx and id) are used. Note that only type_idxuses the new indexing order. The index order of id is unchanged (using the old indexing logic along the ph id) to avoid a breaking change.

x <- x |> add_slide("Comparison")

x |> ph_with("NEW: type_idx", ph_location_label("Title 1"))
for (type_idx in 1:4) {
  x |> ph_with(paste("type_idx:", type_idx), ph_location_type(type_idx = type_idx))
}

x <- x |> add_slide("Comparison")
x |> ph_with("OLD: id", ph_location_label("Title 1"))
for (id in 1:4) {
  x |> ph_with(paste("id:", id), ph_location_type(id = id))
}

file <- tempfile(fileext = ".pptx")
print(x, file)
file.show(file)
Warning:
1: ! The `id` argument in `ph_location_type()` is deprecated as of officer 0.6.7.
ℹ Please use the `type_idx` argument instead.
✖ Caution: new index logic in `type_idx` (see docs). 
2: ! The `id` argument in `ph_location_type()` is deprecated as of officer 0.6.7.
ℹ Please use the `type_idx` argument instead.
✖ Caution: new index logic in `type_idx` (see docs). 
3: ! The `id` argument in `ph_location_type()` is deprecated as of officer 0.6.7.
ℹ Please use the `type_idx` argument instead.
✖ Caution: new index logic in `type_idx` (see docs). 
4: ! The `id` argument in `ph_location_type()` is deprecated as of officer 0.6.7.
ℹ Please use the `type_idx` argument instead.
✖ Caution: new index logic in `type_idx` (see docs). 

image

davidgohel commented 2 weeks ago

thank you again @markheckmann