how to have reprex() render in 'Viewer' tab

Hi, one of my students who uses Windows reports that when reprex() renders, RStudio shows the result in a separate window, rather than in the 'Viewer' tab, which is where it's rendered on my Mac laptop. Is there an option she can set to have it rendered on in the 'Viewer' tab? I thought there might be one like there is for knitting .Rmd files, but haven't been successful in finding one.

Thanks,
David

Follow-up: From reading the source for reprex(), it appears that where the output is rendered depends on whether the getOption("viewer") returns a null value. Here's the block where the rendering occurs:

if (show) {
  html_file <- files[["html_file"]]
  rmarkdown::render(md_file, output_file = html_file, 
                    clean = FALSE, quiet = TRUE, encoding = "UTF-8", 
                    output_options = if (pandoc2.0()) 
                      list(pandoc_args = "--quiet"))
  html_file <- force_tempdir(html_file)
  viewer <- getOption("viewer") %||% utils::browseURL
  viewer(html_file)
}

In the next to last line, viewer is set to utils::browseURL if getOption("viewer") returns a null value, which must be happening on my student's machine. Why would this happen, and how could this be changed so the output is render in the RStudio 'Viewer' tab?

RStudio always sets the viewer option:

so my best guess is that the student (or a package they are loading?) is unsetting that option. Perhaps that change is being made in e.g. the .Rprofile or similar?

It would help if you could confirm if getOption("viewer") does indeed report NULL on your student's machine.

Thanks, Kevin -- I'll check with the student. Since it's an introductory class, the chances are they haven't installed anything beyond the tidyverse and are unlikely to have unset the option, but I'll follow up with what I find out.

Hi Kevin,

It turns out that for this student, getOption("viewer") is set exactly to the function created in the code you posted when the original value is NULL, yet renders in the browser instead of the 'Viewer' pane: What might be a good next place to look for clues to how to fix this? Could it be that reprex() creates the wrong type of url in her case?

Thanks,
David

I am now recalling an issue on the reprex + RStudio repositories where a similar issue was described:

Unfortunately, I believe this needs to be fixed on the RStudio side. I've marked the associated issue with a v1.4 milestone now.

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