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

Edit template #1319

Merged
merged 12 commits into from Feb 9, 2021
Merged

Edit template #1319

merged 12 commits into from Feb 9, 2021

Conversation

malcolmbarrett
Copy link
Collaborator

@malcolmbarrett malcolmbarrett commented Dec 23, 2020

This PR adds edit_template() for creating and editing files in inst/templates. I've resisted this PR because it's such a simple function, but I find myself constantly wanting to have it available. I'm conscious of the fact that, as the package matures, these little helper functions may not find their forever home in usethis. Nevertheless, here's why I think usethis should have this function:

  1. use_template() introduces a structure, much in the way that R Markdown templates do. That structure should be automated away because if you misspecify it, templates will not work. use_rmarkdown_template() is important not just because of the complexity of that structure but the consistency. usethis templates use a considerably simpler structure, yet--and I'm not kidding--I can never remember if it's inst/template or inst/templates. I literally have to look it up every single time.
  2. Templates are a key asset of usethis when you're using the package to develop internal tools. Templates are, in fact, probably the most useful feature of the ecosystem when you're building a usethis-like package. Iterating templates should thus have good support.

@jennybc
Copy link
Member

jennybc commented Feb 8, 2021

I recently added a feature to pr_fetch() and pr_resume() that, when called argument-less, gives you a choice of PRs / branches.

I suspect something similar might be useful here, because who is going to remember the exact names of their existing templates? So if template is not provided, could say something like "looking up existing templates in inst/templates ... and provide a list.

@malcolmbarrett
Copy link
Collaborator Author

Ooo that's a great idea, thank you! I'll try to add that today. I've greatly enjoyed that functionality for the pr functions so far for exactly the same reason

@malcolmbarrett
Copy link
Collaborator Author

Ok, edit_template() now uses the same menu() approach as the PR functions, more or less. I'm excited about that!

PS I noticed that Hadley's change to the tests resulted in just calling edit_template() without capture.output(). I modeled that test after those for edit_file(); happy to do a small (separate) PR to make those tests consistent if capture.output() is not needed, if you like.

R/edit.R Outdated Show resolved Hide resolved
R/edit.R Outdated Show resolved Hide resolved
R/edit.R Outdated Show resolved Hide resolved
@jennybc
Copy link
Member

jennybc commented Feb 9, 2021

Thanks!

@jennybc jennybc merged commit 762daec into r-lib:master Feb 9, 2021
@malcolmbarrett
Copy link
Collaborator Author

Awesome, thanks to you both!

@malcolmbarrett malcolmbarrett deleted the edit_template branch February 9, 2021 00:56
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

Successfully merging this pull request may close these issues.

None yet

3 participants