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: capitalize first letter of each bullet #409

Merged
merged 14 commits into from
Aug 27, 2022
Merged

feat: capitalize first letter of each bullet #409

merged 14 commits into from
Aug 27, 2022

Conversation

maelle
Copy link
Member

@maelle maelle commented Jul 26, 2022

Fix #360

@maelle maelle requested a review from krlmlr July 26, 2022 16:11
@maelle maelle changed the title feat: Capitalize first letter of each bullet feat: capitalize first letter of each bullet Jul 26, 2022
@maelle maelle removed the request for review from krlmlr July 26, 2022 16:13
@maelle maelle marked this pull request as draft July 26, 2022 16:13
@maelle maelle marked this pull request as ready for review July 26, 2022 16:21
R/update-news.R Outdated Show resolved Hide resolved
R/update-news.R Outdated Show resolved Hide resolved
R/update-news.R Outdated
Comment on lines 368 to 369
start_with_pkg <- (grepl(sprintf("^%s ", pkg_name), df$description) ||
grepl(sprintf("^%s's", pkg_name), df$description))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"^%s(?: |'s)" ? Extract regex to separate variable? And perhaps combine with regex above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end I realized the "code" regex was useless as toupper() will not touch those anyway.

R/update-news.R Outdated
Comment on lines 382 to 384
news_item <- split(news_items, seq_len(nrow(news_items))) %>%
purrr::map(capitalize_description)
do.call(rbind, news_item)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the need to split here.

map_dfr() ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map_dfr() requires dplyr which fledge does not depend upon hence the awkward split.
Should I define a helper map_dfr that would hide the split?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I added such a helper)

Comment on lines +374 to +377
df$description <- paste0(
toupper(substr(df$description, 1, 1)),
substr(df$description, 2, nchar(df$description))
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprisingly tricky. I was thinking about a rematch2 solution, which could also include the grepl() logic from above, and allow for vectorization (and more compact code) perhaps?

"Bury the logic in one complex regex..." 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm re-reading ?toupper and actually one of the examples there is very similar to what I did above (which does not mean there are no better solutions!).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One simple solution would be to add a dependency on https://cran.r-project.org/web/packages/snakecase/index.html but that might be overkill for one call only.

@maelle
Copy link
Member Author

maelle commented Aug 25, 2022

Are you still in favor of replacing this with rematch2 or is it fine as is?

@maelle maelle requested a review from krlmlr August 25, 2022 08:07
@krlmlr krlmlr merged commit 03fe9ba into main Aug 27, 2022
@krlmlr krlmlr deleted the capitalization branch August 27, 2022 04:33
@krlmlr
Copy link
Contributor

krlmlr commented Aug 27, 2022

Thanks! No need to dive deeper here.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Capitalize first letter of each bullet
2 participants