Rstudio won't interpret latex/RMarkDown - r

I've had a functioning RStudio setup for a while, on a Manjaro machine.
But suddenly it seems to no longer to able to interpret latex code. (Or is this an RMarkdown issue?). When I try to Knitr a pdf, I now get the following error message in the 'render' window:
You may need to add $ $ around a certain inline R expression r in Labb2New.Rmd (see the above hint). See https://github.com/rstudio/rmarkdown/issues/385 for more info.
Error: LaTeX failed to compile Labb2New.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Labb2New.log for more info.
Execution halted
What could be the issue here?
I've done no installation or updates (that I'm aware of) since Rstudio last worked.

There's tons of ways that you can compile Latex inside RMarkdown in RStudio, it can be confusing... so personally I did this:
Be sure to install everything in ONE SINGLE USER and not in the system, it could cause directory conflict and MiKtex somehow doesn't work for the whole systems, i read other comments where they can't solve that problem, me neither xD.
You should have all this requirements
R (you already installed it)
RStudio
MikTex
TeX Live
Install from CRAN
install.extras(repos = "http://cran.us.r-project.org")
THEN
## Install from CRAN
install.packages('rmarkdown')
Everything should work, you should have enough space memory to do this though. I just had this exact same problem yesterday so i reviewed my history x3
anyway if you have other problem with this process please feel free to tell me, be sure to read the documentations for what I listed there's lots of requirements inside, so probably is that!

Related

Why the vignette of my package is disapearing after a few time?

I encounter an issue regarding the vignette of a package I am developping in R. Vignette had been created using usethis::use_vignette. It is a Rmd file in the vignettes directory, and the DESCRIPTION file has the following inside :
Suggests:
testthat,
knitr,
rmarkdown
VignetteBuilder: knitr
The check throws one warning, but I think it isn't relevant ("'qpdf' is needed for checks on size reduction of PDFs")
Then I build my source package, and obtain a .tar.gz archive. When I install this (either with the graphic interface of RStudio or with install.packages), my vignette appears if I use ??my_package and is listed when I call vignette(). The installation process also mentions "installing vignettes" and everything seems ok.
However, after a few times the vignette just disapear, and is not findable anymore (or listed). I have not been able to determine what trigger this (this may be after a reboot but not always, sometimes this happens fast sometimes after a few hours...).
I am a bit confused with this, does anyone have an idea?
Many thanks to you!

R: kable_as_image cannot find Ghostscript

I'm re-running some R Markdown scripts that worked fine a month ago, but now kable_as_image is unable to find Ghostscript (yes, I'm on Windows 8). I get the following error message:
Error in kable_as_image(criteria.table,"Criteria",file_format="jpeg"):
Ghostscript is required to read PDF on windows. Please download it here: https://ghostscript.com/
My computer still has Ghostscript, which runs fine when I open it up independently (I tried reinstalling Ghostscript; it didn't help). My guess is that the problem has something to do with R, RStudio, or a package being unable to find the Ghostscript.
I'm pretty sure I've upgraded R in the interim, and I'm currently on 3.4.3 with the latest versions of kableExtra and magick. I've also tried
Sys.setenv(R_GSCMD="C:/Program Files/gs/gs9.22/bin/gswin64.exe")
(and also for gswin64c.exe) but that didn't help, either. Any advice would be appreciated.
Despite what the error message says, R needs the path to MikTeX (or your TeX program of choice), not to Ghostscript itself. The best solution is to add it to PATH in your operating system directly so it's always there, but it also works to add it within R. This is helpful to test it out before digging into your OS (make sure you have the right path), or if you don't have administrator privileges to your work machine.
Sys.setenv("PATH"=sprintf("%s;C:\\Users\\me\\AppData\\Local\\Programs\\MiKTeX 2.9\\miktex\\bin\\x64\\",Sys.getenv("PATH")))
Your path to MikTeX will likely be different than mine. Note that you need sprintf() or something similar to add the directory to the end of the PATH instead of overwriting the existing path.

yaml dependency in R won't update in Windows

I'm on a windows machine and I'm trying to knit an RMarkdown document with RStudio. When I press the 'knit' button in RStudio, I get a "requires an updated version of the yaml package" message. I install.packages("yaml") to find a message saying something along the lines of "binary source needs_compilation." I check the CRAN page for yaml and it seems that the Microsoft binaries are not up to date with the the more recent Mac version (2.1.14 < 2.1.15). I think this is the reason why I can't knit an RMarkdown document, but I do not know how to work around this.
This error popped up a few days ago and I'm not really sure how to fix it. I've been knitting documents pretty consistently until now and don't really know what to do.
Any help or guidance would be greatly appreciated.
#cedric's link helped out. I had to install() the yaml package using devtools

Knitr pandoc Execution halted in R

Knitr / Rmarkdown Execution halted
When I run Knitr and Rmarkdown, even with the knitr example scripts, I get the below error message.
Error in system(paste(shQuote(pandoc_path), "--version"), intern = TRUE) :
'"C:/Program Files/RStudio/bin/pandoc/pandoc"' not found
Calls: <Anonymous> ... get_pandoc_version -> with_pandoc_safe_environment -> force -> system Execution halted
I have installed and loaded knitr and rmarkdown from the libraries and alternatively using dev tools to get the most recent versions from github.
As it was working previously and I haven't changed any settings, I was wondering whether it might be due to the new R release and whether that has caused this?
I have tried uploading pandoc to the specific location it requested in the error but the online guidance was difficult to follow so didn't move into folder just it case it made it worst, as it was not required before I was confused as to why it was an error?
Not sure what else to try out, I have googled, stackflowed and explored knitr and pandoc webpages for any clues but with not success.
If anyone knows how to fix this as soon as possible I would be very grateful!!
I know this is a very old question, but I had the exact same issue, where knitting an Rmd file worked perfectly yesterday, and today, stopped working with the identical error message above. Even knitting the default Rmd starter document failed.
It's possible that a Windows patch was applied by our IS folks that may have broken something, as I had not changed my setup at all.
Doing a Sys.which('pandoc') suggested that it was looking in the wrong place (a user-specific location).
Updating RStudio did not help. Adding the following to my Rmd file also did not work:
Sys.setenv(RSTUDIO_PANDOC="PATH_TO_MY_PANDOC_BIN")
What eventually worked was a subset of the response by Ivo Fugers:
install.packages('installr')
install.pandoc()
(I wasn't paying close attention but think I allowed it to uninstall another version of pandoc.) After a system restart, knitting is working again.
Hope this helps folks in the future, as it seems to be a problem that still sporadically recurs.
I had a similar problem in a Statistical Computing class. A solution that worked for some of my classmates (including myself) is installing a few version of MikTex (takes about an hour). Otherwise, this is a solution that our teacher gave us:
So here is a possible strategy when you end up with a pandoc error, or when your Latex Equations do not show up in the 'markup':
Step 1
Re-install pandoc manually in your R console:
installing/loading the package:
if(!require(installr)) { install.packages("installr"); require(installr)} #load / install+load installr
Installing pandoc
install.pandoc()
Step 2
Download the the self-extracting protext.exe file from http://www.tug.org/protext/ . Install MikTex from this .exe file using the default settings...
2a. Make sure you allow Protext to install packages on the fly without asking permission.
Step 3
Look at https://tex.stackexchange.com/questions/81739/the-memory-dump-file-could-not-be-found , not the solution. Change the persmissions of all users in
C:\Users\YourUsername\AppData\Local\Temp
and
C:\Program Files\MikTex 2.9\
to full control.
How to do this? Go to C:\Users\YourUsername\AppData\Local , and right click on the folder Temp. Go to properties --> Security... and make sure all users listed there (even the trusted install) will have full control acces.
I faced the exact same problem yesterday and shocked because everything was working until day before yesterday. I was finishing my project in R markdown and it started throwing error.
Without having much help, I just have upgraded my RStudio to its latest version (0.98.1091). It took less than 10 minutes and everything started working as it was. I believe this sudden chocking was due to Windows patch update, but not 100% sure.
change your file name "C:/Program Files/RStudio/bin/pandoc/pandoc" into
"C:/ProgramFiles/RStudio/bin/pandoc/pandoc" or something else.
It doesn't allow space in the file address (like Program Files).

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