One advantage of using R is that it is a very well-documented programming language. This is often because there is a certain amount of documentation that is required by CRAN before it will publish a package on the website.
It is considered a best practice to document your packages or functions well, no matter where you are publishing them. Good documentation is important, both for other people who may use your functions and also for yourself when you return to them in the future.
As such, there are a few built-in ways in R to get help. The first way to get help is to use the package documentation. You can access it by using the help() function or the question mark ?. These will do the same thing. For example, say you (this one happens a lot) can't remember off the top of your head the inputs to the glm() function. The following code will bring up the documentation for the glm() function, as shown in the following screenshot:
If you read the documentation, you will see that you need to input at least a formula, family, and dataset name.
Of course, help() and the question mark ? can only help you with packages and functions you already know the name of. When you're not as sure, you can use help. search() and ?? to find things. These functions are also analogous, and will search the built-in help documentation for any and all instances of what you're looking for, for example, help.search("logit") or ??logit.
Both of the preceding options return a long list of help pages where logit appears. As you look through the results of your search for logit in the R documentation, you may notice that there are lots of things written in the format agricolae::reg.homog and base::Control.
In R, this notation means that the agricolae package has a function called reg.homog (agricolae::reg.homog), and that the base package has a function called Control (base::Control).
The double colon :: always separates a package and function name in R. (This comes in handy when you have functions named after the same thing in multiple packages, such as stats::filter and dplyr::filter!)
In addition to the often very helpful and thorough documentation built into R, some packages also have one or more vignettes, which are documents written by the author(s) of the package that are intended to demonstrate the main functionality of the functions contained in the package. You can bring these up inside RStudio in a number of ways.
Let's use the vignette-related functions browseVignettes() and vignettes() to explore the vignettes for R packages. Follow the steps given below:
- To see a list of many available vignettes in R, use the browseVignettes() method:
- Browse the vignettes available for the dplyr package using the method syntax browseVignettes(package = "dplyr") or browseVignettes("dplyr")
- Access the vignette for the tibble package using the syntax vignette("tibble") or vignette(package = "tibble").
- In a search engine of your choice, find the vignette for the R package tidyr.
Check your Help tab to see the vignettes when you access them inside of RStudio. The output will be as follows: