Skip to content

Specific helper for RStudio code execution links #456

Closed

Description

@hadley

e.g.:

  link <- function(code) {
    cli::style_hyperlink(code, paste0("rstudio:run:testthat::", code))
  }

Main difference with style_hyperlink() is that it's only activated if in RStudio.

Activity

  1. added
    feature
    on Apr 27, 2022
  2. hadley commented on Apr 27, 2022

    @hadley
    MemberAuthor

    Paired with inline formatter like .run. I'm pretty sure this this should be different to .code since that often contains unrunnable snippets.

    It may need to be like .href because while we want to match the code clicked and run, we made want to vary the details, e.g. we show snapshot_accpet("foo.R") but we run testthat::snapshot_accept("~/documents/testthat/tests/_snaps/foo.R").

  3. gaborcsardi commented on Apr 27, 2022

    @gaborcsardi
    Member

    Yeah, unfortunately, we are creating a (sub)DSL for this, but there isn't really another way. I'll write some DSL ideas in this issue later...

  4. hadley commented on May 2, 2022

    @hadley
    MemberAuthor

    Another case where this will be important is for pkgdown — we'd want to render links to websites, but not to local files or to run code.

  5. hadley commented on Jul 15, 2022

    @hadley
    MemberAuthor

    See complete list in rstudio/rstudio#11273 (comment)

  6. lionel- commented on Aug 15, 2022

    @lionel-
    Member

    For IDE agnosticity, I think this is now ide:run: and should be guarded by nzchar(Sys.getenv("R_CLI_HAS_HYPERLINK_RUN")) (see #499). But @romainfrancois should confirm this.

  7. added this to the 3.4.0 milestone on Aug 23, 2022
  8. gaborcsardi commented on Aug 25, 2022

    @gaborcsardi
    Member

    Final list of link types: rstudio/rstudio#11273 (comment)

  9. gaborcsardi commented on Aug 26, 2022

    @gaborcsardi
  10. gaborcsardi commented on Aug 27, 2022

    @gaborcsardi
    Member

    I considered having {.url url link text} instead of a new {.href} style, but URLs are now styled by adding <...> currently, and that does not look good if there is link text, so it is better to have a new {.href}` style.

  11. gaborcsardi commented on Sep 1, 2022

    @gaborcsardi
    Member

    Auto-linking existing styles

    They keep formatting. It is not possible to use a different link text with them. We could add link text support, but theming is applied to the result of these tags, and it would look weird for link text. (I.e. if there is link text you don't want to append () to the function name, etc.)

    N Goal Input Links to (link text is always the verbatim content, styled)
    1 auto-link emails {.email [email protected]} mailto:[email protected]
    2 auto-link file {.file path/file} file:///abs/path/dile
    3 auto-link file with line and column numbers {.file /abs/path:line:col} file:///abs/path:line:col, params = list(line = line, col = col)
    4 auto-link function {.fun pkg::fun} x-r-help:pkg::fun
    5 mention function w/o package {.fun fun} no link is created for this form
    6 auto-link url {.url url} url

    New styles to create links

    These all have link text support, via the [text](link) markdown syntax.

    N Goal Input Link text Links to Non-link form
    7 link qualified function name to help {.help pkg::fun} {.fun pkg::fun} x-r-help:pkg::fun {.fun ?pkg::fun}
    8 link to function with link text {.help [text](pkg::fun)} text x-r-help:pkg::fun text ({.fun ?pkg::fun})
    9 link to topic {.topic pkg::topic} pkg::topic x-r-help:pkg::topic {.code ?pkg::topic}
    10 link to topic with link text {.topic [text](pkg::topic)} text x-r-help:pkg::topic text ({.code pkg::topic})
    11 link url {.href url} {.url url} url {.url url}
    12 link url with link text {.href [text](url)} text url text ({.url url})
    13 link running expr {.run expr} {.code expr} x-r-run:expr {.code expr}
    14 link running expr, show code {.run [code](expr)} {.code code} x-r-run:expr {.code expr}
    15 link to vignette {.vignette pkg::name} pkg::name x-r-vignette:pkg::name {.code vignette(pkg::name)}
    16 link to vignette with link text {.vignette [text](pkg::name)} text x-r-vignette:pkg::name text ({.code vignette(pkg::name)})
  12. hadley commented on Sep 1, 2022

    @hadley
    MemberAuthor

    Suggestions for non-link forms:

    • For documentation link, add ? in front of the proposed text?
    • For urls, surround in <> (I think maybe only "link url" is missing that?)
    • For vignette, make it vignette(name, pkg)?
  13. gaborcsardi commented on Sep 1, 2022

    @gaborcsardi
    Member

    Sounds good. URLs are already in <>, that's part of the default theme.

  14. gaborcsardi commented on Sep 1, 2022

    @gaborcsardi
    Member

    I updated the table above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions