Closed aavogt closed 2 months ago
Using source all on this works for me (ie. h.png
is created)
library(ggplot2)
png(file = "h.png", width = 400, height = 200)
ggplot(mtcars, aes(x = mpg)) +
geom_histogram()
dev.off()
I confirm the bug. I get the expected output after <LocalLeader>aa
with @PMassicotte's code, but not with @aavogt's one. The code of nvimcom:::source.and.clean
is:
function (f, ...) {
on.exit(unlink(f))
base::source(f, ...)
}
I don't know what might be wrong...
Interesting, removing the comments will make it work:
library(tidyverse)
library(ggplot2)
# df <- Sys.glob("*.csv") %>%
# map_dfr(~ {
# cbind(f = ., read_csv(., col_names = c("T", "h")))
# })
#
# # cat(deparse(dir()))
# ns <- c("10kPa.csv" = 10, "150kPa.csv" = 150, "18e-3kPa.csv" = 18e-3, "220kPa.csv" = 220, "80.5kPa.csv" = 80.5)
# df$p <- ns[df$f]
# write_csv(df, "df.csv")
df <- tribble(
~f, ~T, ~h, ~p,
"10kPa.csv", round(41.13252472675314, 2), round(4.575119307705421, 2), 10
)
png(file = "h.png", width = 400L, height = 200L)
ggplot(df, aes(p, h, col = T)) +
ylab("h / (W/m²K)") +
xlab("p / kPa") +
geom_point() +
theme_minimal() +
ggtitle("h = a * p^b")
dev.off()
print(system("file h.png", intern = T))
But this is working
library(tidyverse)
library(ggplot2)
# df <- Sys.glob("*.csv") %>%
# map_dfr(~ {
# cbind(f = ., read_csv(., col_names = c("T", "h")))
# })
#
png(file = "h.png", width = 400L, height = 200L)
ggplot(mtcars, aes(x = mpg)) +
geom_histogram()
dev.off()
print(system("file h.png", intern = TRUE))
system("rm h.png")
Note the difference in the comment. Looks like a base R issue?
I agree that it seems to be an issue with base::source
. The results are identical if we run base::source()
manually on the R Console.
We need a minimal example to put in the Known bugs section and close this issue.
@aavogt, could you please try this in your R.nvim
config:
source_args = "print.eval = TRUE",
Your issue seems to be the opposite of #216
From source
help:
Note that running code via
source
differs in a few respects from entering it at the R command line. Since expressions are not executed at the top level, auto-printing is not done. So you will need to include explicitlattice
, FAQ Q7.22).
It seems that we should set print.eval=TRUE
by default as we have done for nvimcom:::Rnvim.source
.
It seems that we should set
print.eval=TRUE
by default as we have done fornvimcom:::Rnvim.source
.
Would make sens.
@aavogt, could you try the print_eval
branch, please?
If I send the png / ggplot / dev.off() lines with
<localleader>l
, it correctly makes theh.png
. If I send the whole file I don't get the h.png (ie."h.png: cannot open `h.png' (No such file or directory)"
). If I addplot( ggplot ... )
or remove some of the apparently unnecessary lines, I get the h.png.df.csv