help(package = "rmarkdown")
Getting help
It is truly amazing to see the extent and variety of help that is available to an analyst working in R. You can get basic help within R, through Google searches, in ChatGPT, and through an LLM-based tool within RStudio itself.
1 In RStudio on a package
Suppose that you are perusing the list of packages (both installed and not installed on your system) that are listed in the “Packages” tab in the lower right of RStudio. Further, suppose that you want to learn about one of them. The easiest way from within RStudio is to simply click on the name of the package. As an example, you might look at rmarkdown
, a package that contains tools for creating “dynamic documents for R.”
From the console, you can also type the following:
For some reason, this provides a better formatted (but, seemingly, equivalent in content) result than typing the following:
help(rmarkdown)
In addition to the typical help-page type information that the help()
command displays, you have an option (with some packages) to display more task-oriented or story-based types of information with the vignette()
command:
vignette(package = "rmarkdown")
In the worlds of R and RStudio, a vignette is this task-based help. Type this command into your Console
. It will display the following information (at least as of September 2023):
in package ‘rmarkdown’:
Vignettes
Markdown (source, html)
rmarkdown Learn R -filters Lua filters in R Markdown (source, html) lua
If you want to see a specific vignette, you should type vignette("name-of-package")
. In this case, you have two vignettes that you might display, rmarkdown
and lua-filters
. Let’s take a look at the first:
vignette("rmarkdown")
(Note that the rmarkdown
in this command is the vignette name and not the package name. Confusing, we know.) This brings up some text in the Help
tab in the lower-right pane about how you might go about learning to use R Markdown.
2 In RStudio on a function
R Provides a lot of help on its built-in functions within RStudio. You can type either of the following in order to get help on the select
function (which we will be learning about soon):
help("select")
Or the following:
?select
The same information that pops up in the “Viewer” tab will appear as a pop-over as you are typing the name of command in the Console
. Try this: Go to the >
prompt in the console, type select
but don’t hit the Enter
key. A bunch of helpful information should appear in a pop-up.
3 On the Internet
A thriving community of R users on the Internet are just waiting to answer your question or, more likely, have already answered it. We generally search for answers to our questions from the following:
- Stack Overflow: this is the one that we use most often.
- Getting Help with R
- Cheatsheets
4 In ChatGPT
We are huge believers in the power of LLMs—and, specifically, ChatGPT-4—to improve the productivity of an analyst using R no matter the experience level.
We use them a lot.
We think you should use them a lot as well.
You can use it to explain how to do something. You can use it to interpret existing code for you. You can use it to learn about how you might accomplish something using an alternative approach. And so on.
The following is a simple example of how we used ChatGPT recently. We show what we submitted to ChatGPT and its response to us.
The text we posed to ChatGPT
I have an R question for you. It would be great if your answer used the tidyverse. I have a tibble with 24 columns. I would like to know how many NA values are in each. Thanks!
ChatGPT
Certainly! You can use the tidyverse package to achieve this task conveniently. Functions from the dplyr and tidyr packages within the tidyverse will be particularly helpful. Here’s a step-by-step guide with code to do this:
- First, ensure you’ve loaded the tidyverse package.
- Then, use summarise(across()) to count the NA values across all columns.
Here’s an example of how you can do this:
# Load the tidyverse package
library(tidyverse)
# Assuming your tibble is named my_tibble
<- my_tibble %>%
na_count summarise(across(everything(), ~sum(is.na(.x))))
# Print the result
print(na_count)
In this example:
summarise(across())
is used to apply a function across all columns.everything()
is used to select all columns.~sum(is.na(.x))
calculates the total number of NA values in each column.
This will give you a new tibble (na_count
) where each value represents the number of NA
values in the respective column of the original tibble.
Look at that! It provided a bit of context, then it wrote the code that you might use, and then it explained that code!
Note that, sometimes, the answer that it provides does not work or does not quite do what you want it to do. No worries! Simply tell it about the error or the problem and try again. We have yet to encounter a situation that it has not been able to help with.
5 Using GitHub CoPilot
We won’t go into too much detail here, but you can also get help similar to that provided by ChatGPT within RStudio with a tool called GitHub CoPilot. This tool provides help that is more related to direct code completion. Here are two useful links: