title: Error 43 while knitting a r markdown to pdf on rStudio on Windows
body: <p>I'm running a rStudio project on the Windows of a colleague (I work on mac, so I'm not in my waters).</p>
  
  <p>When I tried to compile to pdf an .rmd file I get this error:</p>
  
  <pre><code>"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS Plot_per_DPUO.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output "Grafici Professioni/Periodo apr-14 ott-15 test/DH ALLERGOLOGIA - SAN PAOLO.pdf" --template "C:\Users\lucilla.rava\Documents\R\win-library\3.1\rmarkdown\rmd\latex\default.tex" --highlight-style tango --latex-engine pdflatex --variable "geometry:margin=1in" 
  pandoc.exe: Could not find image `Grafici%20Professioni\Periodo%20apr-14%20ott-15%20test\DH%20ALLERGOLOGIA%20-%20SAN%20PAOLO_files/figure-latex/set-options-1.pdf', skipping...
  pandoc.exe: Error producing PDF from TeX source.
  ! I can't find file `C:/Users/LUCILL'.
  &lt;to be read again&gt; 
                     \protect 
  &lt;*&gt; C:/Users/LUCILL~
                      1.RAV/AppData/Local/Temp/tex2pdf.3172/input.tex
  Please type another input file name
  ! Emergency stop.
  &lt;to be read again&gt; 
                     \protect 
  &lt;*&gt; C:/Users/LUCILL~
                      1.RAV/AppData/Local/Temp/tex2pdf.3172/input.tex
  !  ==&gt; Fatal error occurred, no output PDF file produced!
  Transcript written on C:/Users/LUCILL~1.RAV/AppData/Local/Temp/tex2pdf.3172/tex
  put.log.
  
   Show Traceback
  
   Rerun with Debug
   Error: pandoc document conversion failed with error 43 
  </code></pre>
  
  <p>I left the full paths because I noticed something strange in the user path. 
  The log prints this snippet:</p>
  
  <pre><code>`C:/Users/LUCILL'.
      &lt;to be read again&gt; 
                         \protect 
      &lt;*&gt; C:/Users/LUCILL~
                          1.RAV
  </code></pre>
  
  <p>where the user name is different from how it should be (lucilla.rava).</p>
  
  <p>On mac the compiling doesn't give errors, so the problem shouldn't be in the code.</p>
  
  <p>Of Note: I created the project on my Mac in a folder shared via google drive.</p>
  
  <p>UPDATE 1: Thanks to @Gnusper we noticed that there is a path separator error. Unix and Windows paths are mixed. I need a way to remove the mixing.</p>
  
  <p>In my code I defined the paths with the following code:</p>
  
  <pre><code>    months.vec &lt;- get.months(unique(Data$Periodo))
      months.vec &lt;- format(months.vec, '%b-%y')
  
      if (type == 1) folder.name &lt;- 'Grafici Generali'
      else if (type == 2) folder.name &lt;- 'Grafici Professioni'
      else if (type == 3) folder.name &lt;- 'Grafici Indicazioni'
  
      folder.path &lt;- file.path(folder.name, sprintf('Periodo %s %s%s', months.vec[1], tail(months.vec, 1), test))
  
      dir.create(folder.path, recursive = T, showWarnings = F)
  
      for (UO in unique(Data$UO)[1:5]) {
          print(file.path(folder.path, sprintf('%s.pdf', sub(pattern = "/", replacement = ' ', UO, fixed = T))))
          render('Plot per DPUO.Rmd', clean = T, output_file = file.path(folder.path, sprintf('%s.pdf', sub(pattern = "/", replacement = ' ', UO, fixed = T))))
      }
  </code></pre>
  
  <p>I made some test with a brand new R project on the windows machine with these results:</p>
  
  <pre><code>&gt; file.path('affs', '0sdfsdf')
  [1] "affs/0sdfsdf"
  &gt; .Platform$file.sep
  [1] "/"
  &gt; 
  </code></pre>
  
  <p>The path separator is still Unix like. Reading the help of file.path I found this:</p>
  
  <blockquote>
    <p>file.path(..., fsep = .Platform$file.sep)</p>
    
    <p>[...]</p>
    
    <p>Note</p>
    
    <p>The components are by default separated by / (not ) on Windows.</p>
  </blockquote>
  
  <p>For some reason the function implements the Unix separator also on windows... 
  I tried then to run .Platform$file.sep &lt;- '\\'. But when I use file.path() I still get the '/' separator. So fsep = .Platform$file.sep in the arguments it's not evaluated each time the function is run.</p>
  
  <p>In the new project I made more tests:</p>
  
  <pre><code>dir.create(file.path('ssdg','fgsfdg'), recursive = T, showWarnings = F)
  write(c(1,2,3,4,5), file = 'ssdg/fgsfdg/test.txt')
  write(c(1,2,3,4,5), file = 'ssdg\\fgsfdg\\test2.txt')
  write(c(1,2,3,4,5), file = 'ssdg/fgsfdg\\test3.txt')
  </code></pre>
  
  <p>all of them work and create the file. I also tried dir.create() with various separators combinations and all of them work. Seems like R understand what to do when managing files and correct the separators.</p>
  
  <p>But since the compiling of the .rmd file is performed by pandoc via a shell command, the mix of separators is not fixed and the error occurs.</p>
  
  <p>I find very odd thought that in the error log, pandoc is called with an Unix path </p>
  
  <blockquote>
    <p>C:/Program Files/RStudio/bin/pandoc/pandoc</p>
  </blockquote>
  
  <p>How is pandoc able to run and raise the error??</p>
  
  <p>Summing up I need my code to run on both platforms.</p>
  
  <p>UPDATE 2: I tried removing white spaces from every paths in my code. Also I tried to move the scripts and rmd file to a new project in local folder, to check for problems introduced by having a shared project on GoogleDrive. 
  No improvements whatsoever.</p>
  
  <p>UPDATE 3: I posted the problem as an issue on <a href="https://github.com/rstudio/rmarkdown/issues/574" rel="nofollow">https://github.com/rstudio/rmarkdown</a>. I implemented the suggestion I was given there (creating the output first in the same folder as the project and then move it to the actual destination folder) but with no luck. however I am pretty sure now that the problem is in the creation and retrieval of the temporary files.</p>
  
  <p>If I run tempdir() on windows it returns:</p>
  
  <pre><code>tempdir()
  [1] "C:\\Users\\LUCILL~1.RAV\\AppData\\Local\\Temp\\RtmpUrsOgH"
  </code></pre>
  
  <p>with the strange shorten user name which is also reported in the error log.</p>
  
  <p>If I run:</p>
  
  <pre><code>normalizePath(tempdir())
  [1] "C:\\Users\\lucilla.rava\\AppData\\Loc
  </code></pre>
  
  <p>I get the correct path. </p>
  
  <p>UPDATE 4:
  If it can be useful: I need to set up the path for pdftext every time I open the R project.</p>
  
  <p>In a .Rprofile file I declare:</p>
  
  <pre><code>Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64", sep = .Platform$path.sep))
  </code></pre>
  
  <p>UPDATE 5: 
  Odd as it seems, we moved to a new windows computer, and the knitting this time worked. No idea why... Nevertheless if someone still has any idea why would be appreciated, since the other computer is the main workstation of my colleague.</p>