Getting Help

Nelson Areal

Help | Using RStudio

We can use RStudio help:

RStudio help

Help | inside R

We can also use R help system:

  1. If we don’t know exactly the name of the function you are looking for, you can type on the console:
help.search("normal distribution")

or alternatively:

??"normal distribution"
  1. If we know the name of the function:
help(rnorm)

or alternatively:

?rnorm

Help | inside R

We can also search for operators, for instance:

?"+"

Help | inside R

Most pages will have an example section. We can run all the examples from a given function using:

example(rnorm)

rnorm> require(graphics)

rnorm> dnorm(0) == 1/sqrt(2*pi)
[1] TRUE

rnorm> dnorm(1) == exp(-1/2)/sqrt(2*pi)
[1] TRUE

rnorm> dnorm(1) == 1/sqrt(2*pi*exp(1))
[1] TRUE

rnorm> ## Using "log = TRUE" for an extended range :
rnorm> par(mfrow = c(2,1))

rnorm> plot(function(x) dnorm(x, log = TRUE), -60, 50,
rnorm+      main = "log { Normal density }")

rnorm> curve(log(dnorm(x)), add = TRUE, col = "red", lwd = 2)

rnorm> mtext("dnorm(x, log=TRUE)", adj = 0)

rnorm> mtext("log(dnorm(x))", col = "red", adj = 1)

rnorm> plot(function(x) pnorm(x, log.p = TRUE), -50, 10,
rnorm+      main = "log { Normal Cumulative }")

rnorm> curve(log(pnorm(x)), add = TRUE, col = "red", lwd = 2)

rnorm> mtext("pnorm(x, log=TRUE)", adj = 0)

rnorm> mtext("log(pnorm(x))", col = "red", adj = 1)

rnorm> ## if you want the so-called 'error function'
rnorm> erf <- function(x) 2 * pnorm(x * sqrt(2)) - 1

rnorm> ## (see Abramowitz and Stegun 29.2.29)
rnorm> ## and the so-called 'complementary error function'
rnorm> erfc <- function(x) 2 * pnorm(x * sqrt(2), lower = FALSE)

rnorm> ## and the inverses
rnorm> erfinv <- function (x) qnorm((1 + x)/2)/sqrt(2)

rnorm> erfcinv <- function (x) qnorm(x/2, lower = FALSE)/sqrt(2)

Help | inside R

If we are not sure about the name of the function, we can search using the apropos function:

apropos("rno")
[1] "psmirnov" "qsmirnov" "rnorm"    "rsmirnov"
apropos("norm")
 [1] "dlnorm"        "dnorm"         "norm"          "normalizePath"
 [5] "plnorm"        "pnorm"         "qlnorm"        "qnorm"        
 [9] "qqnorm"        "rlnorm"        "rnorm"        

Note: You can even use regular expressions in the search string.

Help | inside R

The find() function tells what package a function is in, for instance:

find("rnorm")
[1] "package:stats"

Help | inside R

Many R packages also have vignettes (more detailed descriptions on how the packages work).

To List vignettes from loaded (attached packages):

vignette(all = FALSE)

To list vignettes from all installed packages:

vignette(all = TRUE)

A friendlier option is:

browseVignettes()

Help | inside R

If you know the name of the vignette use:

vignette("reshape")

Help | outside R

The R manuals

Go to https://cran.r-project.org/ and select Manuals on the left bar.

Help | outside R

The R forums and lists

RStudio Community is a friendly forum to ask questions about R and RStudio.

R also has a user list, to search it go to https://cran.r-project.org/ and select Search

Notes: You can also use RSiteSearch("rnorm") from the R console

Help | outside R

Google

The trick to search google is to add “in R”, or just “R” after the search term:

Go to https://google.com

and try searching for random normal numbers in r

Help | outside R

Other good sources for help are:

Help | Before asking a question

Before asking a question make sure that you have:

  1. Searched before asking the question
  2. Narrowed down the problem
  3. Been explicit about what you are trying to do and provide an example of what you want to accomplish.

Help | Reproducible example

Be sure to provided a reproducible example.

  1. Include the list of packages that you have loaded
  2. Provide a minimal dataset
  3. The absolute minimum code that you have that narrows down the problem
  4. The expected output or end result

Help | Reproducible example

For more on this take a look at:

Cheatsheets

Rstudio provides a wide selection of cheatsheets which contain excellent information, particularly when starting out:

Let’s practice

Try to do the exercises below.