## 2.5 Getting help

This book is intended as a relatively brief introduction to R and as such you will soon be using functions and packages that go beyond this scope of this introductory text. Fortunately, one of the strengths of R is its comprehensive and easily accessible help system and wealth of online resources where you can obtain further information.

### 2.5.1 R help

To access R’s built-in help facility to get information on any function simply use the help() function. For example, to open the help page our friend the mean() function

help("mean")

or you can use the equivalent shortcut

?mean

the help page is displayed in the ‘Help’ tab in the Files pane (usually in the bottom right of RStudio)

Admittedly the help files can seem anything but helpful when you first start using R. This is probably because they’re written in a very concise manner and the language used is often quite technical and full of jargon. Having said that, you do get used to this and will over time even come to appreciate a certain beauty in their brevity (honest!). One of the great things about the help files is that they all have a very similar structure regardless of the function. This makes it easy to navigate through the file to find exactly what you need.

The first line of the help document contains information such as the name of the function and the package where the function can be found. There are also other headings that provide more specific information such as

• Description: gives a brief description of the function and what it does.

• Usage: gives the name of the arguments associated with the function and possible default values.

• Arguments: provides more detail regarding each argument and what they do.

• Details: gives further details of the function if required.

• Value: if applicable, gives the type and structure of the object returned by the function or the operator.

• See Also: provides information on other help pages with similar or related content.

• Examples: gives some examples of using the function. These are really helpful, all you need to do is copy and paste them into the console to see what happens. You can also access examples at any time by using the example() function (i.e. example("mean"))

The help() function is useful if you know the name of the function. If you’re not sure of the name, but can remember a key word then you can search R’s help system using the help.search() function.

help.search("mean")

or you can use the equivalent shortcut

??mean

The results of the search will be displayed in RStudio under the ‘Help’ tab as before. The help.search() function searches through the help documentation, code demonstrations and package vignettes and displays the results as clickable links for further exploration.

Another useful function is apropos(). This function can be used to list all functions containing a specified character string. For example, to find all functions with mean in their name

apropos("mean")
##  [1] ".colMeans"     ".rowMeans"     "colMeans"      "kmeans"
##  [5] "mean"          "mean_temp"     "mean.Date"     "mean.default"
##  [9] "mean.difftime" "mean.POSIXct"  "mean.POSIXlt"  "rowMeans"
## [13] "vec_mean"      "weighted.mean"

You can then bring up the help file for the relevant function.

help("kmeans")

An extremely useful function is RSiteSearch() which enables you to search for keywords and phrases in function help pages and vignettes for all CRAN packages, and in CRAN task views. This function allows you to access the https://www.r-project.org/search.html search engine directly from the Console with the results displayed in your web browser

RSiteSearch("regression")

### 2.5.2 Other sources of help

There really has never been a better time to start learning R. There are a plethora of freely available online resources ranging from whole courses to subject specific tutorials and mailing lists. There are also plenty of paid for options if that’s your thing but unless you’ve money to burn there really is no need to part with your hard earned cash. Some resources we have found helpful are listed below.

General R resources

Getting help

• Google it!: Try Googling any error messages you get. It’s not cheating and everyone does it! You’ll be surprised how many other people have probably had the same problem and solved it.

• Stack Overflow: There are many thousands of questions relevant to R on Stack Overflow. Here are the most popular ones, ranked by vote. Make sure you search for similar questions before asking your own, and make sure you include a reproducible example to get the most useful advice. A reproducible example is a minimal example that lets others who are trying to help you to see the error themselves.

R markdown resources

Git and GitHub resources

R programming