knitr doesn't print plots in latex document [duplicate] - r

i have a knitr based Rnw file that is compiling to pdf perfectly fine in RStudio on mac (v0.97.316) and knitr (v1.1) but in a windows enviornment (same versions) i get a compilation error. I've checked the options in RStudio in both environments and they are consistent.
It appears that the windows setup is always injecting: "\SweaveOpts{concordance=TRUE}" into the ".tex" file even though i have no such flag in the Rnw file, and/or if i toggle the settings in the preferences, and/or if i add the "opts_knit$set(concordance=FALSE)" options to a knitr settings chunk. If i drop the line from the ".tex" file and compile it manually at the cmd prompt the output is generated as expected.
I'm not sure if this is an RStudio or knitr problem, but any pointers would be appreciated.
Note, i've also posted this question on the RStudio support board (http://support.rstudio.org/help/discussions/problems/5039-knitr-compile-problems-with-rstudio-windows?unresolve=true).

The reason that it was injecting \SweaveOpts{concordance=TRUE} is likely to be your weaver was Sweave instead of knitr, and you also enabled Rnw concordance: http://www.rstudio.com/ide/docs/authoring/rnw_weave But I cannot say for sure it is not a bug for the Windows version of RStudio. Anyway, it is easy to verify if it is an RStudio problem -- open the Compile PDF panel and you should see the log like this:
If your weaver was Sweave, you will see something like this instead:
This is my configuration (I'm under Ubuntu):
If you are using knitr indeed, and RStudio still inserts \SweaveOpts{concordance=TRUE}, I guess it must be a bug of RStudio.

I encountered this problem with "R CMD build KFAS-master" downloaded 2016-04-24 as "KFAS-master.zip" clicking "Download ZIP" from KFAS on GitHub (https://github.com/helske/KFAS). I'm unable to replicate the problem, but the work around I used was to find the line mentioned in the pop-up (copied below), and comment it out by preceding it with "%%".
After downloading it, I unzipped it and changed the name of the folder to "KFAS". Then I got a command prompt and navigated to the directory containing the KFAS-master folder renamed as KFAS. This time "R CMD build KFAS" worked as expected. Then I opened ~KFAS/vignettes/KFAS.Rmw in RStudio 0.99.893, the current version as of 2016-04-26. I changed something and saved the result. When I repeated "R CMD build KFAS", I got the problem portrayed in the image below.
Jouni Helske directed me to this post. I commented out line 69 mentioned in the screen shot below by prepending "%%" to "\SweaveOpts{concordance=TRUE}". I saved the result, and "R CMD build KFAS" worked.
Something seems to occasionally insert a line like "\SweaveOpts{concordance=TRUE}" into a *.Rnw file, but I don't know what it is. I'm running R 3.2.4 on a MacBook Pro with OS X 10.11.2.
Thanks to Yihui and others for earlier posts in this thread.
screen shot showing pop-up complaining, "It seems you are using the Sweave-specific syntax in line(s) 69... ."

I had the same problem even when knitr was set for "Weave Rnw files using" by default.
I solved it by going to Tools/Global Options/Sweave and setting "Weave Rnw files using" to Sweave and pressing Ok. Then, I went back and set it back to knitr, and everything works fine now.
I guess it was indeed Rstudio bug

Related

RMarkdown doesn't compile pdf caption.sty not found

I'm trying to knit an RMarkdown to a pdf but the code just doesn't compile. I'm on a Windows operating system.
This is the error message I get at the end:
! LaTeX Error: File `caption.sty' not found.
I've tried debugging by going through other posts on StackExchange like this one.
I can't seem to get it to work. I don't even know what a .sty extension really means, and I'm actually terrible with the Windows operating system, despite for having to use it here. I am not bad with the RStudio console, though. Is there anything I can do from within the RStudio environment to make this work? I've tried tinytex::install_tinytex() or tinytex::reinstall_tinytex() with no luck.

RStudio produces a TeX file with no errors, just warnings, but fails when it comes to showing the PDF

I am writing a book with knitr (not R-Markdown, nor Bookdown).
It is a multi-chapter book (like nearly all books), with child documents for each chapter. This all works fine. However when I work on my Windows machine, knitr processes the file fine, produces the latex, and then pdftex does its thing - with no errors, just warnings and badboxes, i.e. the usual LaTeX stuff, but finishes with this:
output file: chapter03.tex
[1] "chapter03.tex"
Running pdflatex.exe on chapter03.tex...failed
Issues: 23 warnings, 25 badboxes
This is true of every chapter I have worked on so far. It works fine on my Mac. It compiles fine and displays using MikTeX and TeXStudio with Windows -- again with no errors. Is there some evil Adobe thing that is stopping the PDF viewer from launching?
Update: I went back to my document and used knit2pdf. This compiled the document to a PDF without errors, and then clicking on the "Sync PDF view" button brought the compiled PDF up no issues. So, at least to me, this seems like it is still an R Studio issue - something to do with how the "Compile PDF" button is working.
I will try and create a minimal reprex.
Operating system is Windows 10 (up to date), with the latest version of r 3.6.3, R-Studio, and miktex 2.9 (also completely up-to-date).

RStudio not showing code in Rmd file, while Notepad does

I'm currently running into an issue of a .Rmd file opening in RStudio without actually populating the Source pane with the code. The file was written in RStudio, and the code shows up when I open the file in Notepad (and copies with the right formatting), but there's nothing showing up inside of RStudio.
Has anyone run into this issue before or have a good fix?
I had this same challenge too. I had to install Rstudio directly from CRAN and it works now, this issue probably happens with R studio installed via Anaconda.

Where does RStudio store the temporary R script files before saved?

I've just had RStudio crash on me unexpectedly, and on re-starting, contrary to what I've come to expect, the R script I had been tinkering around with was nowhere to be found.
I've managed to track down the Rhistory file so I'll be able to piece together all the commands, which is reassuring.
However, I am curious if there's somewhere I might try looking to find the temporary unsaved file on the off chance that might be cached somewhere (after all, it is usually cached somewhere that RStudio apparently knows to look). Is there a particular file extension/format I should be searching for?
Currently running R 3.3.1 through RStudio 0.99.903 on Linux Mint 17.3 (over Ubuntu 14.04.3 LTS).
I've tried running grep on the command line to find some of the more recently updated lines of code; I may be out of luck. I found two files:
~/.rstudio-desktop/history_database
Which appears to basically be a more centralized .Rhistory for RStudio
and
~/.rstudio-desktop/sdb/s-9CD2C698/D7986B2A
This looks JSON-like and also appears to basically be an Rhistory. Please correct me if I'm wrong.
As indicated by #KevinUshey from RStudio:
RStudio stores autosave data as part of the JSON 'blobs' within the sdb folder. You should see the document serialized as a long 'string', with newlines embedded.
Use packages such as jsonlite to parse this and best of luck.
if you used Rstudio on linux, the temporary R script files were stored in .rstudio/sources folder, and you can open all of the script files directly.
Good luck
In Rstudio if you saved or not a script but you ran this code, you can check the history off the app, this is the "telemetric data" that Rstudio has about you.
In windows, this is the path,
C:\Users\ANALISTA\AppData\Local\RStudio\history_database
you should use "visual studio code" or something similar to see it.

compiling minimal knitr example fails

I'm working on getting knitr setup. I installed the latest version of R (2.15.1), Lyx 2.0 including the MiKTex 2.9 distribution, and RStudio 0.96.304 on a Windows 7 Enterprise box. I can get pdflatex output if I open up Lyx and simply view the tutorial, so the basic system is working. I then downloaded the minimal Rnw example saved it in my working directory as testknitr.Snw, opened that file in RStudio, and pressed the compile PDF button. The knitr output completes with a single warning about the parser package, and produces a file testknitr.tex. pdflatex.exe then runs, but fails, and the particular error in the log file seems to be
! LaTeX Error: Environment alltt undefined.
I received the same error when attempting to compile testknitr.tex using TexWorks. I created that file from inside R using knit("testknitr.Rnw") - different extension because of the default in RStudio. I did tell MikTek to update packages automatically when compiling. A bit of research on CTAN suggests that the alltt environment is part of the ltxbase package, which is installed when I look at the package manager. In fact it seems like a pretty core part of the whole thing!
OK - I was reading the comments on the minimal example page, and discovered a workaround to that problem, and that it is a known bug as of 19 hours ago. And yes, I doublechecked that RStudio is set to use knitr, not sweave. I now get a new error:
! LaTeX Error: Command \textquotesingle unavailable in encoding T1.
EDIT: OK! it turns out that error isn't fatal - there's a lovely pdf of the minimal example sitting in the working directory if one takes the time to look. Somewhat alarming that RStudio thinks compilation failed when it didn't?
The workaround, perhaps obvious to an experience LaTex-ie, is to add
\usepackage{alltt}
to the file. According to Yihui's comment this will be fixed in future versions, or now if you want to get the development version from github. I also tested #Yihui's comment above that the line
\usepackage[T1]{fontenc}
could be commented out. This fixes the 2nd issue in the question, and RStudio now treats the compilation as successful, cleaning up (some?) intermediate files and immediately previewing the pdf.

Resources