Getting Help with R
A good place to start is Rstudio’s guide for getting help with R
Asking for Help
When asking for help with R it is important to at least
- Include the exact code that you ran
- The error message that you got
Without the code and the error message it can be hard to impossible to diagnose the problem and provide a solution. Questions such as “This isn’t working” or even “I’m getting this error message” aren’t useful without the code and error message.
Even better is to provide a minimal reproducible answer. This is the smallest amount of code that someone else can run, that produces the same error that you are getting. This often means trying to reproduce your error running the same code on a different built-in data set and seeing if you still get the same error. See more instructions here. A benefit of this approach, is that often by trying to reproduce with minimal code you will be able to debug the code itself.
Finally, include the results of sessionInfo()
.
This provides information about the exact versions of R, loaded packages, and operating system you are using, which can be useful in debugging problems.
sessionInfo()
## R version 3.5.0 (2018-04-23)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: macOS High Sierra 10.13.4
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## loaded via a namespace (and not attached):
## [1] compiler_3.5.0 backports_1.1.2 bookdown_0.7 magrittr_1.5
## [5] rprojroot_1.3-2 tools_3.5.0 htmltools_0.3.6 yaml_2.1.18
## [9] Rcpp_0.12.16 stringi_1.1.7 rmarkdown_1.9 blogdown_0.6
## [13] knitr_1.20 stringr_1.3.0 digest_0.6.15 xfun_0.1
## [17] evaluate_0.10.1
For further discussion on how to ask good questions:
- How to ask for help in R
- StackOverflow. How to make a great R reproducible example?
- StackOverflow. How to create a Minimal, Complete, and Verifiable example
- R Posting Guide: How to ask good questions that prompt useful answers
- Coding Killed the Cat. How to ask for programming question
- Matt Gemmell. What Have You Tried?
Getting Help from Within R and RStudio
Help tab: The first place to look is to use the search box in the Help tab of RStudio.
Autocompletion: If you start typing in either the console or editor in RStudio and hit [TAB]
, the RStudio will show a list of completions as well as a short help for each.
There are several R functions to get help.
You can use either ?
or help
.
For example to find help for a function quantile
, both
?quantile
and
help("quantile")
will display the help page for quantile
.
To view this documentation online in a searchable form visit Rdocumentation.org.
To find the help pages available for a package, use help
with the package
argument.
For example,
help(package = "tidyr")
The help for R functions is only useful if you know what function you need want to know either what it is doing, or what the arguments are. The help files in R are not useful for understanding what a package does or how to use it. However, vignettes for R packages are often overviews of the functionality of packages that serve as tutorials or introductions to using the package. To get a list of all vignettes of the packages your have installed, run
browseVignettes()
To get the list of vignettes for a specific package, run
browseVignettes("dplyr")
You can also find vignettes for packages you have not installed on the packages’ CRAN page https://cran.r-project.org/web/packages/tidyr/index.html.
There is also a vignette
function, but you need the exact name of the vignette, which you generally do not know.
You can search for foo in help manuals and archived mailing lists
RSiteSearch("ggplot2")
Want to find out what data sets are included in the R packages that you have installed?
data()
To find data sets included in a specific package, use data
with the package
argument,
For example,
data(package = "ggplot2")
Note that search()
does not do what you expect it to do (unless you expect it to return the search path in which R looks for names of functions and objects).
Help on the Internet
Rdocumentation.org searches the documentation of all R packages on CRAN.
There are several documentation sites that are of particular use:
- tidyverse.org hosts documentation for the various tidyverse packages (ggplot2, tibble, tidyr, reader, purr, dplyr, …).
- ggplot2 documentation. Documentation for ggplot2.
- ggplot2 extensions A list of packages that extend the functionality of ggplot2.
Google has gotten better with R searches, but R
is a particularly unfriendly search term.
However, if you are searching for “R” with other words in context, you are likely to have some success.
An alternative is to use rseek.org instead.
It is a Google search restricted to a curated set of sites related to R.
Many R packages have an article in either the Journal of Statistical Software or The R Journal These articles are similar to package does.
Stack Overflow is a question and answer website for computer programming questions.
Search for questions about R using the “r” tag. You can do this by adding [r]
to your search query. Other tags that may be useful are [ggplot2]
, [plyr]
.
However, generally you should not need to ask questions for this course.
Someone has likely already asked your question before.
If you have a question about “statistics” or “data analysis” rather than “R”, then Cross Validated is a Q-and-A site like Stack Overflow, but for statistics and machine learning.
The traditional source of R help was the R-help mailing list. It is still a useful resource, though much of the traffic has moved over to StackOverflow.
R Cheatsheets
RStudio has man very good cheatsheets. The most relevant to this course are:
- RStudio IDE
- Data Visualization
- Data Transformation Cheat Sheet
- R Markdown
- R Markdown Reference Guide
- Data Import Cheat Sheet
- Base R
- Advanced R
- Regular Expressions
The Short R Reference Card is the classic cheatsheet. However, some of the data manipulation and plotting functions are not those we use in this course, but it does cover much of the statistical functions.
Books
Two references organized by task are The Cookbook for R and Quick-R.
Blogs and Twitter
R-bloggers aggregates R-related blogging.
Task Views
Do you want to know what packages exist for a given topic? CRAN Task Views provide subject matter groupings of R packages. Some potentially useful task-views to social scientists are: