Quarto can't find R-objects

When trying to render a quarto presentation, whether from a terminal with quarto_render or by just clicking the render-icon in Rstudio, any object that is in the environment is not seen by quartro.

When using this code from the hello.qmd file by Quarto, it will render.

#| warning: false

library(ggplot2)
ggplot(airquality, aes(Temp, Ozone)) + 
  geom_point() + 
  geom_smooth(method = "loess", se = FALSE)

But when I would first create the plot in R and save it as a ggplot object, say temp_ozone_plot

temp_ozone_plot <- ggplot(airquality, aes(Temp, Ozone)) + 
  geom_point() + 
  geom_smooth(method = "loess", se = FALSE)

and subsequently use this object in a code block, it will not render

temp_ozone_plot

the error message is:

Error in eval(expr, envir, enclos) : object 'temp_ozone_plot' not found
Calls: .main ... withVisible -> eval_with_user_handlers -> eval -> eval

I am running R 4.2.1 and Quarto 1.2.313, with Rstudio 2022.12.0+353

1 Like

R objects need to be known and available from within the .qmd document itself. Quarto won't be able to render a document using R objects that lives in your current R session only.

Are you doing this in the .qmd file ?

If you created the object in a previous code block it should find it. If you created in your R session only, then the object does not exist when the document is rendered.

When rendering a document with quarto, it will run in an entire new external process which will call a new R process for each document of the project. This differs from R Markdown where all happen in R only.

2 Likes

@cderv Thanks! I have been working extensively wit Rmarkdown, bookdown, distill... So I was used to markdown being aware of the object in the R session.

1 Like

Yes I understand completely. This is a big difference for R users. This is part why we are saying that that R Markdown is not going away: R Users will still have use cases and need a tool like R Markdown that is tied to the R language. This is one advantage that ends up being a limitation for broader usage in the scientific communication domain. Quarto is a tool that aims to reach broader that R only by not being tied with the R language if you don't need it - this comes with some limitation like this one.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.