Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
markheckmann opened this issue Oct 13, 2024 · 2 comments
Open

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

markheckmann opened this issue Oct 13, 2024 · 2 comments
Assignees

Comments

@markheckmann
Copy link
Contributor

markheckmann commented Oct 13, 2024

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
Copy link
Owner

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
Copy link
Contributor Author

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

markheckmann added a commit to markheckmann/officer that referenced this issue Jan 25, 2025
…avidgohel#623)

Instead of a `location` object created by the `ph_location_*` function family,
`ph_with_*` functions now resolves certain short form input into corresponding
`location` objects. For example, instead of using `ph_location_label("<label>")`
you can now simply pass the `"<label>"` to the `location` arg. The functionn will
convert the string into the corresponding location object automatically. Other
examples are `"body [1]"` for `ph_location_type(type = "body", type_idx = 1)`,
or the integer `1` for `ph_location_id(id = 1)`.
davidgohel pushed a commit that referenced this issue Feb 3, 2025
- Simplified input format for `location` arg in `ph_with_*` functions (#623)

Instead of a `location` object created by the `ph_location_*` function family,
`ph_with_*` functions now resolves certain short form input into corresponding
`location` objects. For example, instead of using `ph_location_label("<label>")`
you can now simply pass the `"<label>"` to the `location` arg. The functionn will
convert the string into the corresponding location object automatically. Other
examples are `"body [1]"` for `ph_location_type(type = "body", type_idx = 1)`,
or the integer `1` for `ph_location_id(id = 1)`.

- export resolve_location() function. It might be helpful if other packages want
to use it in their own wrappers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants