Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upRStudio 1.4 support? #31
Comments
|
Thanks for sharing the news. This looks like an interesting update. I'll try the new RStudio when it is released. |
|
Sounds good, thanks for considering. In case you didn't know, RStudio 1. 4 is currently available in the daily builds https://dailies.rstudio.com/ |
|
Good to know that. I'll have a try when I get some time for this. |
|
Tracing back to rstudio/rstudio#2142, I accidentally found a workaround for the issue with RStudio 1.3 or earlier. Basically you just need to run the following code at the beginning of each R session: trace(grDevices::png, exit = quote({
showtext::showtext_begin()
}), print = FALSE)And then run any library(showtext)
font_add_google("Lobster", "lobster")
showtext_auto()
plot(1, pch = 16, cex = 3)
text(1, 1.1, "A fancy dot", family = "lobster", col = "steelblue", cex = 3)Can you test if it works for you? |
|
Nice, can confirm this works on RStudio Preview (1.3.952). I did notice, though, that exporting to pdf via the export dropdown doesn't appear to work |
|
Then you just need to add another tracer: trace(grDevices::pdf, exit = quote({
showtext::showtext_begin()
}), print = FALSE) |
|
Interestingly it appears that if the RStudioGD is already open, this plot(1)then trace(grDevices::png, exit = quote({
showtext::showtext_begin()
}), print = FALSE)This no longer works library(showtext)
font_add_google("Lobster", "lobster")
showtext_auto()
plot(1, pch = 16, cex = 3)
text(1, 1.1, "A fancy dot", family = "lobster", col = "steelblue", cex = 3) |
|
The thing is, RStudio will open a new PNG device after it plots, so the device might be already open before plot(1)
trace(grDevices::png, exit = quote({
showtext::showtext_begin()
}), print = FALSE)
# Force the new device to apply tracer
plot.new()
library(showtext)
font_add_google("Lobster", "lobster")
showtext_auto()
plot(1, pch = 16, cex = 3)
text(1, 1.1, "A fancy dot", family = "lobster", col = "steelblue", cex = 3) |
|
Oh, I see, so RStudio must close and open a new device on every |
|
This is my guess, but may be wrong. RStudioGD seems to have some sophisticated operations at the backend. Something that may be useful for checking is to set
In one of my sessions, the result is
I check the last PNG file and it is 0 byte, so it should be used for future plots. |
|
As the new version is already on CRAN, I guess we can close this issue first. |
Just FYI, RStudio 1.4 comes with the capability of customizing the graphics backend. Perhaps showtext could leverage that new ability to render fonts in the RStudio graphics device?