6 Seeking Help


6.1 Reading Help files

R, and every package, provide help files for functions. To search for help on a specific function that is in a package loaded into your namespace (your interactive R session):

?function_name

help(function_name)

function_name  # Highlight the function name without parenthesis and press F1

This will load up a help page in RStudio (or as plain text in R by itself).

Each help page is broken down into sections:

  • Description: An extended description of what the function does.
  • Usage: The arguments of the function and their default values (if any).
  • Arguments: An explanation of the input each argument is expecting.
  • Details: Any important details to be aware of.
  • Value: The data the function returns.
  • See Also: Any related functions you might find useful.
  • Examples: Some examples for how to use the function.

Different functions might have different sections, but these are the main ones you should be aware of.


6.2 Special Operators

To seek help on special operators, use quotes:

?"+"

6.3 Getting help on packages

Many packages come with “vignettes”: tutorials and extended example documentation. Without any arguments, vignette() will list all vignettes for all installed packages; vignette(package="package-name") will list all available vignettes forpackage-name, and vignette("vignette-name") will open the specified vignette.

If a package doesn’t have any vignettes, you can usually find help by typing help("package-name").


6.4 When you kind of remember the function

If you’re not sure what package a function is in, or how it’s specifically spelled you can do a fuzzy search:

??function_name

6.5 When you have no idea where to begin

If you don’t know what function or package you need to use CRAN Task Views is a specially maintained list of packages grouped into fields. This can be a good starting point.


6.6 When your code doesn’t work: seeking help from your peers

If you’re having trouble using a function, 9 times out of 10, the answers you are seeking have already been answered on Stack Overflow. You can search using the [r] tag.

If you can’t find the answer, there are a few useful functions to help you ask a question from your peers:

?dput

Will dump the data you’re working with into a format so that it can be copy and pasted by anyone else into their R session.

sessionInfo()
## R version 3.4.2 (2017-09-28)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows >= 8 x64 (build 9200)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252   
## [3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
## [5] LC_TIME=English_Australia.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] bookdown_0.7.10
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_0.12.15.1   digest_0.6.15    withr_2.1.1      rprojroot_1.3-2 
##  [5] R6_2.2.2         backports_1.1.2  magrittr_1.5     git2r_0.21.0    
##  [9] evaluate_0.10.1  httr_1.3.1       stringi_1.2.2    curl_3.1        
## [13] rstudioapi_0.7   rmarkdown_1.9.11 devtools_1.12.0  tools_3.4.2     
## [17] stringr_1.3.1    xfun_0.1         yaml_2.1.19      compiler_3.4.2  
## [21] memoise_1.1.0    htmltools_0.3.6  knitr_1.20

Will print out your current version of R, as well as any packages you have loaded. This can be useful for others to help reproduce and debug your issue.

###################
### Challenge 8 ###
###################

# Look at the help for the `paste` function. You'll need to use this later.  What is the difference between the `sep` and `collapse` arguments?

6.7 Other ports of call