0

currently trying to get an output .pdf file for an R assignment, but I keep getting stuck on the following error:

Error in install.packages(update[instlib == l, "Package"], l, repos = repos,  : 
  unable to install packages
Calls: <Anonymous> ... eval -> eval -> update.packages -> install.packages

I uninstalled MikTex, to install TinyTex through R in the markdown file:

```{r data description, include=FALSE}
tinytex::install_tinytex(force=TRUE)
update.packages(ask = FALSE, checkBuilt = TRUE, repos='http://cran.us.r-project.org')
tinytex::tlmgr_update()
options(tinytex.verbose=TRUE)
library(tinytex)
```

for all packages in the document I use the same source (repos='http://cran.us.r-project.org'). Only when I tried to install Tinytex for formatting the .pdf output file did I start to get these errors.

Previous error was:

Error: LaTeX failed to compile APB_EXAM_markdown.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See APB_EXAM_markdown.log for more info.

I'm not quite understanding what the problem is: I only have TinyTex installed as above and tried the troubleshooting steps from yihui.org, but still my file fails to give me a .pdf output.

Any help would be very appreciated.

shafee
  • 15,566
  • 3
  • 19
  • 47
Hieuwd
  • 35
  • 5
  • Does it work if you run `update.packages()` directly in the console? That seems to be what’s generating the error, not `install_tinytex()`. – zephryl Dec 02 '22 at 13:34
  • 2
    It also doesn’t seem like great practice to include install or update commands in R markdown. You know you only have to install packages and tinytex once, not every time you use them, right? – zephryl Dec 02 '22 at 13:37
  • [This thread](https://stackoverflow.com/q/21461649/17303805) on `update.packages()` may also be helpful. e.g., you can’t update a package if it’s currently loaded. – zephryl Dec 02 '22 at 13:40
  • 1
    It is strongly recommended that you do not install anything in your markdown document. You should only be loading libraries. Install packages or system dependencies should be done outside the document. – MrFlick Dec 02 '22 at 14:38
  • I was in fact not aware that I only had to install all packages in the console, not the markdown file. I have removed all the install.packages code, and made sure the packages were installed (through the console). I've tried updating all packages multiple times, and have followed the debugging tips from https://yihui.org/tinytex/r/#debugging, but I am still getting the same error. There is no MikTex or other on my computer, only TinyTex installed according to yihui/org's instructions. – Hieuwd Dec 21 '22 at 11:51

0 Answers0