/Home/username/* directories are being written to and are almost full after running R script in RStudio

Hello all. I installed R 4.1.3 and RStudio-Server on a Linux (RHEL 8.7) server. For every RStudio user, there is an automatically created "R" directory in the user's home directory, like /home/username/R. In my case, the /home mount point doesn't have much size so I am trying to set everything to run & save to a different directory that has much more storage allocated.

I've changed the "TMPDIR", the Library path to download & install packages, the working directory (setwd) and the Default working directory that is within the Global Options. So now all these don't use the /home/username/R directories. It's working as expected when downloading & installing packages.

However, when I run R scripts, even a small scoped one, for some reason, it still consumes quite a bit of storage in the R directories, as well as the hidden directory /home/username/.local. What are these and is there a way to prevent it from using the /home/username storage and instead using the other directory that has more storage? Please advise.

See below Linux command results after running the R script that gets a list of directories that use the most storage in the /home/username directory.

457M    /home/username/R
457M    /home/username/R/x86_64-pc-linux-gnu-library
457M    /home/username/R/x86_64-pc-linux-gnu-library/4.1
680M    /home/username/.local/share/rstudio/sessions/active/session-c6264382/graphics-r3
705M    /home/username/.local
705M    /home/username/.local/share
705M    /home/username/.local/share/rstudio
705M    /home/username/.local/share/rstudio/sessions
705M    /home/username/.local/share/rstudio/sessions/active
705M    /home/username/.local/share/rstudio/sessions/active/session-c6264382
1.2G    /home/username
1.5G    /home

 Size  Used Avail Use% Mounted on
 2.0G  1.6G  486M  77% /home

You can configure the location used for user storage via XDG_DATA_HOME, c.f. Administration Guide - Workspace Management.

The location of the user's library is controlled by R itself, c.f. R Manuals :: R Installation and Administration - 6  Add-on packages.

1 Like

Hi rstub,

Thanks for your reply.

I've configured the "XDG_DATA_HOME" and "XDG_STATE_HOME" in RStudio console by running Sys.setenv(XDG_DATA_HOME="/rstudio/servername/username") and Sys.setenv(XDG_STATE_HOME="/rstudio/servername/username"). Now when I run the Sys.getenv command in RStudio, it returns the correct path I would like the user-specific data files and state files to go to. However, after that, I restarted the rstudio-server service and my RStudio console session, I ran the script again and noticed it was still writing the files to /home/username/.local/share/rstudio.

Any ideas why ? Did I do it wrong so it didn't take effect or anything else I need to do? Does it require a new session to be started and if yes, would I reset all the environment variables again in the new session?

These variables need to be set globally for the server process. Please have a look at the linked documentation that explains how to set this.

I've added the systemd init system command for the rstudio-server service as mentioned in the linked documentation (see below). Is "XDG_DATA_HOME" the only environment variable I should add in my case? What about "XDG_STATE_HOME"? If I also should add that, would that be one more line to add in the rstudio-server service editor?


AFAIK XDG_STATE_HOME is not used, so the configuration you have now should be enough.

1 Like

Thank you @rstub . I will do some test and let you know how it goes.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.