Skip to content

Conversation

DavisVaughan
Copy link
Contributor

@DavisVaughan DavisVaughan commented Aug 21, 2025

Addresses posit-dev/positron#7681

My preferred alternative to #895

In a fresh R session, .Device in RStudio returns "null device" and getOption("device") returns "RStudioGD". i.e. R doesn't have a current device active, but it knows to use a function named RStudioGD() when it needs to make one (and indeed you can call RStudioGD at the console and you can find it yourself).

For these reasons, I do not think we should inject ourselves as the current active device on startup as proposed by #895. I think we should also follow RStudio's lead and let the device be "null device" until a plot is actually required.


To solve the problem a different way, we just recognize that the main issue is that we are calling grDevices::deviceIsInteractive() to register ourselves as an interactive device too late - we are calling it at first plot time, but should call it at startup time. I have made that change in this PR, and in theory that should have been enough to fix the issue.

In practice there is one other issue I had to deal with. We set options(device = <fn>) where RStudio sets options(device = "RStudioGD"). This is surprisingly important. In a fresh session, grDevices::dev.interactive(orNone = TRUE) (used by demo(graphics)) will look to see if the current device is in the set of known devices provided by deviceIsInteractive(). However, if that device is "null device", then it will consult getOption("device") and see if that name is in the set provided by deviceIsInteractive() instead. But if you set options(device =) to a function rather than a name then you don't get to take advantage of this nice feature. I've reworked a few things to take advantage of this now. Importantly, we now mimic RStudio exactly here.

I've also updated docs and added tests to assert our beliefs about how these functions work on startup.

QA Notes

Running demo(graphics) in a fresh session with release Positron should render all the plots non-interactively:

Screen.Recording.2025-05-14.at.08.14.06.mov

With the fix, this should now prompt you to type Enter between each plot.

Screen.Recording.2025-08-09.at.16.31.17.mov

@lionel-
Copy link
Contributor

lionel- commented Aug 22, 2025

For these reasons, I do not think we should inject ourselves as the current active device on startup as proposed by #895. I think we should also follow RStudio's lead and let the device be "null device" until a plot is actually required.

Sorry I don't understand. What are the reasons?

@DavisVaughan
Copy link
Contributor Author

DavisVaughan commented Aug 22, 2025

I think Positron/ark should work like starting R at the command line or from RStudio, i.e.:

  • Initially the current graphics device is "null device"
  • getOption("device") contains the default device to use when a plot is required
    • In R at the command line, this is a function that invokes a Quartz device on Mac
    • In RStudio, this is "RStudioGD"
    • In ark, I want this to be ".ark.graphics.device"

It seems like that approach follows standard practices rather than setting the ark graphics device as the current device on startup

@lionel-
Copy link
Contributor

lionel- commented Aug 25, 2025

So the material difference between the two approaches is that mine pushes a new device to the device ring on startup, whereas yours doesn't. I agree we should have an empty device ring on startup. (Furthermore I see that the started device in my PR is always Ark's, but we'd like the user to be able to override it e.g. to "quartz".)

@DavisVaughan DavisVaughan merged commit d7e1f8c into main Aug 27, 2025
6 checks passed
@DavisVaughan DavisVaughan deleted the fix/ark-graphics branch August 27, 2025 12:25
@github-actions github-actions bot locked and limited conversation to collaborators Aug 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants