Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the default PDF viewer for rstudio

Tags:

r

pdf

rstudio

knitr

Using knitr in Rstudio, when an .Rmd file is knit to PDF, the resulting file viewer is evince. I would very much like to change this to okular, but I cannot find a way to make this happen.

Looking at the Sweave settings, I see "system viewer" noted for the preview, but okular is already set as my default system viewer. I've also checked the default viewer with xdg-mime and okular is default there as well. In all other instances, okular is the default but Rstudio/knitr always used evince.

How can I change this behavior?

like image 457
KirkD-CO Avatar asked Sep 23 '17 19:09

KirkD-CO


2 Answers

Works on Mac, R Studio version 1.2.1335

Opitons | Sweave | PDF Viewer : System viewer enter image description here

like image 177
Ben Vincent Avatar answered Oct 04 '22 04:10

Ben Vincent


I recently had this problem and found a potential solution.

First, check to see what the default PDF viewer is set to:

    Sys.getenv("R_PDFVIEWER")

Now, on my system this was "open", but it needed to be "xdg-open".

So, I changed the environmental variable:

    Sys.setenv(R_PDFVIEWER = "xdg-open")

This may be permanently set by:

    # Checking where your home directory is in R
    Sys.getenv('HOME')

Then in terminal, in the home directory:

    # Making an R environment file that runs at startup
    touch .Renviron

    # Add the environment variable change
    echo 'R_PDFVIEWER = xdg-open' >> .Renviron

Now, when R starts the correct PDF viewer should be used.

like image 22
compBio Avatar answered Oct 04 '22 04:10

compBio