1 minute read
The YAML Language �������������������������������������������������������������������������������������������������������
Chapter 1 ■ IntroduCtIon to r programmIng
Figure 1-3. RStudio’s help frame
Advertisement
Try looking up the documentation for a few functions. For example, the nchar function you also saw previously.
All infix operators, like + or %%, are also functions in R, and you can read the documentation for them as well. But you cannot write ?+ in the R terminal and get the information. The R parser doesn’t know how to deal with that. If you want help on an infix operator, you need to quote it, and you do that using backquotes. So to read the documentation for +, you need to write:
You probably do not need help to figure out what addition does, but people can write their own infix operators, so this is useful to know when you need help on those.
Writing Your Own Functions
You can easily write your own functions. You use function expressions to define a function and an assignment to give a function a name. For example, to write a function that computes the square of a number, you can write:
square <- function(x) x**2 square(1:4) ## [1] 1 4 9 16
10