Skip to content

Cli links with line numbers and .href #601

Description

@olivroy

Hello,

I am trying to use cli hyperlinks to line numbers with .href

# With .Rprofile existing 
# link works
cli::cli_bullets("{.file ~/.Rprofile}")
#> ~/.Rprofile 
# link works and takes me to line 4
cli::cli_bullets("{.file ~/.Rprofile:4}")
#> .Rprofile:4
# works and shows a link 
cli::cli_bullets("{.href [R profile](file://~/.Rprofile)}")
#> R profile
# link does not work
cli::cli_bullets("{.href [R profile line 1](file://~/.Rprofile:498)}")
#> R profile line 1

I get an error message that says No such file ~.Rprofile:498 does not exist. (in a prompt)
It may be out of scope, but from what I understand in the docs, it should be working.,

Running with RStudio 2023.03.0, Windows, and latest cli.

Edit: Ignore the other question ( I see that this is supported only outside RStudio https://cli.r-lib.org/reference/links.html#default-handler

Opening files outside RStudio within RStudio with cli hyperlink does not work.

# creates output, but clicking on the link does not work in RStudio.
cli::cli_text("{.file path/to/excel.xslx"})
#> path/to/excel.xlsx

Edit 2: Maybe a suggestion not to create a link (underline it ) to show that it won't open. for Excel file for example..

It seems that roxygen2 uses

  link <- cli::style_hyperlink(
    paste0(basename(file), ":", line),
    paste0("file://", file),
    params = c(line = line, col = 1)
  )

Another workaround that keeps the blue for file hyperlink is

withr::with_dir(
  "R",
  cli::format_inline("{.file path-under-r.R:8}") |> cat()
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions