title: How to knit to pdf in r markdown file?
body: <p>I had a r markdown file copied from Roger Peng's tutorial. And I was able to knit to html and Word but had problems knitting to pdf. The test.Rmd code:  </p>
  
  <pre><code>My First Knitr Document
  ===============================
  
  This is some text (i.e. a text chunk).
  
  here is a code chunk
  ```{r}
  set.seed(1)
  x &lt;- rnorm(100)
  mean(x)
  ```  
  </code></pre>
  
  <p>After clicking 'knit to pdf', error:  </p>
  
  <pre><code>Output created: test.pdf
  Error in tools::file_path_as_absolute(output_file) : 
  file 'test.pdf' does not exist
  Calls: &lt;Anonymous&gt; -&gt; &lt;Anonymous&gt;
  In addition: Warning messages:
  1: running command '"pdflatex" -halt-on-error -interaction=batchmode 
  "test.tex"' had status 1 
  2: In readLines(logfile) : incomplete final line found on 'test.log'
  Execution halted  
  </code></pre>
  
  <p>When I run 'latexmk -version' in cmd (windows), I got:  </p>
  
  <pre><code>latexmk: warning: running with administrator privileges
  latexmk: The script engine  could not be found
  latexmk: Data: scriptEngine="perl.exe"  
  </code></pre>
  
  <p>My session info:  </p>
  
  <pre><code>R version 3.4.4 (2018-03-15)
  Platform: x86_64-w64-mingw32/x64 (64-bit)
  Running under: Windows 7 x64 (build 7601) Service Pack 1
  
  Matrix products: default
  
  locale:
  [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
  [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
  [5] LC_TIME=English_United States.1252    
  
  attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base     
  
  other attached packages:
  [1] tinytex_0.4 sp_1.2-7   
  
  loaded via a namespace (and not attached):
  [1] Rcpp_0.12.16    lattice_0.20-35 withr_2.1.2     digest_0.6.15   
  rprojroot_1.3-2 grid_3.4.4     
  [7] R6_2.2.2        backports_1.1.2 magrittr_1.5    evaluate_0.10.1 
  httr_1.3.1      stringi_1.1.7  
  [13] rmarkdown_1.9   devtools_1.13.5 tools_3.4.4     stringr_1.3.0   
  yaml_2.1.18     compiler_3.4.4 
  [19] memoise_1.1.0   htmltools_0.3.6 knitr_1.20   
  </code></pre>
  
  <p>My MikTex version: basic-miktex-2.9.6.  </p>
  
  <p><strong>Updated</strong>, to be more precise, the same code worked well on mac (R version 3.4.0 though).<br>
  More information: I installed RStudio on E disk while MikTex on C disk.<br>
  <strong>Also</strong>, I am able to use R Sweave compile pdf.</p>
  
  <p>I appreciate if anyone could help.   </p>