9  Help and Documentation

NoteSession Overview

Estimated time: ~15 minutes

By the end of this session you’ll be able to:

  • Open a function’s help file using ? or help().
  • View all the documentation for an installed package with help(package = "packageName").
  • Search across R’s documentation with ?? or help.search() when you don’t know a function’s exact name.
  • Know where to look (online communities, the Troubleshooting & FAQ appendix) when you get stuck.

Before you start: Basic Data Visualization – no new objects are required for this session.

Self-paced tip: This is the shortest session in the course, but one of the most useful – the skills here are how you’ll keep learning R long after this course ends.

Understanding how to access help and documentation in R is crucial for both beginners and experienced users. This section will guide you through two essential skills: accessing help files and searching for R documentation. These tools will empower you to find solutions and understand functions or packages better as you progress in your R journey.

9.1 Accessing Help Files

In R, every function and package comes with a help file that explains its usage, arguments, and provides examples. These files are invaluable for learning how to use different functions correctly.

9.1.1 How to Access Help Files:

  1. Using ? Operator: The simplest way to access help for a function is by using the ? operator followed by the function name. For example, ?mean will open the help file for the mean function.

  2. Using help() Function: Alternatively, you can use the help() function. For example, help(mean) achieves the same as ?mean.

  3. Help for Packages: To view documentation for a whole package, use help(package = "packageName"). Replace "packageName" with the name of the package you’re interested in.

9.1.2 Tips for Navigating Help Files:

  • Arguments: Pay attention to the ‘Arguments’ section to understand what inputs the function accepts.
  • Examples: The ‘Examples’ section is great for seeing how the function works in practice.
  • See Also: This section provides links to related functions and documentation.

9.2 Searching for R Documentation

Sometimes you might not remember the exact name of a function or you’re looking for functions related to a specific task. Here’s how to search effectively:

  1. Using ?? Operator: This is a broader search than ?. For example, ??regression will return a list of help files related to regression.

  2. Using help.search() Function: This works similarly to ??. For example, help.search("regression") will search for “regression” in the R documentation.

  3. Online Resources: Websites like RDocumentation or CRAN provide searchable databases of R documentation.

9.2.1 Tips for Effective Searching:

  • Use Keywords: Think about the keywords related to what you’re trying to find.
  • Explore Related Functions: Often, searching will lead you to related functions that might be useful.
  • Check Online Communities: Forums like Stack Overflow have a wealth of information and examples.

Mastering the use of help files and knowing how to search the R documentation effectively will significantly enhance your ability to learn and solve problems in R. Remember, seeking help is an integral part of the learning process, and these tools are there to assist you every step of the way.

Tip

Always explore the examples given in the help files, as they often provide practical insights into how functions can be used.

9.3 Summary & Self-Check

Key takeaways:

  • ?function_name (or help(function_name)) opens the help file for a specific function – check the Arguments and Examples sections first.
  • help(package = "packageName") lists all the help files for an entire package.
  • ??keyword (or help.search("keyword")) searches R’s documentation when you don’t know the exact function name.
  • When R’s built-in help isn’t enough, the Troubleshooting & FAQ appendix and communities like Stack Overflow and the RStudio Community are great next steps.

Check your understanding:

Which command opens the help file for the mean() function?

True or false: ??regression searches R’s documentation for anything related to “regression”, even if you don’t know the exact function name.

To see all the help files for an installed package called dplyr, you would type .

What’s next: Congratulations – you’ve completed all 9 sessions! Revisit the Course Roadmap for a recap of everything you’ve covered, and take a few minutes for Pause & Reflect to consolidate what you’ve learned.