SSLib comes as a series of R packages. Not all packages need to be installed, though some have some have dependencies and recommended packages. The recommended packages are generally required to run some of the examples on the manual pages. In order to use the SSLib packages, the R Software must firstly be installed onto your system.
The easiest way to install R is to download the required binary, a compiled version of the software that is compatible with the particular version your operating system. These binaries can be found on CRAN (Comprehensive R Archive Network). Select an appropriate repository location from the CRAN Mirrors. There are binaries for various versions of Linux, Windows and MacOS.
Some distributions of Linux (e.g. Debian, Ubuntu and Fedora) have R included within their distribution, and can be installed directly from that source. Alternatively, it can also be installed directly from CRAN. For example, in Debian 11 (codename “bullseye”) and R version 4.2, one includes
deb https://cran.r-project.org/bin/linux/debian bullseye-cran40/
into file /etc/apt/sources.list
, and then R can be installed in the standard Debian way as sudo apt-get install r-base
. This has the big advantage that the system software will automatically install any required system dependencies; and further, remove all of these dependencies if R is subsequently deleted and they are not required by other system software. In order to install packages from source code (includes those from SSLib), you will need to also install r-base-dev
, i.e. sudo apt-get install r-base-dev
. This has a number of system dependencies including Fortran and C compilers, and LaTeX components. See CRAN-Linux-Debian for further information. Installation in other Linux distributions will be similar.
SSLib does not provide MacOS binaries of its packages, hence the base R install in MacOS needs to add additional components (as in Linux above) such that it can compile contributed packages from source code. This will include Fortran and C compilers, and components of LaTeX. See cran.r-project.org/bin/macosx for more information.
Software management in MS Windows is a little more messy. One needs to manually download the appropriate binary, and install. If an older version of R is already installed, this new version can be installed in parallel. One may need to relocate the user installed packages (not base R) if they are installed within the directory of the older R version before deleting that particular R version. It is best to keep the directory containing additional user installed packages quite separate. The deletion of the older version of R can be done in the standard Windows way from the Control Panel. SSLib provides compiled Windows binaries of its packages for the current stable version of R. See cran.r-project.org/bin/windows for more information.
After upgrading to a new version of R, check for package updates (see below) to those you have previously installed. The old installed compiled versions may not necessarily work in the new R version, see argument checkBuilt
below.
If a binary is not available for your operating system or you want to configure the installation of R in a non-standard way, then you need to install the software using the source code; also available from CRAN.
We firstly need to decide how and where.
Linux versions of R are configured to install packages from their source code by default, so everything described below works ‘out of the box’. Depending on your distribution, you may need to install a package named something like r-base-dev
(required in Debian, see above).
MacOS works in a similar way to Linux. The critical point to take care of when installing R is the installation of the r-base-dev
package (or something similar) and all of its dependencies. See section above.
The manual method (below) to install from source code can also be used in MS Windows, but it requires the Rtools software to be installed; also see biostat.wisc.edu/~kbroman/Rintro/Rwinpack.html for further details. If a compiled binary exists (.zip), it is much easier to use this, see subsection Within an Active R Session below. This is the standard method in MS Windows.
The main thing that needs to be decided is where to install additional R packages. This will depend on whether you have root/admin rights to install into the system directories.
One should also determine from where the packages are sourced. In Debian (Linux), some packages are available from both CRAN and the Debian repositories. The Debian repository version may tend to be slightly older, but if it has complicated system requirements, then those will be taken care of by the Debian apt-get
package management system.
In a standard Debian configured computer, packages that are installed as part of the R base installation are in
/usr/lib/R/library/
,
and additional packages installed from the Debian repositories using apt-get
are in
/usr/lib/R/site-library/
.
Packages that are installed from the CRAN or SSLib repositories, as described below (assuming root/admin permissions), are stored in
/usr/local/lib/R/site-library
.
If one does not have root/admin permissions, then packages could be installed into one's home directory, e.g.
/home/david/R-library/
.
You can see the library locations on your machine by running .libPaths()
within R. You can also see the packages installed in each within the R html help interface; run help.start()
within R, then click on “Packages”. You can define other library locations by including those in your R profile.
We firstly need to let R know where to find the required package repositories.
Then we need to tell R where to install the package, and whether this is done using source code or a compiled binary. In UNIX, this is done using source code, and in MS Windows it is generally done using a binary. The location of the installation directory may require root/admin rights depending on its location. Hence, we might have something like:
# define repositories repos <- c("https://www.statsresearch.co.nz/dsh/sslib/r-repo/", "https://cran.r-project.org/") # define system defaults if (Sys.info()["sysname"]=="Windows"){ # MS Windows operating system lib.loc <- "H:/R/lib/" pkg.type <- "win.binary" } if (Sys.info()["sysname"]=="Linux"){ # Linux operating system (Debian defaults) lib.loc <- "/usr/local/lib/R/site-library" pkg.type <- "source" } # update packges in lib.loc: update.packages(repos=repos, lib.loc=lib.loc, type=pkg.type, checkBuilt=TRUE, ask=TRUE) # install package ssBase, say, as: install.packages("ssBase", lib=lib.loc, repos=repos, type=pkg.type) # remove package ssBase, say, as: remove.packages("ssBase", lib=lib.loc) # list available packages in SSLib repository: available.packages(repos=repos[1], type=pkg.type) # list installed package versions and R version under which each was built: print(installed.packages()[,c("LibPath", "Version", "Built")], quote=FALSE)
Library locations, package types, and repository definitions can be saved as part of the system options, see here. Then in Windows, for example, one could simply use the “Packages” pull down menu.
See the R help pages for install.packages
, remove.packages
, update.packages
, installed.packages
and available.packages
for further options.
install.packages()
, as above, all required package dependencies will also be installed.
update.packages
as above. Older builds of the packages will not necessarily work with a newer version of R.
https://www.statsresearch.co.nz/dsh/sslib/r-repo/diagnostics.Rand run. Please attach a copy of the output with your email.
To install a package called “pkgname_1.2-3.tar.gz”, one runs the following command from within the directory that contains the downloaded “pkgname_1.2-3.tar.gz” file:
R CMD INSTALL pkgname_1.2-3.tar.gz
Run R CMD INSTALL --help
for a list of other options, e.g. installation library location. Unmet package dependencies will causes errors; see above for an alternative.
Note that during installation from source code, the R software finds the most appropriate compilers on the system (Fortran and C) and automatically compiles any source code that is included within the package. Further, the created binaries are automatically linked into the R system when the package is required by a user.
To subsequently remove a package, e.g. “ssBase”, one runs the following command:
R CMD REMOVE ssBase
For further installation options, see R Installation and Administration.