Iwo-K / HSPCdynamics

2 stars 0 forks source link

Wrong R library DLL paths of the singularity image #1

Open chengmingbo opened 9 months ago

chengmingbo commented 9 months ago

Hi there, Great paper, great singularity image! I'm not familiar with singularity, it might be my issue.

I tried the singularity image but failed. When I started a container using shell and go into the R prompt

singularity shell --cleanenv container_rpy_v4_p3_fix2.sif

I got the wrong R library paths which I think shouldn't be from the host.

> .libPaths()
[1] "/home/mingbo/R/x86_64-pc-linux-gnu-library/4.1"
[2] "/usr/local/lib/R/site-library"
[3] "/usr/lib/R/site-library"
[4] "/usr/lib/R/library"

No package can be loaded successfully, e.g.:

> library(dplyr)
Error: package or namespace load failed for 'dplyr' in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/mingbo/R/x86_64-pc-linux-gnu-library/4.1/cli/libs/cli.so':
  /usr/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /home/mingbo/R/x86_64-pc-linux-gnu-library/4.1/cli/libs/cli.so)
In addition: Warning message:
package 'dplyr' was built under R version 4.1.2
>

I think it's because the Renviron refers a host directory in the file /usr/lib/R/etc/Renviron

Where R_LIB_USER is setting is

R_LIBS_USER=${R_LIBS_USER-'~/R/x86_64-pc-linux-gnu-library/4.1'}

On the other hand, even I tried a hotfix by setting libPaths to add in the front

.libPaths("/usr/local/lib/R/site-library")

I still got the error message:

 > knitr::spin('01_SS2_processing.R')

processing file: 01_SS2_processing.Rmd

output file: 01_SS2_processing.md

Error in mark_html(out, output, ...) :
  The 'markdown' package version >= 1.3 is required.
Calls: <Anonymous> -> knit2html -> mark_html
Execution halted
Iwo-K commented 8 months ago

Thanks for raising this issue. As you explained, this look like insufficient isolation of the container from the main system and R config referring to the host home directory. In our case (I suspect) there is no issue because '~/R/x86_64-pc-linux-gnu-library/4.1' simply does not exist (both on the host and container), thus .libPaths() looks like this:

> .libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"
[3] "/usr/lib/R/library"

And indeed once loaded this is where the relevant pacakges are located (shortened output):

>  devtools::session_info()
...
- Packages -------------------------------------------------------------------
 package     * version date       lib source
 devtools      2.4.2   2021-06-07 [1] CRAN (R 4.1.0)
 dplyr       * 1.0.7   2021-06-18 [1] CRAN (R 4.1.0)
 markdown    * 1.1     2019-08-07 [1] CRAN (R 4.1.0)
[1] /usr/local/lib/R/site-library
[2] /usr/lib/R/site-library
[3] /usr/lib/R/library

I am wondering if this could be easily fixed by removing (or renaming) the "/home/mingbo/R/x86_64-pc-linux-gnu-library/4.1" on your host or running the container in an environment without R installation.

I am surprised though that manually specifying .libPaths does not fix your problem. Does this apply to any package or just the knitr:spin function? If you specify the .libPaths can you run library(dplyr)? If this is the case you may still be able to run the necessary code, you may just not be able to "spin" and generate a report.