I can't get the R package tikzDevice
to running. I installed MiKTex and I don't have problems to produce documents like this one via TeXworks.
Exporting plots via tikzDevice unfortunately doesn't work, for example the following code from here produces an error message:
library(tikzDevice)
library(ggplot2)
#For some reason, Rstudio needs to know the time zone...
options(tz="CA")
#Dummy data for the plot
y <- exp(seq(1,10,.1))
x <- 1:length(y)
data <- data.frame(x = x, y = y)
#Create a .tex file that will contain your plot as vectors
#You need to set the size of your plot here, if you do it in LaTeX,
#font consistency with the rest of the document will be lost
tikz(file = "plot_test.tex", width = 5, height = 5)
#Simple plot of the dummy data using LaTeX elements
plot <- ggplot(data, aes(x = x, y = y)) +
geom_line() +
#Space does not appear after Latex
ggtitle( paste("Fancy \\LaTeX ", "\\hspace{0.01cm} title")) +
labs( x = "$x$ = Time", y = "$\\Phi$ = Innovation output") +
theme_bw()
#This line is only necessary if you want to preview the plot right after compiling
print(plot)
#Necessary to close or the tikxDevice .tex file will not be written
dev.off()
The following error message is produced:
Measuring dimensions of: \char77
Error in get_latex_cmd(TeXMetrics$engine) :
Cannot find LaTeX! Please check your system configuration or manually provide a value for options(tikzLatex)
I couldn't find a discussion about that problem on Google or here so I would appreciate some help.
Your LaTex file is not set in your library. In my case it's the pdflatex file. You can add an pdftex, xetex or luatex file.
easy attempt:
Try to reinstall your library or your latex if possible, that should be an easy way to clean install it.
Set your Variable manually
On Linux:
With
i generate the output
so this is my path to the latex file and this is what's missing in your case. So we need to add it.
You can check where your Latex file is with the command in the Terminal:
so if you figured out the path to your file you set it with:
Windows
i'm not a windows user, so i just can guess it's the same way. The similar command on Windows for finding your file is the
where
command where command on windowsSetting your Variable should be the same. Would be nice if someone could confirm this.
Edit: a windows solution is provided by Mason Malone in the commentary of the question
"For Windows User's it does work the same way for Windows users. Open the Windows command prompt (Start > type "Command Prompt" > enter).
Type the following:
where pdflatex
Copy the file path that it gives you, e.g.:C:\Users\user1\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64\pdflatex.exe
In R, type the following:
options("tikzLatex"='C:/Users/user1/AppData/Local/Programs/MiKTeX 2.9/miktex/bin/x64/pdflatex.exe')
Note that for the file path we are given via the command prompt, it has backslashes
, but in R we have to type forward slashes /
. "