Install R Packages¶
This page describes how to install an R package in a CoCalc project.
CoCalc already includes hundreds of R packages, but you can install even more or update them inside your project.
Your project must have the “Internet access” upgrade in order to download software from a remote repository (i.e. CRAN) to your project. The install command will not work unless you upgrade your project to have internet access.
Otherwise you have to download the tarball of the R package to your own machine, and upload it to your project. Then, you can tell R to install the package directly from there as a local file.
In a nutshell, a CoCalc project is a Linux environment inside a Docker container. This means, almost everything you can do as a “normal” Linux user also works. In particular, you can install packages locally, such that R instances can pick them up.
If a package may have general use but is not already installed in CoCalc, please open a support request to tell us to install it globally for everyone. Please include information about special dependencies or a specific example to test it.
Install a package¶
To actually install a package, create or open an existing Linux Terminal file.
- Wait for the command-line promt and type in
Rand hit the Return key. R will start up.
- Type in
install.packages("<name of package>")and hit the Return key.
- R will ask you to install it in a local directory, starting with “
~” – the “home directory” of your project. In the example below it is
- Confirm the questions with
yand the installation process should run smoothly.
- Exit R by pressing Ctrl+d or calling the
Below is how such a session for installing conjoint looks like:
~$ R R version 3.4.4 (2018-03-15) -- "Someone to Lean On" Copyright (C) 2018 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) [...] > install.packages("conjoint") Installing package into ‘/usr/local/lib/R/site-library’ (as ‘lib’ is unspecified) Warning in install.packages("conjoint") : 'lib = "/usr/local/lib/R/site-library"' is not writable Would you like to use a personal library instead? (y/n) y Would you like to create a personal library ~/R/x86_64-pc-linux-gnu-library/3.4 to install packages into? (y/n) y trying URL 'https://cloud.r-project.org/src/contrib/conjoint_1.41.tar.gz' Content type 'application/x-gzip' length 32601 bytes (31 KB) ================================================== downloaded 31 KB * installing *source* package ‘conjoint’ ... ** package ‘conjoint’ successfully unpacked and MD5 sums checked ** R ** data ** inst ** preparing package for lazy loading ** help *** installing help indices ** building package indices ** testing if installed package can be loaded * DONE (conjoint) The downloaded source packages are in ‘/tmp/RtmpHza9lC/downloaded_packages’ > q() Save workspace image? [y/n/c]: n
The above will install R packages for use with CoCalc worksheets (
and Jupyter notebooks using default R.
The Sage binary may be built with a different release of R.
R-sage instead of
R to install packages for it.