Search code examples
rtinytexpapaja

tinytex can't write to directory when a latex package is missing


I'm running RStudio (R version 3.6.0) on a Ubuntu 18.04.2 LTS server and trying to compile a pdf using the {papaja} package. I removed the pre-bundled Tex distribution as recommended (sudo apt-get purge texlive-*) and installed {tinytex}.

tinytex::tinytex_root()
# "/home/rstudio/.TinyTeX"

When I try to compile to PDF, I get an error that starts with the search for tlmgr search --file --global '/apa6.cls', a file needed for papaja:

Trying to automatically install missing LaTeX packages...

tlmgr install apa6

You don't have permission to change the installation in any way, specifically, the directory /home/rstudio/.TinyTeX/tlpkg/ is not writable.

This Github issue seems to be related, but if so I'm not understanding the solution.


Solution

  • From the comments under your post, you indicated that you originally installed TinyTeX by starting R with sudo R (then in R, tinytex::install_tinytex()). As a result, the installation directory /home/rstudio/.TinyTeX won't be writable when you run R as a non-root user (rstudio in your case) later, which means tinytex won't be able to automatically install the missing LaTeX packages for you (unless you change the ownership of the .TinyTeX directory, which will make things even more complicated).

    The solution is to run tinytex::install_tinytex() in an R process that is not started by sudo (e.g., running tinytex::install_tinytex() in the R console in RStudio will be fine).