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

local_pdf (and probably other similar functions as well) does not restore device #138

Closed
gaborcsardi opened this issue Jun 17, 2020 · 3 comments · Fixed by #245
Closed
Labels
bug an unexpected problem or unintended behavior

Comments

@gaborcsardi
Copy link
Member

gaborcsardi commented Jun 17, 2020

Because the devices are in a circular ring, not in a stack (!!!).

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

Created on 2020-06-17 by the reprex package (v0.3.0)

(Without reprex, the first dev.cur() returns 3, probably reprex or knitr / evaluate are also messing with the devices.)

@jimhester
Copy link
Member

Yeah, I guess the tests never try opening multiple devices so don't run into this, definitely a bug.

@jimhester jimhester added the bug an unexpected problem or unintended behavior label Jun 17, 2020
@jimhester
Copy link
Member

While I agree it is very confusing, this behavior is consistent with what would happen if you open and close the devices manually, so I am not sure we should change it...

f <- function() {
  png("1.png")
  dev.off()
  invisible()
}
png("2.png")
png("3.png")
dev.cur()
#> quartz_off_screen 
#>                 4
f()
dev.cur()
#> quartz_off_screen 
#>                 2

Created on 2020-09-02 by the reprex package (v0.3.0)

@gaborcsardi
Copy link
Member Author

this behavior is consistent with what would happen if you open and close the devices manually

I am not sure withr needs to follow that. I think withr's contract is more like "create a temporary context, and then clean up side effects". I.e. a withr::with*(...) block should not have any side effect.

hadley added a commit that referenced this issue Jan 9, 2024
hadley added a commit that referenced this issue Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants