help(): Help document for pre-built functions

If you type ls() the function is evaluated and, as seen before, we see objects in the workspace.

Unlike ls, most functions require one or more arguments. Below is an example of how we assign an object to the argument of the function log. Remember that we earlier defined a to be 1:

log(8)
#> [1] 2.08
log(a) 
#> [1] 0

You can find out what the function expects and what it does by reviewing the very useful manuals included in R. You can get help by using the help function like this:

help("log")

For most functions, we can also use this shorthand:

?log

The help page will show you what arguments the function is expecting.

If you want a quick look at the arguments without opening the help system, you can type:

args(log)
#> function (x, base = exp(1)) 
#> NULL

Some arguments are required and others are optional. In log function, the default value of base is exp(1) and it is optional. If we do not put the value on the base, log function consider itself as a natural log with base of e.

We can specify the base argument of log like this:

log(base = 2, x = 8)
#> [1] 3

In addition, there is a help tab in the right bottom pannel in RStudio. When we use help function, the help document pops up in the help tab like the image below:

1-6_help.png

Instruction

# DO NOT RUN this code in the environment # COPY AND PASTE THIS CODE AND RUN IN RSTUDIO. # Pop up the help document of seq function. help("seq") # Another method to pop up the help document of seq. ?seq # Find arguments of seq function. args(seq) # An example of using seq function seq(1, 10)

Previous: 1-5 | ls(): Lists of variables saved in the workspace

Next: 1-7 | install.packages(): install packages from external sources

Back to Main