Skip to content

Export usethis ui functions #308

@mdlincoln

Description

@mdlincoln

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?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancementtooling 🔨Internal usethis tooling

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions