Free R books and manuals
There are free available books online in case you need a book to help you to learn R without spending money. The official resources can be found on the web page of the R-project.https://cran.r-project.org/manuals.html
In the following table you will find all this available books. The first one is a recommended reading for those initiating in R programming.
|An Introduction to R||Beginner and intermediate|
|R Data Import/Export||Beginner and intermediate|
|R Installation and Administration||Advanced|
|Writing R Extensions||Advanced|
|R language definition (Draft)||Advanced|
|The R Reference Index||Advanced|
In addition, if you are working with base R IDE (not RStudio), you can go to menu Help → Manuals (PDF) and access to several books.
There are also contributed and translated resources, but the page is no longer actively maintained. You can see the full list in the following link.https://cran.r-project.org/other-docs.html
Package PDF manuals
It should be noted that there are PDF manuals of every R package. Some of them are more extensive and detailed than others, as there is no restriction about the quality of the documentation when uploading a package to CRAN. You can access the PDF documentation with links of the following structure.
If you are new to R programming language and you feel lost, you can call the
help.start() # HTML help will open
Once executed, if you are using RStudio the
Help tab will show you HTML help. Otherwise, a browser will be open with the HTML documentation. Then, you will be able to access to manuals, references and miscellaneous or specific material.
R Help function
Help of a function
R has documentation integrated in the IDE. In order to obtain help of any function you can call the
help function or, equivalently, the
# Obtaining help of the rnorm function help(rnorm) ?rnorm # Equivalent
The help will be in HTML format and will contain at least the description of the function, the arguments with its definition and an example.
Help of a package
Equivalently, you can obtain package help in R if you specify the package in the
help(package = "stats") ?stats # Equivalent
Sometimes you don’t know the exact name of the function from which you want to get the documentation. In these cases the
help.search function looks for documentation of some word in all packages, even if they are not loaded in memory. As an example, if you don’t know which function to use for calculating the median of a data set, you can use the following code:
In addition, you can also specify the package where you want to look for the term with the
help.search("median", package = "stats")
If you want to obtain more information about the arguments of the
help.search function, recall to use
Equivalently, you can use the
library(help = "package_name")
When looking for a specific topic, or when you only remember part of the name of a function, you can search for that string with the
apropos function. As an example, in case you want to look for functions related to
plot, you can obtain a list of all the functions that contain ‘plot’ within its name writing:
# Functions that contain 'plot' apropos("plot", mode = "function")
"assocplot" "barplot" "barplot.default" "biplot" "boxplot" "boxplot.default"
You could also use a regular expression. As an example, if you want to display all functions that starts with ‘plot’ you can use:
# Functions that starts with 'plot' apropos("^plot", mode = "function")
"plot" "plot.default" "plot.design" "plot.ecdf" "plot.function" "plot.new"
RSiteSearch function is used for looking for online help of any topic. As an example, if you search for ‘plot’ again, with this function a web page will open and will show results of your query.
# Searching for the string 'plot' in online CRAN resources RSiteSearch("plot")
R cheat sheets
R cheat sheets are quick guides of some topic, like ggplot2 or regular expressions, among others. You can download them in PDF from the RStudio official web page:https://cran.r-project.org/manuals.html
If you want to see the full list of available datasets, you can use the
data function as follows:
In case you prefer to show the full list of datasets of all packages you have installed you can call the function and specify the
data(package = .packages(all.available = TRUE))
Note that you can set any packages you want in that argument, instead of calling all with the
Moreover, when working with datasets you also need information about them, such information about the variables or how the data was collected. For that purpose just call the
? functions, specifying properly the name of the dataset. As an example, if you want information about the
diamonds dataset, type one of the following lines:
help("diamonds") ?diamonds # Equivalent
Packages include examples of use of their own functions, that you can call with the
example function. For instance, you can see different
plot examples typing:
After executing, several plots will be displayed by order. You can see the next plot pressing Enter or clicking over the plot (in base R). In case you want to leave, press Esc. Other example can be the one displayed in the next code block.
example("quantile") example(quantile) # Equivalent
The previous code will output an example of use of the
quantile function with random sample data.
R package demos
example function, there exists other function named
demo that calls more extensive examples of some relevant functions.
If you call the
demo function it will output a list of available demos to execute.
Once you decided which one you want to execute, just type it inside the function with or without quotation marks.
demo("smooth") demo(smooth) # Equivalent
The vignettes are long guides of packages that describe its use with wide explanations and more detailed examples than the ones in the base documentation, written in Rmarkdown format. Note that many packages contain vignettes, but not all. You can see the full list of vignettes of your installed R packages with the
You can also specify one or more packages instead of looking for all vignettes with the
vignette(package = "ggplot2")
Vignettes in package ‘ggplot2’: ggplot2-specs Aesthetic specifications (source, html) extending-ggplot2 Extending ggplot2 (source, html) ggplot2-in-packages Using ggplot2 in packages (source, html)
Once you decided which to see, type:
vignette("name_of_the_vignette") # Example: vignette("ggplot2-specs")
After calling the function, a window will open with the full documentation.