Built-in functions

R has a quite extensive set of base functions that come with each R distrution. It is possible to get a complete list by typing builtins() in the R console. Some examples of R functions here and here.

Getting help on functions

RStudio has a help tab in the right part of the window. You can search there, or type ?functionName in the console. The easiest, however, is to put the cursor on a function name and press F1.

Some extended help functions in the console:

help.start()      #opens the help summary
help(var)         #we get info about the variance function
?var
apropos("var")    #a list with the functions that contain the letters "var"
help.search(var)
??var             #it extends the search 

R packages

To extend the base functionalities, you have can load R packages. A large list of packages is available. Many of them are hosted on the central package repository CRAN. Here is a list of all contributed CRAN packages. A list of recommendations of useful packages is available here

To load a package, type

library("packageName")

If the package is not available, you will get an error. In this case, you need to install the package first (see below)

Installing R packages

The basic way to install a packages from CRAN is to type

install.packages("packageName")

You can modify the source of the packages to be installed (repos other than CRAN, or from a file), as well as the location where the package should be installed to (default is in the directory of R, but you may not have write permissions there).

For example, when on a linux machine without root acces and you can specify a local directory such as

install.packages("spatstat", lib="/data/Rpackages/")
library(spatstat, lib.loc="/data/Rpackages/")

A longer-term solution in this case though is to modify the .Renviron file with the line R_LIBS=/data/Rpackages/, in which case we can drop the lib commands and do everything as before.

Alternatively, in RStudio, one can install packages in Tools-> Install Packages. We can then select if we want to install it from the repository or from an archive file and whereis the library where it will be installed. Once installed, we can activate clicking on its correspondent box in the bottom right window from RStudio.

Installing R packages from github

You can install packages which are not in the cran yet or install a developmental version of a package using the devtools package. Instruction on how to install/update to the latest version of devtools can be found here.

Example: Installing the current developmental version of spatstat package

install.packages("devtools")
library(devtools)
devtools::install_github("spatstat/spatstat")