gadenbuie / shrtcts

Make Anything an RStudio Shortcut
https://pkg.garrickadenbuie.com/shrtcts/
Other
119 stars 4 forks source link

R script-based shortcut assignment #4

Closed gadenbuie closed 4 years ago

gadenbuie commented 4 years ago

Kind of an out-there idea that might just actually work. In place of the .shrtcts.yaml, shortcuts could instead be stored in an .R script with the settings pulled from roxygen2 tags.

Example:

- Name: Restart RStudio
  id: 5
  Binding: usethis:::restart_rstudio
  Interactive: true

becomes

#' Restart RStudio
#' 
#' @name 5
#' @export
usethis:::restart_rstudio

or

- Name: New Temporary R Markdown Document
  Binding: |
    tmp <- tempfile(fileext = ".Rmd")
    rmarkdown::draft(
      tmp,
      template = "github_document",
      package = "rmarkdown",
      edit = FALSE
    )
    rstudioapi::navigateToFile(tmp)
  Interactive: false

becomes

#' New Temporary R Markdown Document
#' 
#' Create and open a new, temporary R Markdown Document
function() {
  tmp <- tempfile(fileext = ".Rmd")
  rmarkdown::draft(
    tmp,
    template = "github_document",
    package = "rmarkdown",
    edit = FALSE
  )
  rstudioapi::navigateToFile(tmp)
}
gadenbuie commented 4 years ago
shortcuts <- roxygen2::parse_file("~/.config/.shrtcts.R")

# Shortcut Title
roxygen2::block_get_tag_value(shortcuts[[1]], "title")
#> [1] "Restart RStudio"

# Shortcut Description
roxygen2::block_get_tag_value(shortcuts[[1]], "description")
#> NULL

# Shortcut ID
roxygen2::block_get_tag_value(shortcuts[[1]], "name")
#> [1] "5"

# Is Shortcut Interactive?
roxygen2::block_has_tags(shortcuts[[1]], "export")
#> [1] TRUE