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

Restore previously opened device #245

Merged
merged 2 commits into from
Jan 10, 2024
Merged

Restore previously opened device #245

merged 2 commits into from
Jan 10, 2024

Conversation

hadley
Copy link
Member

@hadley hadley commented Jan 9, 2024

Fixes #138

@gaborcsardi
Copy link
Member

Do we want to handle this case?

f <- function() { 
  withr::local_pdf(tempfile())
  print(dev.cur())
  png("4.png")
  dev.cur() 
}
png("2.png")
png("3.png")

dev.cur()
#> quartz_off_screen
#>                 3

f()
#> pdf
#>   4
#> quartz_off_screen
#>                 5

dev.cur()
#> quartz_off_screen
#>                3

I.e. if the current device changes between the creation and the destruction of the temporary device, should we keep that new device, instead of restoring the one that was active before the temporary device. I think that would be more natural, and to do it we would need to check if we are closing the current device.

(And of course, if somebody closes the temporary device and creates a new one, then our exit handler will close that one, but since the device id is a simple number which is reused, we cannot do much about this.)

@lionel-
Copy link
Member

lionel- commented Jan 10, 2024

I.e. if the current device changes between the creation and the destruction of the temporary device, should we keep that new device, instead of restoring the one that was active before the temporary device. I think that would be more natural, and to do it we would need to check if we are closing the current device.

There is probably no ideal way here, so I think we should favour the simplest / most obvious behaviour. I think I like the guarantee that you can go back to working on the device that was active on entry once you exit a local_ / with_ context. It seems least surprising to me. Does that make sense?

@hadley hadley merged commit ceb26d9 into main Jan 10, 2024
11 checks passed
@hadley hadley deleted the device-order branch January 10, 2024 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

local_pdf (and probably other similar functions as well) does not restore device
3 participants