How to access R session's variables from inside quarto file

I'm using quarto as an alternative to rmarkdown to generate reports using R. However, I'm not sure how to access R objects already created before calling the quarto_render function. For example, in the below


i want to access var1 from inside Audit.qmd file. But Audit.qmd does not recognise var1.Not sure how to do this. In Rmarkdown this can be done naturally. Quarto being language independent, doesn't make it that simple. I can store those variables as rds objects, and then import it back from inside qmd file, but is there a simpler way by which all the objects are accessed from qmd session?

In R Markdown, this can be done "naturally" because rmarkdown::render() is a R function running inside the same R session by default. You would have the same issue as with quarto if you were running rmarkdown::render() in a new background R session. FWIW quarto_render() is only a R wrapper function to call the CLI tool on the system quarto render using system() call.

Quarto is not coded in R - it will just open a new R background session to evaluate R code.

This is the best way for complex R objects (like dataframe or list, or models or other specifics). If you need to pass values, you can use the parametrization

and use execute_params argument

quarto::quarto_render(input="Audit.qmd", execute_params = list(var1 = 5))

var1 will be available in your document as params$var1


This topic was automatically closed 7 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.