Quarto flake from wiki doesn't set $R_LIBS_SITE

I tried using the quarto flake from the Wiki, which worked fine, except that rstudio didn’t find and of the installed libraries. I checked against my other flakes, and the R_LIBS_SITE variable was empty, unlike all my other shells. The difference between my other flakes and this one is

(pkgs.rWrapper.override {packages = myRPackages; })

My other flakes don’t use the wrapper. When I changed this to simply

pkgs.R
myRPackages

it worked, the variable was set, and rstudio was happy.

So I’m curious what the purpose is of the rWrapper.override, why it doesn’t set the needed environment variable, and if I am doing the wrong thing by not using the override syntax.

Thanks

In this context the purpose is to allow you as a user to override the defaults that are passed to rWrapper by nixpkgs.

Technically, it does, your shell does not see it though. It is embedded into the wrapper for R instead. If you run the R CLI and run Sys.getenv(“R_LIBS_SITE”) you will see your specified additional packages shown there.

That is because rStudio does not use your overridden R, which has the environment variable set. If you want rStudio to also see your additional packages, you need to do this:

(rstudioWrapper.override { packages = myRPackages; })

I am surprised that your other flakes work, as the nixpkgs manual notes that:

RStudio uses a standard set of packages and ignores any custom R environments or installed packages you may have.

For what it is worth, the nixpkgs manual recommends using the override mechanism of the R and rStudio wrappers for creating custom environments.

1 Like

Thanks for taking the time, this clears up a lot of things for me, although I do still have a question.

I knew they were in the environment, since quarto rendered properly.

Yes, that worked, thank you! I’ve always been a bit vague on how the wrappers and overrides work and how/when to use them, and this, and the rest of your message, helps a lot.

It’s always worked fine for me to simply list the packages without using a wrapper or override. Even the R packages I build on my own work fine this way. So, my question is, what is the advantage/purpose to using the wrappers? I take it to be best practice to use them, just curious what the extra layer (no pun intended) of syntax, calling the additional functions (override and the wrappers), is meant to achieve, given that the simpler function seems to achieve the same goal.

Cheers

1 Like

This post addresses that topic well.

The NixOS wiki also touches on the topic.

Sorry, badly worded question. I’m pretty clear on what wrappers are and their general purpose, as well as potential FHS issues, although I have never personally faced them. I’m just wondering what the wrappers add in this context (a development shell). In other words, if I use the rWrapper, I also need to use the rstudioWrapper, but I seem to be able to achieve the same end by simply listing the packages I need and avoiding wrappers altogether.