rstudioapi::getVersion() does not Render with Quarto (knitr)

I am running a large course (~150 students) and would like to know what version students are using when they complete homework in Quarto. The first HW assignment is to get R/RStudio/R packages/tinytex/latex packages installed and render a Quarto document. I handled R installation issues on an ad hoc basis (and advised Posit Cloud usage for some). Instead of pestering 150 intro stats students to fill out a survey where they answer questions about how they installed R locally (or not, and might not know), I would include a code chunk like this for the TAs/graders to read on Gradescope (HW grading platform where students submit PDFs) to make sure everything is up-to-date and provide more targeted feedback if not.

c(paste0("R version is: ", R.Version()$major, ".", R.Version()$minor),
  capture.output(sessionInfo())[2:3], 
  paste0("RStudio version is: ", rstudioapi::getVersion(), " running on ", rstudioapi::versionInfo()$mode),
  paste0("Quarto version is: ", quarto::quarto_version()), 
  tinytex::tlmgr_version(), 
  substr(capture.output(rstudioapi::getSourceEditorContext())[3], 15, 1000))

Critically, rstudioapi::versionInfo(), rstudioapi::getVersion(), and rstudioapi::getSourceEditorContext() only work in a session as Quarto is meant to be running in a clean R run, not dependent on RStudio. I couldn't figure out a way to get the RStudio version into a rendered Quarto PDF, so if anyone knows of a clever way to do this, that would be helpful.

Here's some example output:

This was a GitHub issue a few years ago: RStudio.Version() not functioning while knitting · Issue #6892 · rstudio/rstudio · GitHub
And also a community post before thatith even Jenny Bryan weighing in that it might be useful in other contexts.

Quarto will run R in a background process that does not know about RStudio. rstudioapi requires to be inside RStudio IDE.

It should be the with R Markdown when you click the Knit button as it will run in a background process also.

Only calling rmarkdown::render() in the RStudio R session works.

I don't think there is an easy way to achieve what you need unless you create a R wrapper function that would retrieve the info you need from the R session and pass it as parameters (or environment variables) to quarto render.

THe Quarto R package allows to call quarto render from R so it could be used for your special wrapper.

Overall the question is : How can you make the information available to Quarto when rendering in RStudio ?

Maybe there is a way for an environment variable to be passed by RStudio and accessible inside Quarto document when run in background jobs. You can open a feature request at: GitHub - rstudio/rstudio: RStudio is an integrated development environment (IDE) for R

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.