Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify .Rprofile and .Renviron when using singularity #855

Open
nickhir opened this issue Sep 12, 2024 · 7 comments
Open

Specify .Rprofile and .Renviron when using singularity #855

nickhir opened this issue Sep 12, 2024 · 7 comments
Labels

Comments

@nickhir
Copy link

nickhir commented Sep 12, 2024

Hi all,

I have been using the workflow described here to run RStudio on our HPC. Its been working brilliantly so far and makes my life so much easier, so thank you for that!

There is only one thing that I cant get to work: I would like to modify the .Rprofile and .Renviron that is being used by the singularity image, but I cant get it to work. I have tried to place the .Rprofile and .Renviron into the directory specfied by R_LIBS_USER, but the edits did not seem to make any impact (i.e. the settings I have specified in Rprofile did not show up when starting the singularity image.

Any help how to accomplish this would be much appreciated!

Cheers!

@eitsupi eitsupi transferred this issue from rocker-org/rocker Sep 12, 2024
@eddelbuettel
Copy link
Member

Have a look at the (epic, long) help page for help(Startup) about what R reads when and where. R_LIBS_USER is one of those things you can there with different Renviron or Rprofile files, it governs how the package library path (i.e. .libPaths()) is constructed. In general, the files you are after can be read from R's etc/ dir, the user's $HOME dir and the current processes startup directory.

@nickhir
Copy link
Author

nickhir commented Sep 12, 2024

Thank you very much for your answer! I added an .Rprofile to my $HOME directory (which is incidentally also the processes startup directory), but it did not change anything.

The output of the R.home() command is the following: "/usr/local/lib/R", however, I have noticed, that I can not change or add any files in the /usr/local/lib/R/etc directory because its a Read-only file system.

Furthermore, when I try to run usethis::edit_r_profile() I get the following error:

Error: [EISDIR] Failed to open '/rds/user/nickhir/hpc-work/software/R': illegal operation on a directory

Do you have any idea what else I could try?

@eddelbuettel
Copy link
Member

Yes, that can be a problem. These days I work single-user, mostly, and am root here but R is indeed happy to run off a read-only file system.

But let's go back to help(Startup). I think you can also have Renviron read from where an env var points to which may be a clean way to have it picked up. R_ENVIRON_USER seems to be one way:

$ echo "randomdoodle=bar78" > /tmp/r/renviron_demo.txt
$ R_ENVIRON_USER=/tmp/r/renviron_demo.txt Rscript -e 'Sys.getenv("randomdoodle")'
[1] "bar78"
$ 

@nickhir
Copy link
Author

nickhir commented Sep 12, 2024

Thank you very much for your support! I am afraid it is still not working.. I have added

export R_PROFILE_USER=/rds/user/nh608/hpc-work/software/R/.Rprofile # also tried without .Rprofile at the end
export R_ENVIRON_USER=/rds/user/nh608/hpc-work/software/R/.Renviron # also tried without .Renviron at the end

to the script shown here and it still does not work... Do I have to modify the singularity exec command in any way?

@nathanweeks
Copy link

@nickhir Were those environment variable settings added to the rsession.sh script (that also sets R_LIBS_USER)?

https://github.com/rocker-org/website/blob/e99414de7974ba0cb70306a9146594ca0f2e9200/use/singularity.md?plain=1#L96-L101

It seems setting R_PROFILE_USER and R_ENVIRON_USER there have the intended effect (with the rstudio_4.2.sif image listed in the job script). Note the path /rds/user/nh608/hpc-work/software/R/ has to exist in the container (in case it's not being mounted by default).

@drkrynstrng
Copy link

If the singularity or apptainer command includes the --cleanenv option, then these environment variables will not be passed into the container (assuming they are not set in the rsession.sh script that is). Set the following instead:

export SINGULARITYENV_R_PROFILE_USER=/rds/user/nh608/hpc-work/software/R/.Rprofile
export SINGULARITYENV_R_ENVIRON_USER=/rds/user/nh608/hpc-work/software/R/.Renviron

Or

export APPTAINERENV_R_PROFILE_USER=/rds/user/nh608/hpc-work/software/R/.Rprofile
export APPTAINERENV_R_ENVIRON_USER=/rds/user/nh608/hpc-work/software/R/.Renviron

Then they will always be passed into the container, whether the --cleanenv option is used or not.

@nathanweeks
Copy link

@nickhir An example is included in this PR: rocker-org/website#120

eitsupi added a commit to rocker-org/website that referenced this issue Dec 14, 2024
Updates the Singularity guide:

* Set `rserver --server-user` in job script
(rocker-org/rocker-versioned2#837)
* Show where R_PROFILE_USER and R_LIBS_USER can be set
  (rocker-org/rocker-versioned2#855)
*  Use rocker/rstudio:4.4.2
* Specify `python3` instead of `python` (the latter may be python 2 or
absent on some hosts)
* Mention Apptainer
* mktemp is simpler and portable-enough (GNU coreutils) for creating
temp dirs
* Simplify creation of various writable directories in container with
`--scratch` and `--workdir`
* Ensure R_LIBS_USER directory exists
* no longer need to create readable database.conf (sqlite seems to be
the default)
* SLURM_CPUS_ON_NODE technically more correct than
SLURM_JOB_CPUS_PER_NODE
  (though shouldn't make a difference with a single-node allocation)

---------

Co-authored-by: eitsupi <50911393+eitsupi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants