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

Space in output_dir in rmarkdown::render() #2128

Open
phargarten2 opened this issue May 4, 2021 · 3 comments
Open

Space in output_dir in rmarkdown::render() #2128

phargarten2 opened this issue May 4, 2021 · 3 comments
Assignees
Labels
feature a feature request or enhancement theme: paths path related improvment / issue

Comments

@phargarten2
Copy link

Using pdflatex, I ran into a problem compiling when output_dir had spaces in the filename rmarkdown::render(). pdflatex() gave the error Undefined control sequence. I realize that the file cannot be found due to a space in output_dir.

This problem has been well documented
https://stackoverflow.com/questions/57061618/error-generating-pdf-document-with-rmarkdown-when-output-dir-contains-spaces
#1285 (comment)
although pdflatex is somewhat more tolerant of spaces in the past.

       rmarkdown::render(
         input = "lab-specific-report.Rmd",    #name of child R Markdown file
         output_dir = "my_folder/pgm name/doc",  #Latex Fails with spaces 
         output_file = "My_File_1_Week_1",
         output_format = "pdf_document",
       )

Upon compiling, LaTex pdflatex gave this error:

Undefined control sequence
LaTeX Font Info:    Trying to load font information for T1+lmtt on input line 9
3.
(c:/Users/ph137/AppData/Roaming/TinyTeX/texmf-dist/tex/latex/lm/t1lmtt.fd
File: t1lmtt.fd 2015/05/01 v1.6.1 Font defs for Latin Modern
)

! Undefined control sequence.
 ...rmessage  LaTeX Error: File `my_folder/pgm name/doc
l.99 ..._/figure-latex/report-plots-1}
                                                   \end{center} 
Here is how much of TeX's memory you used:
 12231 strings out of 480954
 185972 string characters out of 5905841
 511514 words of memory out of 5000000
 29269 multiletter control sequences out of 15000+600000
 413278 words of font info for 37 fonts, out of 8000000 for 9000
 14 hyphenation exceptions out of 8191
 85i,3n,88p,668b,328s stack positions out of 5000i,500n,10000p,200000b,80000s

!  ==> Fatal error occurred, no output PDF file produced!

After reviewing Yui's comments (see #1285 (comment)), I suggest to add a warning in rmarkdown::render() indicating that the spaces in the filenames may cause LaTex to fail its compilation, maybe in pdflatex, but definitely in xelatex. Add something like this in the function:

if(length(grep(" ", output_dir, fixed = TRUE)) > 0){
  warning("The output directory contains a space. LaTex may have trouble finding files. Suggest to remove space if possible.",
          call. = FALSE)
} 

Other suggestions include using a relative directory (which I am not a fan of) or a temporary drive, but spaces throw off LaTex. I am not sure what to do if you can't remove spaces from the filename.

@cderv
Copy link
Collaborator

cderv commented May 5, 2021

Thanks for the report.

What about rendering the Rmd file where it lives (so not setting output_dir with a space in the path) and maybe move the rendered file after ?

This way the output directory should not impact the pdf rendering, is it ?

@phargarten2
Copy link
Author

phargarten2 commented May 5, 2021

Thank you. Yes, great idea. I agree that your comment should work. So you mean to set output_dir to its default, NULL (and move the rendered file after)?

Yet, if render() could warn a user that a space in output_dir exists, I think that would help the user identify the source of the problem, as the LaTex undefined control sequence error is often difficult to diagnose.

@cderv cderv added the feature a feature request or enhancement label May 10, 2021
@cderv
Copy link
Collaborator

cderv commented May 12, 2021

We could try add a warning for this. All the file input like output_dir, output_file, intermediate_dir, ... could be sensible to things like that and it is hard to know beforehand.

We could start with small step by adding a warning when we know this is necessary. Thanks for the suggestion !

@cderv cderv self-assigned this Dec 23, 2021
@cderv cderv moved this to Backlog in R Markdown Team Projects Dec 23, 2021
@cderv cderv moved this from Backlog to Todo in R Markdown Team Projects Dec 23, 2021
@cderv cderv added the theme: paths path related improvment / issue label Dec 23, 2021
@cderv cderv moved this from Todo to To discuss in R Markdown Team Projects Mar 8, 2022
@cderv cderv moved this from To discuss to Backlog in R Markdown Team Projects Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement theme: paths path related improvment / issue
Projects
Status: Backlog
Development

No branches or pull requests

2 participants