-
Notifications
You must be signed in to change notification settings - Fork 34
/
02-seeking-help.Rmd
144 lines (109 loc) · 4.43 KB
/
02-seeking-help.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
---
layout: page
title: R for RNAseq analysis
subtitle: Seeking help
minutes: 15
---
```{r, include=FALSE}
source("tools/chunk-options.R")
```
> ## Learning Objectives {.objectives}
>
> * To be able read R help files for functions and special operators.
> * To be able to use CRAN task views to identify packages to solve a problem.
> * To be able to seek help from your peers
>
## Reading Help files
R, and every package, provide help files for functions. To search for help on a
function from a specific function that is in a package loaded into your
namespace (your interactive R session):
```{r, eval=FALSE}
?function_name
help(function_name)
```
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.
- Arguments: An explanation of the data 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.
> ## Tip: Reading help files {.callout}
>
> One of the most daunting aspects of R is the large number of functions
> available. It would be prohibitive, if not impossible to remember the
> correct usage for every function you use. Luckily, the help files
> mean you don't have to!
>
## Special Operators
To seek help on special operators, use quotes:
```{r, eval=FALSE}
?"+"
```
## 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 for
`package-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")`.
## 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:
```{r, eval=FALSE}
??function_name
```
## When you have no idea where to begin
If you don't know what function or package you need to use
[CRAN Task Views](http://cran.at.r-project.org/web/views)
is a specially maintained list of packages grouped into
fields. This can be a good starting point.
## 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](http://stackoverflow.com/). 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:
```{r, eval=FALSE}
?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.
```{r}
sessionInfo()
```
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 1 {.challenge}
>
> Look at the help for the `c` function. What kind of vector do you
> expect you will create if you evaluate the following:
> ```{r, eval=FALSE}
> c(1, 2, 3)
> c('d', 'e', 'f')
> c(1, 2, 'f')`
> ```
> ## Challenge 2 {.challenge}
> Use help to find a function (and its associated parameters) that you could
> use to load data from a csv file in which columns are delimited with "\t"
> (tab) and the decimal point is a "." (period). This check for decimal
> separator is important, especially if you are working with international
> colleagues, because different countries have different conventions for the
> decimal point (i.e. comma vs period).
> hint: use `??csv` to lookup csv related functions.
## Other ports of call
* [Quick R](http://www.statmethods.net/)
* [RStudio cheat sheets](http://www.rstudio.com/resources/cheatsheets/)
* [Cookbook for R](http://www.cookbook-r.com/)
## Challenge solutions
> ## Solution to Challenge 1 {.challenge}
>
> The `c()` function creates a vector, in which all elements are the
> same type. In the first case, the elements are numeric, in the
> second, they are characters, and in the third they are characters:
> the numeric values "coerced" to be characters.
>