r-lib/cli

pathes for file or folders do not run in console

Closed this issue · 9 comments

jic007 commented

I get the correct output using the below but when I click on the hyperlink I get an error message " 'file/dir path' does not exist."
I wanted to be able to run this function to return text with hyperlink that i can click on in the console

cli::cli_text("... edit your {.file ~/.Rprofile} file.}")

reprex::reprex()
#> ℹ Non-interactive session, setting `html_preview = FALSE`.
#> CLIPR_ALLOW has not been set, so clipr will not run interactively
#> Error in switch(where, expr = stringify_expression(x_expr), clipboard = ingest_clipboard(), : EXPR must be a length 1 vector

Created on 2023-10-03 with reprex v2.0.2

Yes, I can click on that and it takes me to my ~/.Rprofile. Maybe that file does not exist for you?

If you mean that if the file does not exist, then RStudio should still open it, then file an issue for RStudio, we cannot fix that in cli.

jic007 commented

Yes, I can click on that and it takes me to my ~/.Rprofile. Maybe that file does not exist for you?

If you mean that if the file does not exist, then RStudio should still open it, then file an issue for RStudio, we cannot fix that in cli.

Hi I am using Windows 10, I tried with several files and directory paths but somehow r throws an error. to confirm i opened that path manually using file explorer and it works

Possibly RStudio or Windows has a problem with ~? Can you try this?

cli::cli_text("... edit your {.file {normalizePath('~/.Rprofile')}} file.}")
jic007 commented

Possibly RStudio or Windows has a problem with ~? Can you try this?

cli::cli_text("... edit your {.file {normalizePath('~/.Rprofile')}} file.}")

same issue

Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="C:/Users/xxx/Documents/.Rprofile": The system cannot find the file specified

message is printed correctly in console but that's what i get

i tried aboslute path didn't work

i saw once an idea to add "file:///" before the path it allowed me to click on the link but gives an error

your method prints correctly and shows you you can click but when you click you don't get any response

Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="C:/Users/xxx/Documents/.Rprofile": The system cannot find the file specified

Yeah, but this means that you indeed do not have an .Rpofile file, no?

jic007 commented
Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="C:/Users/xxx/Documents/.Rprofile": The system cannot find the file specified

Yeah, but this means that you indeed do not have an .Rpofile file, no?

i had to wrap the file in here::here()
cli::cli_text("... edit your {.file {normalizePath(here::here('.Rprofile'))}} file.}")

it worked for Rprofile but didn't work for anyother file

apparently without here::here it gives me a different path

So maybe ~ means something different to RStudio (or Windows) than it means to R? In any case, if you are using ~ it is best to convert it to an absolute file name. You can still have a nice and short link text, like this: https://cli.r-lib.org/reference/links.html#link-text-1

jic007 commented

So maybe ~ means something different to RStudio (or Windows) than it means to R? In any case, if you are using ~ it is best to convert it to an absolute file name. You can still have a nice and short link text, like this: https://cli.r-lib.org/reference/links.html#link-text-1

thank you for the follow up. I used here package for the .Rprofile it works but other than this it doesn't. it works for opening scripts and things within Rstudio but cannot open anything other than this

I don't think we can fix this in cli, it would have to be fixed in RStudio I am afraid. We cannot tell RStudio what to do with the linked files.