Error when compiling PDF using knitr - r

When I try to compile a PDF using knitr I get the following error:
there is no package called 'knitr' Error: object 'opts_knit' not found
Execution halted
I'm using RStudio 0.97.332 and R version 2.15.3.
What could be the problem?

It sounds like you need to install knitr. That should be fairly obvious from the error message.
install.packages("knitr")

you can:
install.packages("knitr")
or from Rstudio
Rstudio > Tools > install packages.
type knitr on the window install packages and install
In order to test if the package is installed try
library(knitr)

After installing knitr in R, do not forget to call it in a chunk somewhere before you use it.
I usually use my first chunk, right after \begin{document}, to call all libraries I use
i.e.
<<chunk0, >>=
library("knitr")
library("xtable")
...
#
Then a second chunk for knitr options.

Related

Unable to install conrib.url

I'm having trouble installing the contrib.url package in my RStudio on Windows. Please note that I am using the latest version of RStudio.
I have tried different means via resources I got online and from the R online community but I keep getting this error message:
"A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages"
I noticed I need this package because I am unable to knit my .Rmd files in HTML and PDF. I was advised to install tinytex and contrib.url. I have been able to install tinytex but couldn't get a way around installing contrib.url.
contrib.url is not an R package:
any(grepl("contrib.url", available.packages()))
[1] FALSE
It is a function from the utils package, though (which comes pre-installed):
?contrib.url
It can be used to specify the package type for repository URLs.
I have been able to knit the .Rmd file now to HTML. All I needed to do was to just comment out the install.packages() function before knitting and it was successful. Thanks all for your help!

rmarkdown::render() in cmd returns pandoc error

I need to render forms with rmarkdown from a command line
this is where I am:
knit button in RStudio works fine
function rmarkdown::render(file.rmd) in a .r file works when run in Rstudio
Then I tried running this command in CMD
c:\Program Files\R\R-4.0.2\bin\Rscript.exe" -e "rmarkdown::render('C:/file.rmd')
and I get this error:
Error: pandoc version 1.12.3 or higher is required and was not found (see the help page ?rmarkdown::pandoc_available).
In RStudio I sent
> rmarkdown::pandoc_available()
[1] TRUE
> rmarkdown::pandoc_version()
[1] ‘2.7.3’
What am I missing here?
By the way, I'm on Win10.
Thanks.
There might be an issue wit h Pandoc version, obviously. But maybe some library requires that older pandoc version, and the issue comes from you using Rmarkdown from outside Rstudio.
This link has the answer
Go into Rstudio and type
Sys.getenv("RSTUDIO_PANDOC")
Now take the output from the command above and put it here
Sys.setenv(RSTUDIO_PANDOC="OUTPUT FROM ABOVE COMMAND")

How to compile a pdf in RStudio Markdown?

I've just installed RStudio and I want to knit a pdf document and I get this error message red:
Error: LaTeX failed to compile
diapositivas-PRYE-bugfac8d2bfe22dfde4bdebadc8cd65b2798b315d7788f1f7bef1c4c579a8d5f325.tex.
See https://yihui.org/tinytex/r/#debugging for debugging tips. Además:
Warning messages: 1: In system2(..., stdout = if (use_file_stdout())
f1 else FALSE, stderr = f2) : '"pdflatex"' not found 2: In
system2(...) : '"pdflatex"' not found Ejecución interrumpida
No LaTeX installation detected (LaTeX is required to create PDF
output). You should install a LaTeX distribution for your platform:
https://www.latex-project.org/get/
If you are not sure, you may install TinyTeX in R:
tinytex::install_tinytex()
Otherwise consider MiKTeX on Windows - http://miktex.org
MacTeX on macOS - https://tug.org/mactex/ (NOTE: Download with
Safari rather than Chrome strongly recommended)
Linux: Use system package manager
I've tried installing the "knitr" package, and run this:
install.packages("knitr")
library(knitr)
tinytex::install_tinytex()
but still getting the same error.
Thanks in advance for any help,
Ivan.
So you've tried this.
install.packages("knitr")
library(knitr)
tinytex::install_tinytex()
But try this instead. You need to have the tinytex package to use it's install function.
install.packages("knitr")
library(knitr)
install.packages("tinytex")
tinytex::install_tinytex()
I always run into that same problem. Try knitting it to .html, opening the .html file, and then exporting the .html file to pdf.

pdfpages Latex package not found

I am trying to compile a pdfbook using R-markdown. After I knit I get the following error:
! LaTeX Error: File `pdfpages.sty' not found.
I loaded tiny text using library(tinytex) to help me install the package pdfpages but continue to have the same error. I resorted to running Rstudio in administrator mode and try the preceding step and running the following tinytex::parse_install(text="! LaTeX Error: File `pdfpages.sty' not found.") (as suggested in Yihui in bookdown). Both resulted in the same error.
Any other suggestion on what is wrong? The package is clearly installed, so I do not know what else can the error be.
Generally when you get an error like pdfpages.sty not found, you need to install the package. From the command line (assuming the Tex bin is in your path) use "tlmgr install pdfpages". Yihui Xie called it "TinyTex" because it was a minimal install compared to something like MacTeX or TexLive.

R evaluate_call() error [duplicate]

I am getting below Parsing error each time I use Knit Html in R for converting my Rmd files into HTML:
Error in parse_all(input, filename, stop_on_error != 2L) : unused
argument (stop_on_error != 2) Calls: ... call_block ->
block_exec -> in_dir -> evaluate -> parse_all
Execution halted
Same result is obtained when using knitr or knitr:knit2html from the command line. Error did not exist before (I have already used Knit HTML for many .Rmd reports) but appeared when I used knit2html from the cmd for the first time. The compilation is only working where there are no R code chunks in the .Rmd file or when the chunks are empty. I work under windows 7, R version: 3.2.3, R studio version: 0.99.902. Below is the only R code chunk in the test.Rmd file that I am using for testing:
```{r}
i <- 0
i < i + 3
i
```
After seeing the same error, the following (updating evaluate package) helped me
install.packages("evaluate")
Evaluate is used by knitr. Here is a link to CRAN about evaluate:
https://cran.rstudio.com/web/packages/evaluate/index.html
My R version is 3.2.4. There is no need to do any complicated re-installs. Try this first.
Yes, Vincent is right. You seem to have updated your knitr package to version 1.13 in the last days. This version only runs under the new R version 3.3.0 (also released a couple days ago).
You have two options:
Update R to version 3.3.0
Revert your knitr installation to version 1.12 using the following code:
packageurl <- "http://cran.r-project.org/src/contrib/Archive/knitr/knitr_1.12.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
I faced with the same exact problem, hence I came up with this page. Based on the suggestions, I installed R version 3.3.0, and uninstalled 3.2.4. I re-installed the packages. However, fread function stopped working. I read that it might be related to dll's being messed up etc. Then I completely uninstalled R, and Rstudio. I also deleted the library folder where the packages are installed. Re-installed R, then Rstudio (latest version 0.99.902), then the packages. Now everything is working fine.

Resources