?log
7 Help!
7.1 Built-in help
You can get help for any function by putting a ?
before the name of the function.
So to get help for the function log()
, run
or type fn-F1fn-F1 (F1F1 works on some computers) to get help for the command under the cursor.
This will open the help file in the Help tab of RStudio (by default in the lower left quadrant. You can also search the help from the Help tab.
Most help files have a similar structure (although some sections are optional).
- Description briefly describes the function
- Usage shows the function and its arguments including any defaults
- Arguments describes how the arguments to the functions should be used
- Details Give more details about how to use the function
- Value Describes the output of the function
- Examples Gives examples of how to use the function. This is often one of the most useful parts of the help. You can run the examples by clicking on the “Run examples” link in the help file.
Look at the help file for length()
and run the examples.
7.1.1 Vignettes and demos
Vignettes are long-form documentation that can explain how to use a package. The best way to access them for the dplyr
package is to run
help(package = "dplyr")
and then click on “User guides, package vignettes and other documentation.
Some packages have demos that are like long example sections showing how to use some functions. You can access these with the demo()
function.
7.2 On-line sources of help
The help files are sometimes not the most user friendly.
One of the great things about R is how many sources of help there are.
- R questions on stackoverflow.com
- posit community
There are hundreds of thousands of answers between these sites, so it is likely that other people have had the same problem and asked the same question. Always search to see if find an answer before asking a question. For both these site, it is very important to provide a minimal reproducible example. That is example data (perhaps a built-in dataset) and code that can be run to show the problem. Code not relevant to the problem should be removed. The package reprex
is useful for making reproducible example. Very often, making the reproducible example is enough to identify and fix the problem.
7.3 Artificial Intellegence help
In the last year or two, AI language models have been developed that can help coding in R. This is an area with rapid development, with new products appearing regularly. You ask the AI a question and the AI will reply.
I asked chatGPT, a “How can chatGPT help me code in R?” and it replied
You need a account to use chatGPT. This is free for GPT-4o mini or costs $20/month for the more powerful GPT-4o.
ChatGPT-4o mini was trained on information available in October 2023. It has no information about anything that happened after that date, so may not know about changes in the latest versions of packages that you use.
Phind uses a search engine and summarises what it finds in the output. This means that it knows about recent developments, it also gives the sources it used
It is possible to use copilot within Rstudio to make code suggestions. Copilot is free if you have a verified student account on GitHub.
Be aware that these models do not understand how code works and often generate nonsense code. If you use them, you have to check that the code does what you want. You are responsible for your code whether you write it yourself of with assistance from artificial intelligence.
Ask Phind to explain the error message from the following code
lenght(1:10)
Error in lenght(1:10): could not find function "lenght"
Contributors
- Jonathan Soulé
- Aud Halbritter
- Richard Telford