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

Export usethis ui functions #308

Closed
mdlincoln opened this issue Mar 11, 2018 · 10 comments
Closed

Export usethis ui functions #308

mdlincoln opened this issue Mar 11, 2018 · 10 comments

Comments

@mdlincoln
Copy link

@mdlincoln mdlincoln commented Mar 11, 2018

I'm developing a package that wants to prompt the user to add some code to their .R profile (in this case, a .Last function.)

I love how use_usethis() locates and opens the .Rprofile via edit_r_profile while also displaying the code to be added and writing it to the clipboard. However, the function code_block() for formatting and accessing the clipboard is not exported currently. Are there plans to export code_block() in the future so we can create generic use_usethis-esque functions? Or perhaps create some kind of API for creating generic use_ functions, maybe by way of a closure/function factory?

use_ <- function(edit_function, todo_text, code, ...) {
    function() {
        edit_function(...)
        todo(todo_text)
        code_block(code)
    }
}

use_x <- use_(edit_r_profile,
             todo_text = "Include this code in your .Rprofile to get x package working",
             code = c(".Last <- function() {", "message('All done.')", "}")

(Unless there is some way to call use_template() for this that I've missed?)

@jennybc
Copy link
Member

@jennybc jennybc commented Mar 11, 2018

We definitely want usethis to be extensible! Hence the recent export of use_template() as you point out.

I don't have a short, immediate answer, but am happy to think and discuss how to facilitate this more generally.

cc @hadley

@hadley
Copy link
Member

@hadley hadley commented Nov 24, 2018

I think we can consider this family of functions for export in the next release. We'll need to rethink their names and possibly consider a common prefix.

@hadley
Copy link
Member

@hadley hadley commented Nov 26, 2018

@jennybc any thoughts on what prefix we should use? We currently have done(), todo(), code_block() (which I suspect will be reduced to _code()). Random ideas: info_, show_, user_, cat_

@jennybc
Copy link
Member

@jennybc jennybc commented Nov 26, 2018

What do you think of ui_?

@gadenbuie

This comment has been hidden.

@hadley

This comment has been hidden.

@gadenbuie

This comment has been hidden.

@hadley

This comment has been hidden.

@hadley
Copy link
Member

@hadley hadley commented Nov 27, 2018

So this would give us:

  • Informative messages: ui_done(), ui_todo(), ui_code_block()
  • Component styling: ui_field(), ui_value(), ui_code()
  • Questions: ui_yep(), ui_nope()

How does that sound, en masse?

@hadley hadley changed the title Design for extending usethis functions Export usethis ui functions Nov 28, 2018
@hadley
Copy link
Member

@hadley hadley commented Nov 30, 2018

And maybe ui_stop() and ui_warn() to replace stop_glue() and warning_glue()

hadley added a commit that referenced this issue Nov 30, 2018
* Now called ui_code_block() in preparation for #308
* Now takes a single line, relying on glue formatting more
@hadley hadley closed this in 02fc4b2 Nov 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants