daqana / tikzDevice

A R package for producing graphics output as PGF/TikZ code for use in TeX documents.
https://daqana.github.io/tikzDevice
132 stars 26 forks source link

ggsave unused argument (filename = filename) #181

Closed zapster closed 6 years ago

zapster commented 6 years ago

The following code fails with the current ggplot2 and tikzDevice versions.

library(ggplot2)
df <- data.frame(
  gp = factor(rep(letters[1:3], each = 10)),
  y = rnorm(30)
)
g <- ggplot(df, aes(gp, y)) + geom_point()

ggsave("plot.pdf", g, device=pdf) # OK 
ggsave("plot.tex", g, device=tikzDevice::tikz) # fail

I think the fix for https://github.com/tidyverse/ggplot2/issues/2355 broke tikzDevice when used with ggsave. Here is the corresponding commit: https://github.com/tidyverse/ggplot2/commit/a06e904cfb60af58cfd0bf9674b481758683298c

kylevoyto commented 6 years ago

I don't know whether my issue relates to tikzDevice as well, but I'm getting the same issue with ggsave unused argument (filename = filename) after updating to 3.0.0.

rstub commented 6 years ago

Thanks for the report @zapster!

Are you sure that ggsave("plot.pdf", g, device=pdf) works correctly? For me it throws the same error message, while ggsave("plot.pdf", g, device="pdf") or ggsave("plot.png", g, device=png) work correctly.

BTW, here some background for this issue:

https://github.com/daqana/tikzDevice/blob/0086e88a41160f02eb1e4236b731bdb5d242b836/R/tikz.R#L227-L229

Most likely we will update tikz() to accept both file and filename.

bellackn commented 6 years ago

Hello @zapster, latest version 0.12.1 fixes this. You can install it by devtools::install_github("daqana/tikzDevice"). Thanks for reporting this issue!

rstub commented 6 years ago

Alternative installation method if you already have the dependencies installed:

install.packages("tikzDevice", repo = 'http://www.daqana.org/drat')

General method:

if (!requireNamespace("drat", quietly = TRUE))
  install.packages("drat")
drat::addRepo("daqana")
install.packages("tikzDevice")
zapster commented 6 years ago

Thanks for fixing!