简体   繁体   中英

Setting the default PDF viewer for rstudio

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?

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.

Works on Mac, R Studio version 1.2.1335

Opitons | Sweave | PDF Viewer : System viewer 在此处输入图片说明

Rstudio setup

Same as you :

  • Opitons | Sweave | PDF Viewer : System viewer

OS Setup

Using file manager :

  • Right-click some random .pdf file
  • Open with... | Choose application...
  • Select your favorite PDF viewer
  • Set as default

Linux Mint 18.2 Sonya
File manager: nemo
PDF Viewer: apvlv
RStudio 1.1.383

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM