{"id":942,"date":"2022-06-03T20:16:47","date_gmt":"2022-06-03T20:16:47","guid":{"rendered":"https:\/\/www.embl.org\/groups\/bioinformatics-rome\/?p=942"},"modified":"2022-06-03T20:16:49","modified_gmt":"2022-06-03T20:16:49","slug":"very-fast-r-packages-installation-with-r2u","status":"publish","type":"post","link":"https:\/\/www.embl.org\/groups\/bioinformatics-rome\/blog\/2022\/06\/very-fast-r-packages-installation-with-r2u\/","title":{"rendered":"Very fast R packages installation with r2u"},"content":{"rendered":"\n<div style=\"height:41px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>In this post, I want to test <a href=\"https:\/\/eddelbuettel.github.io\/r2u\/\" target=\"_blank\" rel=\"noreferrer noopener\">r2u<\/a>, a very rapid and efficient tool to install R packages. It currently supports 19,066 and 18,921 binary packages from <a rel=\"noreferrer noopener\" href=\"https:\/\/cran.r-project.org\/\" target=\"_blank\">CRAN<\/a> in &#8220;<a rel=\"noreferrer noopener\" href=\"https:\/\/releases.ubuntu.com\/20.04\/\" target=\"_blank\">focal<\/a>&#8221; and &#8220;<a rel=\"noreferrer noopener\" href=\"https:\/\/releases.ubuntu.com\/22.04\/\" target=\"_blank\">jammy<\/a>&#8221; respectively.  It also supports 207 (focal) and 215 (jammy) <a rel=\"noreferrer noopener\" href=\"https:\/\/bioconductor.org\/\" target=\"_blank\">BioConductor<\/a> packages from the 3.15 release. They limited the Bioconductor packages to the ones used in CRAN. Everything is provided as &#8220;.deb&#8221; binary files with proper dependency resolution by using a proper apt repo which also has a signed Release file.<\/p>\n\n\n\n<p>From their <a rel=\"noreferrer noopener\" href=\"https:\/\/eddelbuettel.github.io\/r2u\/\" target=\"_blank\">web page<\/a>, here are its key features:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Full integration with apt as every binary resolves all dependencies: No more installations (of pre-built archives) only to discover that a shared library is missing. No more surprises.<\/li><li>Full integration with apt so that an update of a system library cannot break an R package: if a (shared) library is used by CRAN, the package manager knows and will not remove it. No more (R package) breakage from (system) library updates.<\/li><li>Installations are fast, automated and reversible thanks to the package management layer.<\/li><li>Optional (but recommended) use with bspm automagically connects R functions like install.packages() to apt for access to binaries and dependencies.<\/li><\/ul>\n\n\n\n<div style=\"height:41px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Creating the singularities<\/h2>\n\n\n\n<p>Below we want to measure the time spent on the installation of <code>dplyr<\/code> and <code>deseq2<\/code> from R and using r2u. For this, we are going to use a singularity container. If you do not have singularity already installed, please look at the procedure <a href=\"https:\/\/sylabs.io\/guides\/3.0\/user-guide\/installation.html\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p>Let&#8217;s build two singularities in <a rel=\"noreferrer noopener\" href=\"https:\/\/sylabs.io\/guides\/3.0\/user-guide\/build_a_container.html?highlight=sandbox#creating-writable-sandbox-directories\" target=\"_blank\">sandbox<\/a> mode (writable).  Create a singularity recipe in a <code>Singularity<\/code> file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>BootStrap: docker\nFrom: ubuntu:focal\n\n%post\n    # ~~~~~~ General setup ~~~~~~ #\n    # See https:\/\/cloud.r-project.org\/bin\/linux\/ubuntu\/\n    apt update -qq\n    export DEBIAN_FRONTEND=noninteractive\n    apt-get install --assume-yes --no-install-recommends software-properties-common dirmngr \\\n    wget build-essential libblas-dev liblapack-dev gcc-10 g++-10 gfortran-10 emacs \\\n    libcurl4-openssl-dev libxml2-dev libsodium-dev libssl-dev\n    \n    # ~~~~~~ R 4.2.0 ~~~~~~ #\n    wget -q -O- https:\/\/cloud.r-project.org\/bin\/linux\/ubuntu\/marutter_pubkey.asc \\\n    | tee -a \/etc\/apt\/trusted.gpg.d\/cran_ubuntu_key.asc\n    echo \"deb &#91;arch=amd64] https:\/\/cloud.r-project.org\/bin\/linux\/ubuntu focal-cran40\/\" \\\n        &gt; \/etc\/apt\/sources.list.d\/cran-ubuntu.list\n    apt update &amp;&amp; apt upgrade --yes\n    apt install --yes r-base r-base-core\n<\/code><\/pre>\n\n\n\n<p>Insert the following code in a script <code>buildSingularity.sh<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/bash\n\nsingularity build --sandbox sandbox1 Singularity\nsingularity build --sandbox sandbox2 Singularity\n<\/code><\/pre>\n\n\n\n<p>Build the two images using <code>sudo<\/code> and measure the execution time with <code>time<\/code> (4:25.84elapsed 68%CPU):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo time bash buildSingularity.sh<\/code><\/pre>\n\n\n\n<div style=\"height:41px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Installation from R<\/h2>\n\n\n\n<p>Run sandbox1:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo singularity shell --writable sandbox1<\/code><\/pre>\n\n\n\n<p>Open R and install <a href=\"https:\/\/cran.r-project.org\/web\/packages\/dplyr\/index.html\" target=\"_blank\" rel=\"noreferrer noopener\">dplyr<\/a> and <a href=\"https:\/\/bioconductor.org\/packages\/release\/bioc\/html\/DESeq2.html\" target=\"_blank\" rel=\"noreferrer noopener\">deseq2<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; start_time1&lt;-Sys.time();install.packages(\"dplyr\");end_time1&lt;-Sys.time()\n&gt; install.packages(\"BiocManager\")\n&gt; library(\"BiocManager\")\n&gt; start_time2&lt;-Sys.time();install(\"DESeq2\");end_time2&lt;-Sys.time()\n&gt; end_time1-start_time1\n## 1.51152 mins\n&gt; end_time2-start_time2\n## 12.23746 mins\n<\/code><\/pre>\n\n\n\n<div style=\"height:41px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Installation with r2u<\/h2>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">With Docker hub<\/h3>\n\n\n\n<p>After installing <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.docker.com\/engine\/install\/\" target=\"_blank\">docker<\/a>, run the command (0m18,790s):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>time docker pull eddelbuettel\/r2u:focal<\/code><\/pre>\n\n\n\n<p>Run the docker:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -it eddelbuettel\/r2u:focal<\/code><\/pre>\n\n\n\n<p>Install <code>dplyr<\/code> from R:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; start_time&lt;-Sys.time();install.packages(\"dplyr\");end_time&lt;-Sys.time()\n&gt; end_time-start_time\n## 12.99056 secs\n<\/code><\/pre>\n\n\n\n<p>Install <code>deseq2<\/code> with <code>apt<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>time apt install --yes r-bioc-deseq2\n## 0m23.676s\n<\/code><\/pre>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Manually<\/h3>\n\n\n\n<p>Run sandbox2 in another terminal:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo singularity shell --writable sandbox2<\/code><\/pre>\n\n\n\n<p>Copy the following script to <code>install-r2u.sh<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/bash\n\n## First: update apt and get gpg-agent and key\napt update -qq\napt install --yes --no-install-recommends gpg-agent     # to add the key\napt-key adv --keyserver keyserver.ubuntu.com --recv-keys A1489FE2AB99A21A\n\n## Second: add the repo\necho \"deb &#91;arch=amd64] https:\/\/dirk.eddelbuettel.com\/cranapt focal main\" &gt; \/etc\/apt\/sources.list.d\/cranapt.list\napt update\n\n## Third: ensure R 4.2.0 is used\necho \"deb &#91;arch=amd64] https:\/\/cloud.r-project.org\/bin\/linux\/ubuntu focal-cran40\/\" &gt; \/etc\/apt\/sources.list.d\/edd-misc.list\napt-key adv --keyserver keyserver.ubuntu.com --recv-keys 67C2D66C4B1D4339\n\n\n## Fourth: add pinning to ensure package sorting\necho \"Package: *\" &gt; \/etc\/apt\/preferences.d\/99cranapt\necho \"Pin: origin \\\"dirk.eddelbuettel.com\\\"\" &gt;&gt; \/etc\/apt\/preferences.d\/99cranapt\necho \"Pin-Priority: 700\"  &gt;&gt; \/etc\/apt\/preferences.d\/99cranapt\n\n## Fifth: install bspm and enable it\nRscript -e 'install.packages(\"bspm\")'\nRHOME=$(R RHOME)\necho \"suppressMessages(bspm::enable())\" &gt;&gt; ${RHOME}\/etc\/Rprofile.site\necho \"options(bspm.sudo=TRUE)\" &gt;&gt; ${RHOME}\/etc\/Rprofile.site\n<\/code><\/pre>\n\n\n\n<p>Run the script (0m38.782s):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bash install-r2u.sh<\/code><\/pre>\n\n\n\n<p>Open R and install <code>dplyr<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; start_time&lt;-Sys.time();install.packages(\"dplyr\");end_time&lt;-Sys.time()\n&gt; end_time-start_time\n## 33.09381 secs\n<\/code><\/pre>\n\n\n\n<p>From the command line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>time apt install --yes r-bioc-deseq2\n## 4m51.869s\n<\/code><\/pre>\n\n\n\n<div style=\"height:41px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In this post, we have compared the time needed for installing two R packages (dplyr and DESeq2) with or without using <code>r2u<\/code>. Here is a summary:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>package<\/th><th>time<\/th><\/tr><\/thead><tbody><tr><td>From R<\/td><td>dplyr<\/td><td>1.51152 mins<\/td><\/tr><tr><td>From R<\/td><td>DESeq2<\/td><td>12.23746 mins<\/td><\/tr><tr><td>From r2u docker<\/td><td>dplyr<\/td><td>12.99056 secs<\/td><\/tr><tr><td>From r2u docker<\/td><td>DESeq2<\/td><td>0m23.676s<\/td><\/tr><tr><td>From r2u<\/td><td>dplyr<\/td><td>33.09381 secs<\/td><\/tr><tr><td>From r2u<\/td><td>DESeq2<\/td><td>4m51.869s<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this post, I want to test r2u, a very rapid and efficient tool to install R packages. It currently supports 19,066 and 18,921 binary packages from CRAN in &#8220;focal&#8221; and &#8220;jammy&#8221; respectively. It also supports 207 (focal) and 215 (jammy) BioConductor packages&hellip;<\/p>\n","protected":false},"author":5,"featured_media":952,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[4096],"tags":[5434,5432,5436],"embl_taxonomy":[],"class_list":["post-942","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technical","tag-packages","tag-r","tag-r2u"],"acf":[],"embl_taxonomy_terms":[],"featured_image_src":"https:\/\/www.embl.org\/groups\/bioinformatics-rome\/wp-content\/uploads\/2022\/06\/lartigue.jpg","_links":{"self":[{"href":"https:\/\/www.embl.org\/groups\/bioinformatics-rome\/wp-json\/wp\/v2\/posts\/942"}],"collection":[{"href":"https:\/\/www.embl.org\/groups\/bioinformatics-rome\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.embl.org\/groups\/bioinformatics-rome\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.embl.org\/groups\/bioinformatics-rome\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.embl.org\/groups\/bioinformatics-rome\/wp-json\/wp\/v2\/comments?post=942"}],"version-history":[{"count":5,"href":"https:\/\/www.embl.org\/groups\/bioinformatics-rome\/wp-json\/wp\/v2\/posts\/942\/revisions"}],"predecessor-version":[{"id":954,"href":"https:\/\/www.embl.org\/groups\/bioinformatics-rome\/wp-json\/wp\/v2\/posts\/942\/revisions\/954"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.embl.org\/groups\/bioinformatics-rome\/wp-json\/wp\/v2\/media\/952"}],"wp:attachment":[{"href":"https:\/\/www.embl.org\/groups\/bioinformatics-rome\/wp-json\/wp\/v2\/media?parent=942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.embl.org\/groups\/bioinformatics-rome\/wp-json\/wp\/v2\/categories?post=942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.embl.org\/groups\/bioinformatics-rome\/wp-json\/wp\/v2\/tags?post=942"},{"taxonomy":"embl_taxonomy","embeddable":true,"href":"https:\/\/www.embl.org\/groups\/bioinformatics-rome\/wp-json\/wp\/v2\/embl_taxonomy?post=942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}