davidgohel / officer

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

feat: simplified input for `ph_with`'s `location` arg #623

Open markheckmann opened 1 week ago

markheckmann commented 1 week ago

When I started out with officer, I was initially confused by the ph_with location argument which expects the output of one of the ph_location_* functions. Now, all make perfect sense. Still I think it would be useful (especially for newcomers) to also offer the option of supplying a simplified location arg input (string or numeric), instead of a having to call a ph_location_* function.

Providing a string or numeric can - I think unambiguously and without loss of generality - cover most of the common ph_location_* use cases. While the ph_location_* functions allow for more customized settings and additional features, I think the simplified version would be a nice UI addition and suffice the most common use cases.

_NB: Behind the scenes, the simplified input would just be automatically plugged into one of the ph_location_* functions._

What do you think?

x <- read_pptx()
x <- add_slide(x, "Title Slide")

# >>>> consecutive lines would be identical with the UI simplification  <<<<<

# string to specify ph label
x <- ph_with(x, "A title", location = ph_location_label("Title 1"))
x <- ph_with(x, "A title", location = "Title 1")

# numeric for location id
x <- ph_with(x, "A subtitle", location = ph_location_id(3))
x <- ph_with(x, "A subtitle", location = 3)

# string with special format `type[type_idx]`  for type
x <- ph_with(x, "A date", location = ph_location_type("dt", 1))
x <- ph_with(x, "A date", location = "dt [1]") 

# string with keyword: `left`, `right`, or `fullsize`
x <- ph_with(x, "A left text", location = ph_location_left())
x <- ph_with(x, "A left text", location = "left")
davidgohel commented 1 week ago

Hello,

I've been thinking about this and I think it's a good idea, it's similar to what we use for the ggplots position argument, a parameterizable function or a simple string. You're welcome to implement it, of course, or I can help you (or do it myself) :)

I'm not a fan of the numerical index idea, but I'll leave the decision up to you.

David

markheckmann commented 1 week ago

@davidgohel Great, happy to do it. Please feel free to assign the issue to me :)