Error with knitr on texmaker - r

I am trying for the first time to get knitr running on texmaker, I followed this documentation and I am on Windows 7. However, when I compile, I get the following error stack:
Process started
Error in readLines(if (is.character(input2)) { : cannot open the connection Calls: <Anonymous> -> knit -> readLines
In addition: Warning message: In readLines(if (is.character(input2)) { : cannot open file 'try_easy.Rnw': No such file or directory
Execution halted
Process exited with error(s)
I tried to google it, but only found references to linux/unix, which were not helpful for my case. Following is my short test document:
\documentclass[a4paper]{article}
\begin{document}
<<a>>=
x=rnorm(100)
<<b>>=
<<a>>
mean(x)
#
\end{document}
It's my first time on stackoverflow, so please tell me if you need more information or I did something wrong. Thank you very much.
Update
Hello everyone,
I managed to find out my mistake. For the sake of future google-searchers, I had saved the file as a .tex instead as .rnw. Saving as rnw solved it. Since I cannot answer my own questions, I edit it here.

This error happens when the file is saved as a .tex instead of a .Rnw, as the compiler does not know that he should "knitr-compile" files that have the .tex handle, unless you specifically set him up like that.

Related

Rmarkdown tabu.sty error in PDF output with libraries

Hello R community i'm trying to knit a pdf document, but get an error and cannot find the right answer in any forum. I'm using the latest R(4.1) and Rstudio(1.4). I have MiKTeX installed but I can not get a pdf to write unless I changed the global setting in R to write from tiny tex.
I have isolated the problem in the script. If I try to knit the document without loading any libraries, the document WILL knit. If I try to knit with libraries, then I throw a tabu.sty error. The problem here is I need the libraries for tables, graphs, etc.
! LaTeX Error: File `tabu.sty' not found.
! Emergency stop.
<read *>
Error: LaTeX failed to compile Chapter0.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Chapter0.log for more info.
Execution halted```

Could not Publish (TypeError): null is not and object (evaluating b.g.) - Rmarkdown

I'm trying to publish an RMarkdown document to my RPubs account, but I get the next error when clicking on "Publish":
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
cannot open file 'C:/Users/.../File.Rmd': No such file or directory
It also pops up a window saying the next two warnings:
First pop up: "Could not Publish - Error ocurred while executing method"
Second pop up: "Could not Publish - (TypeError): null is not an object evaluating 'b.g.')
My R version is 3.4.2, RStudio version is 1.1.383, knitr version is 1.17.
I have also checked is the working directory contains the files I'm using at the script, and all seems properly set.
This error only happens when I click on Publish. If I try to knit to HTML or to PDF it works. I have tried to restart and reinstall also both R and RStudio but the error persists.
Has anyone had the same error and knows how to solve it?
Thank you very much!
Is the file saved? Are you in the correct directory?
Please check getwd().
I managed to solve it. The problem was that the path of the working directory contained an accent. I changed the path to another folder without accents and it worked.

Error in R while compiling the markdown

I am trying to save a xgboost code in Rmarkdown to knit HTML document. I am getting an error.
The code is completely executable in "R".
Fatal error: creation of tmpfile failed -- set TMPDIR suitably?
The error is same when I try to run knit Pdf/word.
Someone please help me.
Thank you
It seems the temporary directory cannot be created. Trying making your own temporary directory or setting it to the working directory:
Sys.setenv(TMPDIR = ".")

knit2pdf failing to produce pdf in Shiny Apps

As the title states, I am attempting create a shiny application that can generate a pdf file that a user can then download. (Note that this is not a duplicate question because I have not found a question with a similar error)
In my search for a solution, I found this gist by the Knitr package author: https://gist.github.com/yihui/6091942, which I am attempting to recreate. There are also questions on S.O that use the same code, out = knit2pdf('input.Rnw', clean = TRUE) but all of them seem to date to before the 3.2.3 release of R.
The error I am given is:
output file: input.tex
Warning: running command '"pdflatex" -interaction=nonstopmode "input.tex"' had status 1
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, :
unable to run 'pdflatex' on 'input.tex'
Warning: Error in texi2dvi: unable to run 'pdflatex' on 'input.tex'
Stack trace (innermost first):
52: texi2dvi
51: tools::texi2pdf
50: knit2pdf
49: download$func [D:...\App-2/server.R#44]
1: shiny::runApp
What I have tried so far:
Updating R, RStudio, knitr package and my TeX distribution (TeXLive). I know that TeXLive is not the issue as I use it daily, and I can create a dummy .Rnw that will compile perfectly using the Compile PDF button in R Studio. I have also tried using knit() or render() and those will generate .tex files without giving an error. I have also changed my working directory to the app folder as suggested by another S.O. question, but that didn't solve my problem either.
Edit, Additional information: I am using Windows 10
Any suggestions welcome!
I don't think TeXLive is working completely. On Windows, RStudio recommends using MiKTeX, and so does Pandoc.

New error when knitting get_engine(options$engine)

I have an .Rmd file that previously had knitted without any problems. Now I am getting the following error when executing this instruction
confusionMatrix(prediction1, ssTesting$classe)
The error is
Error in get_engine(options$engine) : Unknown language engine 'test' (must be registered via knit_engines$set())
If I execute each chunk independently the error does not occur.
It only happens if I knit.
The error is independent of using version R-3.1.2 or R-3.2.1. I also set all the cache options to FALSE and made sure that all the libraries were correct but the error keeps appearing.
A simple typo in the beginning of the chunk ... ```{rtest.mod1} instead of ```{r test.mod1}
Hard to see but simple to fix.

Resources