Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

questions on knit2pdf (output only allows ".tex" file extension, can't produce to different folder, no clean arg) #2113

Closed
shrektan opened this issue Mar 11, 2022 · 3 comments · Fixed by #2115

Comments

@shrektan
Copy link
Contributor

Hi,

I've been using knitr::knit2pdf() for years but there're some questions on designing that I don't quite understand since the very beginning:

  1. The output argument must be with ".tex" file extension. It just produces a pdf file with the same name. Since the name is knit2pdf(), shouldn't it allow a ".pdf" file extension?
  2. There's no way of removing the "tex" and "log" files, automatically.
  3. The value provided to the output argument must be in the same folder of the Rnw file. Why can't it allow generating the output into another folder?

Is it because of historical reasons or am I using the wrong function?

@shrektan shrektan changed the title why does the output argument in knit2pdf only allows ".tex" file extension questions on knit2pdf (output only allows ".tex" file extension, can't produce to different folder, no clean arg) Mar 11, 2022
@yihui
Copy link
Owner

yihui commented Mar 14, 2022

  1. The output argument is passed to knit(), which is why the file extension needs to be .tex instead of .pdf, but you are right that this is counterintuitive, and .pdf should be allowed.
  2. This function should have a clean argument.
  3. Path issues are usually quite complicated. The main problem is when the .tex file uses external files such as plots. Then we need to make sure the working directory for LaTeX is correct when compiling the document. For example, for knit2pdf('input.Rnw', output = 'another/dir/output.tex'), we have to make sure 1) the plots are generated to the correct dir, 2) the \includegraphics{} commands use the correct relative paths, and 3) LaTeX compiles the .tex file in the correct working directory, or specify the correct -output-directory argument to LaTeX (rstudio/tinytex@66a4e52).

1 and 2 are relatively easy to solve. For 3, the easiest solution might be generating the .pdf in the same directory as .Rnw first, and then move it to the desired directory. However, if the user doesn't have write permission of the directory of the .Rnw document, this solution won't work...

@shrektan
Copy link
Contributor Author

I think moving the pdf files to the desired destination is good enough and the most reliable way. If the user doesn't have the write permission, it shouldn't work any way.

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants