Skip to content

Make plot update smarter using magic null dev size#274

Merged
renkun-ken merged 2 commits intoREditorSupport:masterfrom
renkun-ken:check-null-dev
Apr 11, 2020
Merged

Make plot update smarter using magic null dev size#274
renkun-ken merged 2 commits intoREditorSupport:masterfrom
renkun-ken:check-null-dev

Conversation

@renkun-ken
Copy link
Copy Markdown
Member

@renkun-ken renkun-ken commented Mar 31, 2020

What problem did you solve?

Closes #271

This PR makes plot update smarter using a magic null dev size so that we can check if the current device is the NULL device we create as the default device to output graphics. I don't see if there's any better way to help us identify the device we create since user has very limited capability to set metadata and limited access to the information of a device.

Now plot file is open only when graphics functions are called with the NULL pdf device we create. So knitr::knit() no longer triggers opening existing plot file, and user created device such png or other pdf will not set plot_updated = TRUE so VSCode won't copy the graphics from the current device.

(If you have)Screenshot

(If you do not have screenshot) How can I check this pull request?

  • Basic plot
plot(rnorm(100))
abline(h = 0, col = "red")
# close the plot file
png("test.png") # should not open plot file
plot(rnorm(100)) # should not open plot file
dev.off() # should not open plot file
abline(v = 0, col = "blue") # should open the plot file
  • knitr::knit()
  1. Create a Rmd document (e.g. doc1.Rmd) with the following content:
# hello

Hello, world!

```{r}
plot(rnorm(100))
```
  1. Call knitr::knit("doc1.Rmd")
  2. When the function call completes, no plot file appears.
  3. Call plot(rnorm(10)) and the plot file is open. Close this file.
  4. Call knitr::knit("doc1.Rmd") again and the previous plot file is not open.

@renkun-ken renkun-ken requested a review from andycraig April 6, 2020 13:15
@andycraig
Copy link
Copy Markdown
Collaborator

@renkun-ken I tested this on Windows 10 and it works. If you are happy with it, please merge.

@renkun-ken renkun-ken merged commit 16ac229 into REditorSupport:master Apr 11, 2020
@renkun-ken
Copy link
Copy Markdown
Member Author

Thanks for testing!

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.

knitr::knit a document with plot code opens existing session plot file

2 participants