1

According to the officer package documentation:

index is to be used when a type is not unique in the slide layout

I can't however find any information that identifies which property of a placeholder determines it's index.

Below, I'm providing an example output of layout_properties().

   master_name   name type id            ph_label     offx      offy       cx        cy
148      master layout body 14  Text Placeholder 4 7.500000 0.9791667 2.500000 0.5000000
150      master layout body 13 Text Placeholder 16 8.333333 1.6458333 1.416667 1.0000000
151      master layout body 12 Text Placeholder 13 1.583333 5.1458333 5.916667 0.4791667

I see three possibilities that could determine the proper index values for each text placeholder.

  1. Ranked by column id. From example, starting at the top, indexes = 3, 2, 1
  2. Ranked by the numeric value in column ph_label. Indexes = 1, 3, 2
  3. Ranked by the row order. Indexes = 1, 2, 3

EDIT

For future users, it is the row order which determines the proper index.

Anecdotally, the row order was my guess initially, but I was finding some exceptions to that rule. The cause for these exceptions was actually that the layout properties output was different on my local machine from the output on my shiny server even though it is the exact same code with the exact same template file. Now why that happens?... I have no idea.

Adam Birenbaum
  • 940
  • 9
  • 23

1 Answers1

0

From my understanding, the index is user supplied for position on a slide, and layout_properties displays the actual slide layout. I don't believe anything there corresponds to an index position.

For example:

doc <- read_pptx() %>%
  add_slide(layout = "Two Content", master = "Office Theme") %>%
  ph_with_text(type = "body", str = "body (index 1) is text") %>% 
  ph_with_text(type = "body", str = "body (index 2) is also text")
print(doc, target = "C:/Foo/doc_1.pptx") # Since type is not unique, both are body, they get printed as if they are the same, at the same index position on top of each other.

> layout_properties(doc)
    master_name              name     type id                   ph_label      offx      offy       cx        cy
1  Office Theme    Section Header     body  3         Text Placeholder 2 0.7899311 3.1788200 8.500000 1.6406245
2  Office Theme        Comparison     body  5         Text Placeholder 4 5.0798611 1.6788200 4.420139 0.6996522
3  Office Theme        Comparison     body  6      Content Placeholder 5 5.0798611 2.3784722 4.420139 4.3211811
4  Office Theme        Comparison     body  4      Content Placeholder 3 0.5000000 2.3784722 4.418403 4.3211811
5  Office Theme Title and Content     body  3      Content Placeholder 2 0.5000000 1.7500000 9.000000 4.9496533
6  Office Theme       Two Content     body  3      Content Placeholder 2 0.5000000 1.7500000 4.416667 4.9496533
7  Office Theme       Two Content     body  4      Content Placeholder 3 5.0833333 1.7500000 4.416667 4.9496533
8  Office Theme        Comparison     body  3         Text Placeholder 2 0.5000000 1.6788200 4.418403 0.6996522
9  Office Theme       Title Slide       dt  4         Date Placeholder 3 0.5000000 6.9513889 2.333333 0.3993056
10 Office Theme Title and Content       dt  4         Date Placeholder 3 0.5000000 6.9513889 2.333333 0.3993056
11 Office Theme        Title Only       dt  3         Date Placeholder 2 0.5000000 6.9513889 2.333333 0.3993056
12 Office Theme       Two Content       dt  5         Date Placeholder 4 0.5000000 6.9513889 2.333333 0.3993056
13 Office Theme    Section Header       dt  4         Date Placeholder 3 0.5000000 6.9513889 2.333333 0.3993056
14 Office Theme        Comparison       dt  7         Date Placeholder 6 0.5000000 6.9513889 2.333333 0.3993056
15 Office Theme             Blank       dt  2         Date Placeholder 1 0.5000000 6.9513889 2.333333 0.3993056
16 Office Theme       Two Content      ftr  6       Footer Placeholder 5 3.4166667 6.9513889 3.166667 0.3993056
17 Office Theme       Title Slide      ftr  5       Footer Placeholder 4 3.4166667 6.9513889 3.166667 0.3993056
18 Office Theme        Comparison      ftr  8       Footer Placeholder 7 3.4166667 6.9513889 3.166667 0.3993056
19 Office Theme             Blank      ftr  3       Footer Placeholder 2 3.4166667 6.9513889 3.166667 0.3993056
20 Office Theme        Title Only      ftr  4       Footer Placeholder 3 3.4166667 6.9513889 3.166667 0.3993056
21 Office Theme Title and Content      ftr  5       Footer Placeholder 4 3.4166667 6.9513889 3.166667 0.3993056
22 Office Theme    Section Header      ftr  5       Footer Placeholder 4 3.4166667 6.9513889 3.166667 0.3993056
23 Office Theme        Comparison   sldNum  9 Slide Number Placeholder 8 7.1666667 6.9513889 2.333333 0.3993056
24 Office Theme        Title Only   sldNum  5 Slide Number Placeholder 4 7.1666667 6.9513889 2.333333 0.3993056
25 Office Theme Title and Content   sldNum  6 Slide Number Placeholder 5 7.1666667 6.9513889 2.333333 0.3993056
26 Office Theme    Section Header   sldNum  6 Slide Number Placeholder 5 7.1666667 6.9513889 2.333333 0.3993056
27 Office Theme       Title Slide   sldNum  6 Slide Number Placeholder 5 7.1666667 6.9513889 2.333333 0.3993056
28 Office Theme             Blank   sldNum  4 Slide Number Placeholder 3 7.1666667 6.9513889 2.333333 0.3993056
29 Office Theme       Two Content   sldNum  7 Slide Number Placeholder 6 7.1666667 6.9513889 2.333333 0.3993056
30 Office Theme        Title Only    title  2                    Title 1 0.5000000 0.3003478 9.000000 1.2500000
31 Office Theme Title and Content    title  2                    Title 1 0.5000000 0.3003478 9.000000 1.2500000
32 Office Theme       Two Content    title  2                    Title 1 0.5000000 0.3003478 9.000000 1.2500000
33 Office Theme    Section Header    title  2                    Title 1 0.7899311 4.8194444 8.500000 1.4895833
34 Office Theme        Comparison    title  2                    Title 1 0.5000000 0.3003478 9.000000 1.2500000
35 Office Theme       Title Slide ctrTitle  2                    Title 1 0.7500000 2.3298611 8.500000 1.6076389
36 Office Theme       Title Slide subTitle  3                 Subtitle 2 1.5000000 4.2500000 7.000000 1.9166667

doc <- doc %>% ph_with_text(type = "body", str = " text at real index 2", index = 2)
print(doc, target = "C:/Foo/doc_2.pptx") # Using the same pptx layout, adds text at index = 2.

> layout_properties(doc) # Comparing them, they don't appear to have new text placeholder entries.
    master_name              name     type id                   ph_label      offx      offy       cx        cy
1  Office Theme    Section Header     body  3         Text Placeholder 2 0.7899311 3.1788200 8.500000 1.6406245
2  Office Theme        Comparison     body  5         Text Placeholder 4 5.0798611 1.6788200 4.420139 0.6996522
3  Office Theme        Comparison     body  6      Content Placeholder 5 5.0798611 2.3784722 4.420139 4.3211811
4  Office Theme        Comparison     body  4      Content Placeholder 3 0.5000000 2.3784722 4.418403 4.3211811
5  Office Theme Title and Content     body  3      Content Placeholder 2 0.5000000 1.7500000 9.000000 4.9496533
6  Office Theme       Two Content     body  3      Content Placeholder 2 0.5000000 1.7500000 4.416667 4.9496533
7  Office Theme       Two Content     body  4      Content Placeholder 3 5.0833333 1.7500000 4.416667 4.9496533
8  Office Theme        Comparison     body  3         Text Placeholder 2 0.5000000 1.6788200 4.418403 0.6996522
9  Office Theme       Title Slide       dt  4         Date Placeholder 3 0.5000000 6.9513889 2.333333 0.3993056
10 Office Theme Title and Content       dt  4         Date Placeholder 3 0.5000000 6.9513889 2.333333 0.3993056
11 Office Theme        Title Only       dt  3         Date Placeholder 2 0.5000000 6.9513889 2.333333 0.3993056
12 Office Theme       Two Content       dt  5         Date Placeholder 4 0.5000000 6.9513889 2.333333 0.3993056
13 Office Theme    Section Header       dt  4         Date Placeholder 3 0.5000000 6.9513889 2.333333 0.3993056
14 Office Theme        Comparison       dt  7         Date Placeholder 6 0.5000000 6.9513889 2.333333 0.3993056
15 Office Theme             Blank       dt  2         Date Placeholder 1 0.5000000 6.9513889 2.333333 0.3993056
16 Office Theme       Two Content      ftr  6       Footer Placeholder 5 3.4166667 6.9513889 3.166667 0.3993056
17 Office Theme       Title Slide      ftr  5       Footer Placeholder 4 3.4166667 6.9513889 3.166667 0.3993056
18 Office Theme        Comparison      ftr  8       Footer Placeholder 7 3.4166667 6.9513889 3.166667 0.3993056
19 Office Theme             Blank      ftr  3       Footer Placeholder 2 3.4166667 6.9513889 3.166667 0.3993056
20 Office Theme        Title Only      ftr  4       Footer Placeholder 3 3.4166667 6.9513889 3.166667 0.3993056
21 Office Theme Title and Content      ftr  5       Footer Placeholder 4 3.4166667 6.9513889 3.166667 0.3993056
22 Office Theme    Section Header      ftr  5       Footer Placeholder 4 3.4166667 6.9513889 3.166667 0.3993056
23 Office Theme        Comparison   sldNum  9 Slide Number Placeholder 8 7.1666667 6.9513889 2.333333 0.3993056
24 Office Theme        Title Only   sldNum  5 Slide Number Placeholder 4 7.1666667 6.9513889 2.333333 0.3993056
25 Office Theme Title and Content   sldNum  6 Slide Number Placeholder 5 7.1666667 6.9513889 2.333333 0.3993056
26 Office Theme    Section Header   sldNum  6 Slide Number Placeholder 5 7.1666667 6.9513889 2.333333 0.3993056
27 Office Theme       Title Slide   sldNum  6 Slide Number Placeholder 5 7.1666667 6.9513889 2.333333 0.3993056
28 Office Theme             Blank   sldNum  4 Slide Number Placeholder 3 7.1666667 6.9513889 2.333333 0.3993056
29 Office Theme       Two Content   sldNum  7 Slide Number Placeholder 6 7.1666667 6.9513889 2.333333 0.3993056
30 Office Theme        Title Only    title  2                    Title 1 0.5000000 0.3003478 9.000000 1.2500000
31 Office Theme Title and Content    title  2                    Title 1 0.5000000 0.3003478 9.000000 1.2500000
32 Office Theme       Two Content    title  2                    Title 1 0.5000000 0.3003478 9.000000 1.2500000
33 Office Theme    Section Header    title  2                    Title 1 0.7899311 4.8194444 8.500000 1.4895833
34 Office Theme        Comparison    title  2                    Title 1 0.5000000 0.3003478 9.000000 1.2500000
35 Office Theme       Title Slide ctrTitle  2                    Title 1 0.7500000 2.3298611 8.500000 1.6076389
36 Office Theme       Title Slide subTitle  3                 Subtitle 2 1.5000000 4.2500000 7.000000 1.9166667

doc <- read_pptx() %>%
  add_slide(layout = "Two Content", master = "Office Theme") %>%
  ph_with_text(type = "body", str = "A first text", index = 1) %>%
  ph_with_text(type = "body", str = "A second text", index = 2) %>%
  ph_with_text(type = "title", str = "A title")
print(doc, target = "C:/Foo/doc_3.pptx") # Add index values for the two "body" types, and they'll print in your supplied order/place.

doc4 <- read_pptx() %>%
  add_slide(layout = "Two Content", master = "Office Theme") %>%
  ph_with_text(type = "body", str = "body (index 1) is text") %>% 
  ph_add_text(str = "Bullet text") %>% 
  ph_add_par(level = 1) %>% 
  ph_add_text(str = "Bullet text 2") %>%
  ph_add_par(level = 2) %>% 
  ph_add_text(str = "Lower level text 2")
  print(doc4, target = "C:/Foo/doc_4.pptx")
layout_properties(doc4) # Looks the same
Anonymous coward
  • 2,061
  • 1
  • 16
  • 29
  • 1
    So I understand indexes are user supplied and determine position on a slide. But my question is (following your example) how would you know that by setting index = 2, the text will be positioned in "Content Placeholder 3" and not "Content Placeholder 2"? Obviously, you could test and check to see which index corresponds to a certain placeholder, but there must be a way to determine that ahead of time. My assumption was that something in the layout properties determined that. – Adam Birenbaum Aug 02 '18 at 20:40
  • It seems like it's just row order that determines this, but sometimes I run into inconsistencies. Could just be user error on my part. – Adam Birenbaum Aug 02 '18 at 20:51
  • I suppose it depends on the [slide layout](https://support.office.com/en-us/article/apply-or-change-a-slide-layout-158e6dba-e53e-479b-a6fc-caab72609689) you are using. I would assume the first `Two Content`'s `Content Placeholder` would be the first index. I can't say one way or the other. – Anonymous coward Aug 02 '18 at 20:56