r-lib / cli

Tools for making beautiful & useful command line interfaces
https://cli.r-lib.org/
Other
653 stars 70 forks source link

.run cli hyperlinks with base functions. #598

Closed olivroy closed 1 year ago

olivroy commented 1 year ago

Hi,

I was wondering if it would be possible to allow base functions to have hyperlinks.

It would be handy if

cli::cli_text("{.run names(.Last.value)}")

worked.

The workaround I found is to create my own package and to wrap base::names() function in it, so I can do this.

cli::cli_text("{.run mypkg::get_names()}")

with

get_names <- function(x = .Last.value) { 
  names(x)
}

Thanks for the great package!

Actually I use this as I override the tibble printing method. When a data frame is long, I like to have a clickable hyperlink to display the names of the last value.

gaborcsardi commented 1 year ago

cli already allows this, e.g. it works in my terminal. But RStudio does not allow it: https://github.com/rstudio/rstudio/issues/11273

moodymudskipper commented 1 year ago

Here are the rules I got from the linked thread + experimentation, since I believe those are not documented yet :

The reason as I understand it is that the hyperlink could have dangerous behavior, like removing files or objects, so for instance we forbid base so you can't rm(). You might wrap rm() in a custom function but then the function would have to be in an attached package so it's somewhat safer, though it seems to me it's quite easy to hack around those measures.

gaborcsardi commented 1 year ago

Closing as cli cannot do anything about this.