quarto error: could not find function "ggplot"

Hello. I am trying to render my Quarto document, but it keeps giving me this error :

"! could not find function "ggplot"

Quitting from lines 113-115 [unnamed-chunk-8] (k.qmd)

Execution halted"

I haven't been using R for long, and it was previously working just fine with me. I checked all my codes and there's no mistakes in them. If all my codes are correct, what should I do?

Is there a library(ggplot2) call in a previous code chunk? Make sure it gets run.

I double checked and I already ran it both in console and in a previous chunk.

Thing is, when you compile a quarto document, it happens in a fresh environment: everything you ran in the console is temporarily forgotten (which is important for reproducibility).

I would suggest adding an additional library(ggplot2) in the same code chunk as the first ggplot() call, immediately before it. If that works, it will help pinpoint the problem.

1 Like

If you're encountering an error stating that R could not find the function "ggplot," it typically indicates that the required package, in this case, "ggplot2," is not installed or loaded in your R environment.

I'm recommend you put all libraries in the first chunk for avoid problems like this.