2

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.

Community
  • 1
  • 1
Eric Green
  • 7,385
  • 11
  • 56
  • 102
  • 1
    How did you install TinyTeX? (Normally it shouldn't be installed with `sudo`) – Yihui Xie Dec 02 '19 at 21:45
  • yes, i tried at first using the terminal tab in RStudio to `sudo R` and then `tinytex::install_tinytex()`. then i uninstalled that and tried `wget -qO- "https://yihui.org/gh/tinytex/tools/install-unx.sh" \ | sh -s - --admin --no-path` from https://yihui.org/tinytex/faq/ but I'm a bit stuck. – Eric Green Dec 02 '19 at 21:58
  • I tried skipping to #6 in the faq and `tlmgr init-usertree`, but that does not work as user rstudio and does not work in sudo. – Eric Green Dec 02 '19 at 22:03
  • I said "Normally it should _not_ be installed with `sudo`". Do you have a particular reason why you used `sudo`? – Yihui Xie Dec 02 '19 at 22:53
  • I’ve been in the habit of doing that because I sometimes run scripts in batch mode and need package to be in the system library. – Eric Green Dec 02 '19 at 23:11
  • Who recommends removing `texlive`? And why? I have been on Debian and Ubuntu for 20+ years and have been using latex for longer. Never had an issue. Still don't. I create _a lot_ of pdf documents from Markdown via rmarkdown. No issues. YMMV. – Dirk Eddelbuettel Dec 03 '19 at 00:56
  • For what it is worth: `dpkg -S $(locate apa6 | head -1)` points to `texlive-publishers` (on my 19.04 Ubuntu). If you point to a sample file for/from `papaja` I can test this but as hinted I have no doubt it will just render. – Dirk Eddelbuettel Dec 03 '19 at 01:01
  • I understood @YihuiXie to be suggesting that here: https://github.com/yihui/tinytex/issues/36#issuecomment-383743443, but maybe I've misunderstood. – Eric Green Dec 03 '19 at 01:11
  • @Eric: Do you have a reference document you tried typesetting? Validating that on plain Ubuntu (or Rocker) should be fairly straightforward. Also, the thread you point to used 16.04, your are on 18.04 which may be enough of a difference. – Dirk Eddelbuettel Dec 03 '19 at 01:51
  • @DirkEddelbuettel I was just trying to typeset the default template you get after installing papaja and selecting new markdown from template apa article {papaja} – Eric Green Dec 03 '19 at 01:56
  • 1
    @Eric I see -- I think I had came across that but never installed it. Not a light-weight package but seemingly I had everything already installed. Long story short: the four page pdf file was produced without a hitch on Ubuntu 19.04, everything standard, and of course the distro texlive. – Dirk Eddelbuettel Dec 03 '19 at 02:01
  • @YihuiXie I uninstalled TinyTex from the system library and installed again as the user rstudio. this time it did compile! though it ran through missing latex packages and gave error messages like "add_link_dir_dir: destination /home/rstudio/bin not writable, no links from /home/rstudio/.TinyTeX/bin/x86_64-linux." – Eric Green Dec 03 '19 at 02:06
  • @EricGreen You can ignore the warning message about `add_link_dir_dir`. It is harmless. – Yihui Xie Dec 03 '19 at 02:10
  • Thanks both for helping me to troubleshoot. – Eric Green Dec 03 '19 at 02:16
  • @Eric With user `rstudio` are you using this via the Rocker container? There is quite a bit over at our issue tickets. – Dirk Eddelbuettel Dec 03 '19 at 02:17
  • @DirkEddelbuettel that's my next goal....moving to rocker and containers! – Eric Green Dec 03 '19 at 02:20
  • @Eric So if it not Rocker, how come there is a user 'rstudio' with a home directory (besides of course the `rstudio-server` user that is different, and without `/home` too) ? I have been running the RStudio server and desktop binary packages for as long as they have been provided yet I never needed `/home/rstudio`. What creates that? – Dirk Eddelbuettel Dec 03 '19 at 02:36
  • @DirkEddelbuettel I'm not sure this will answer your question, but I started with one of these AMIs: http://www.louisaslett.com/RStudio_AMI/. The default user is `rstudio`. – Eric Green Dec 03 '19 at 03:04
  • Right, thanks -- I am aware of those VMs. – Dirk Eddelbuettel Dec 03 '19 at 03:06

2 Answers2

2

For what it is worth, and to make this reproducible, this "just worked" on Ubuntu 19.04 using texlive:

edd@rob:/tmp$ Rscript -e 'rmarkdown::draft("test.Rmd", template="apa6", package="papaja", edit=FALSE)'
edd@rob:/tmp$ Rscript -e 'rmarkdown::render("test.Rmd")'
edd@rob:/tmp$ Rscript -e 'rmarkdown::render("test.Rmd")'   # twice for references

No need for additional non-distro hacks.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
2

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).

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419