3

I need to generate a pdf from a tex file, as a temporary file. However I'm facing an error. I believe it's due to the fact that the function tools::texi2dvi is just a call for the system command with the same name. Since the Rtmp directory just allow R to create files, I can't create the pdf file there.

There's what I'm trying to the, and the error I get:

> tf <- tempfile()
> brew("template.brew", tf)
> tools::texi2dvi(tf)

Error in tools::texi2dvi(tf) : 
    Running 'texi2dvi' on '/tmp/Rtmp9n4JFU/filea5811e6a32a' failed.
Messages:
    /usr/bin/texi2dvi: etex exited with bad status, quitting.

I believe one workaround would be create a new temporary file using tempfile() and ask tools::texi2dvi to write the output on it. However I don't know if the system is allowed to edit a file. And also, I couldn't find a way to set tools::texi2dvi output file.

Does anyone know a workaround?

Thanks!

1
  • 2
    Try using setwd() to change the working directory before calling tex2dvi.
    – Andrie
    Feb 9, 2012 at 12:22

1 Answer 1

2

TeX is apparently confused by the lack of file extension. The following should work.

tf <- tempfile(fileext=".tex")
cat(
  "\\documentclass{minimal}\\begin{document}test\\end{document}", 
  file=tf
)
tools::texi2dvi(tf)
2
  • You're right! Now I could generate the pdf. However, the pdf file is generated into my working directory (home directory) and not into the same folder that the tex file (temporary working dir). Is there any way to set texi2dvi output file? Feb 9, 2012 at 12:39
  • That is apparently the indented behaviour of texi2dvi. You can change the working directory before calling texi2dvi, as suggested in Andrie's comment above, and change it back to what it was, after: oldwd <- getwd(); setwd(tempdir()); ... ; setwd(oldwd) Feb 9, 2012 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.