-
Notifications
You must be signed in to change notification settings - Fork 81
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
utils::file.edit()
silently fails in reprex()
when reprex()
is run in an RStudio session on Windows
#204
Comments
I would appreciate your advice @kevinushey. It doesn't seem like a great idea for reprex to get deeper into this sort of business. |
IMHO this is something that should be fixed in RStudio directly, though. |
That said, RStudio does this dance where we override the definition of So a solution of this form might indeed be the best way forward. |
@jennybc , can you expand on why you think reprex shouldn't include a fix for this issue? |
I feel differently now that @kevinushey has provided some context. |
One other thing that's probably worth noting: in RStudio, a plain We should probably make these decisions concrete + apparent with helper functions in the |
But if I call a plain
|
You could probably do something gross like: file.edit <- if (exists("file.edit", envir = globalenv()))
get("file.edit", envir = globalenv())
else
utils::file.edit
file.edit(file) |
What would be the circumstance where reprex would be using file.edit to read user input? From my understanding, reprex will only be using file.edit to open files that it has written for the user so that the user can inspect them (post-execution of |
Having just re-learned this lesson the hard way, I think we also need to do this in a way where the "correct" version of file_edit <- function(...) {
if (exists("file.edit", envir = globalenv())) {
get("file.edit", envir = globalenv())(...)
} else {
utils::file.edit(...)
}
} @crew102 I agree that it seems like reprex's use of |
I think the version of file_edit2 <- function(file) {
if (is_windows()) {
# this will return RStudio's file.edit if it exists...If it doesn't exist, it
# will return utils::file.edit()
get("file.edit")(file)
} else {
utils::file.edit(file)
}
} |
Hmm ... I don't get the preference for a modal. If reprex has made something for the user (either a reprex or harvested and un-reprexed something from the web), it feels like they would want it in a "regular" tab instead of a modal that blocks all other activity, no? |
Yeah, on second thought I guess it would make more sense to prefer tabs to modals... I was just considering the case where the user runs reprex and wants to view the code in the output file and/or copy and paste it from there. However, a regular tab makes more sense when the user is expected to interact with the code beyond doing a copy paste (which would be the case for the undo functions...for those functions, the user will probably want to run the code after it's opened). |
Let's go with the tab then. FYI I got a little patch release out this weekend, mostly because I have to give a webinar on Wednesday and I wanted a few small fixes to be out there. I'd like the next release to really target some of this UI stuff: stress testing different workflows on Windows/RStudio Cloud, polish the addin, etc. |
Much of this appears very similar to Perhaps a robust implementation of |
Interesting package @krlmlr . I'd be happy to try to incorporate |
Issue related to line
reprex/R/reprex.R
Line 377 in 8c64e13
This issue may have gone unnoticed thus far b/c
utils::file.edit()
is wrapped indefer()
anddefer()
seems to muffle errors (CC'ing @kevinushey, as I'm not sure if this is desired behavior):Created on 2018-09-13 by the reprex package (v0.2.0.9000).
reprex()
didn't wraputils::file.edit()
indefer()
, the user would see the following error to explain why no file had been opened:I believe this error stems from the fact that RStudio sets the "editor" option to be the following function on Windows:
https://github.com/rstudio/rstudio/blob/8af730409bb6d651cc8f6816d136bea91441e7a4/src/cpp/session/modules/SessionEnvironment.R#L379
.. but this function doesn't seem to play well with
utils::file.edit()
(it does work with RStudio'sfile.edit()
though).reprex()
fails to open file:R version: 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
RStudio version: 1.1.419
The text was updated successfully, but these errors were encountered: