Knit working then suddenly not

I want to import the adjusted stock price data for 3 stocks so I can compare their returns. I had managed to knit the document with the code below then tried changing the captions to Returns_for_[stock name] and now it wont knit. The error message I am getting I have included below the code...

library(tidyquant)

library(tidyverse)
#library(broom)
library(knitr)
#library(kableExtra)

library(tinytex)
tinytex::install_tinytex() 

stocks1 <- tq_get(c("AZN"), get="stock.price", from = "2020-01-01")%>%
  select(symbol, date, adjusted)

stocks2 <- tq_get(c("XOM"), get="stock.price", from = "2020-01-01")%>%
  select(symbol, date, adjusted)

stocks3 <- tq_get(c("UNH"), get="stock.price", from = "2020-01-01")%>%
  select(symbol, date, adjusted)

head(stocks1, n = 6)%>%
  kable(caption = "Returns")

head(stocks2, n = 6)%>%
  kable(caption = "Returns")

head(stocks3, n = 6)%>%
  kable(caption = "Returns")`Preformatted text`

The error message I am receiving is below. I have TinyTex installed already, and also changed my captions to how they were when it kintted the document and it still won't know... Anyone know how I can fix it? I am using windows 11.

Error in `tinytex::install_tinytex()`:
! If you want to force installing TinyTeX anyway, use tinytex::install_tinytex(force = TRUE).
Backtrace:
    x
 1. \-tinytex::install_tinytex()
Warning messages:
1: In eng_r(options) :
  Failed to tidy R code in chunk 'unnamed-chunk-1'. Reason:
Error : The formatR package is required by the chunk option tidy = TRUE but not installed; tidy = TRUE will be ignored.

2: In eng_r(options) :
  Failed to tidy R code in chunk 'unnamed-chunk-2'. Reason:
Error : The formatR package is required by the chunk option tidy = TRUE but not installed; tidy = TRUE will be ignored.


Quitting from ecom2001-term-project-1.Rmd:27-55 [unnamed-chunk-2]
Execution halted

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

You shouldn't be installing packages while knitting. Comment out that line.

  1. Installing packages brings them from the internet (usually) into your computer.
  2. Loading via using library brings them from your computer to your session

You should only need to rarely install packages and it shouldn't be done in scripts. If you want to keep it as a reminder, comment it out.

3 Likes