Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reprex makes me jump to my web browser on Windows (again?) #213

Closed
yutannihilation opened this issue Oct 19, 2018 · 9 comments
Closed

reprex makes me jump to my web browser on Windows (again?) #213

yutannihilation opened this issue Oct 19, 2018 · 9 comments

Comments

@yutannihilation
Copy link
Member

@yutannihilation yutannihilation commented Oct 19, 2018

related: rstudio/rstudio#3577 (comment)

On Windows, I am jumped to browsers every time I execute reprex(). Once I've fixed this problem (#75), but it seems to occur again (I don't remember when). Now I slightly suspect #164 is involved.

Ultimately this is an RStudio's bug, but they say it won't get fixed for v1.2, so it'd be better to have suggested workaround in reprex package, though it seems only few people get affected. Hopefully, I'll send a PR for this if I have some time...

@jennybc

This comment has been minimized.

Copy link
Member

@jennybc jennybc commented Oct 19, 2018

All path handling has been fs-ified since #164 happened.

I read through
rstudio/rstudio#3577 (comment).

Are you willing to explore the effects of processing file path with various functions from fs? And how they interact with the behaviour of viewer() in RStudio? I'm talking about fs:path_expand(), fs::path::real() and friends. Let me know if there's a function that produces a path that RStudio recognizes as below the temp directory.

I would test myself in my Windows VM, but my username doesn't trigger this short path name ickiness.

@jennybc

This comment has been minimized.

Copy link
Member

@jennybc jennybc commented Oct 19, 2018

Try installing from this branch and let me know what happens:

https://github.com/tidyverse/reprex/tree/path-real

@jennybc

This comment has been minimized.

Copy link
Member

@jennybc jennybc commented Oct 19, 2018

Actually, now that I re-read the RStudio issue, I have done the opposite of what's needed in that branch. I don't think it will help you. The workaround is pretty yucky ... but I guess I could try it.

@yutannihilation

This comment has been minimized.

Copy link
Member Author

@yutannihilation yutannihilation commented Oct 20, 2018

Thanks for the infomation! I don't know how fs treats Windows' tricky 8.3 filename. But, I think I'll have to explore it...

@jennybc

This comment has been minimized.

Copy link
Member

@jennybc jennybc commented Oct 20, 2018

I think the best way to use @kevinushey's proposed workaround might be to write a wrapper around viewer() -- that pre-process file paths with the regex substitution he suggests -- and put that in your .Rprofile. Because this problem won't be limited to reprex anyway.

@yutannihilation

This comment has been minimized.

Copy link
Member Author

@yutannihilation yutannihilation commented Oct 20, 2018

Hmm... OK, it sounds reasonable. I'll do so. Should I close this then?

@jennybc

This comment has been minimized.

Copy link
Member

@jennybc jennybc commented Oct 20, 2018

If you get it to work, it wold be great to post your solution here, in case there are other people in the unlucky intersection of sets you find yourself in. But you could do that after closing it, just as well as before.

@yutannihilation

This comment has been minimized.

Copy link
Member Author

@yutannihilation yutannihilation commented Oct 21, 2018

Thanks, this worked for me :)

local({
  options(viewer = function(url, height = NULL){
    # If `url` is a URL, no tweak is needed
    if (grepl("^(https?|ftps?)://", url))
      return(rstudioapi::viewer(url))

    # If `url` is a path, tweak the path
    path <- normalizePath(url)
    tmpdir <- normalizePath(tempdir())
    if (regexpr(tmpdir, path, fixed = TRUE) == 1)
      path <- sub(tmpdir, tempdir(), path, fixed = TRUE)

    rstudioapi::viewer(path)
  })
})
@jennybc

This comment has been minimized.

Copy link
Member

@jennybc jennybc commented Oct 21, 2018

Awesome! Glad it's working for you and appreciate you sharing the solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.