forked from swcarpentry/r-novice-gapminder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03-seeking-help.html
160 lines (156 loc) · 9.53 KB
/
03-seeking-help.html
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<title>Software Carpentry: R for reproducible scientific analysis</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap-theme.css" />
<link rel="stylesheet" type="text/css" href="css/swc.css" />
<link rel="alternate" type="application/rss+xml" title="Software Carpentry Blog" href="http://software-carpentry.org/feed.xml"/>
<meta charset="UTF-8" />
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body class="lesson">
<div class="container card">
<div class="banner">
<a href="http://software-carpentry.org" title="Software Carpentry">
<img alt="Software Carpentry banner" src="img/software-carpentry-banner.png" />
</a>
</div>
<article>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<a href="index.html"><h1 class="title">R for reproducible scientific analysis</h1></a>
<h2 class="subtitle">Seeking help</h2>
<section class="objectives panel panel-warning">
<div class="panel-heading">
<h2 id="learning-objectives"><span class="glyphicon glyphicon-certificate"></span>Learning Objectives</h2>
</div>
<div class="panel-body">
<ul>
<li>To be able read R help files for functions and special operators.</li>
<li>To be able to use CRAN task views to identify packages to solve a problem.</li>
<li>To be able to seek help from your peers</li>
</ul>
</div>
</section>
<h2 id="reading-help-files">Reading Help files</h2>
<p>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):</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">?function_name
<span class="kw">help</span>(function_name)</code></pre></div>
<p>This will load up a help page in RStudio (or as plain text in R by itself).</p>
<p>Each help page is broken down into sections:</p>
<ul>
<li>Description: An extended description of what the function does.</li>
<li>Usage: The arguments of the function and their default values.</li>
<li>Arguments: An explanation of the data each argument is expecting.</li>
<li>Details: Any important details to be aware of.</li>
<li>Value: The data the function returns.</li>
<li>See Also: Any related functions you might find useful.</li>
<li>Examples: Some examples for how to use the function.</li>
</ul>
<p>Different functions might have different sections, but these are the main ones you should be aware of.</p>
<aside class="callout panel panel-info">
<div class="panel-heading">
<h2 id="tip-reading-help-files"><span class="glyphicon glyphicon-pushpin"></span>Tip: Reading help files</h2>
</div>
<div class="panel-body">
<p>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!</p>
</div>
</aside>
<h2 id="special-operators">Special Operators</h2>
<p>To seek help on special operators, use quotes:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">?<span class="st">"+"</span></code></pre></div>
<h2 id="getting-help-on-packages">Getting help on packages</h2>
<p>Many packages come with “vignettes”: tutorials and extended example documentation. Without any arguments, <code>vignette()</code> will list all vignettes for all installed packages; <code>vignette(package="package-name")</code> will list all available vignettes for <code>package-name</code>, and <code>vignette("vignette-name")</code> will open the specified vignette.</p>
<p>If a package doesn’t have any vignettes, you can usually find help by typing <code>help("package-name")</code>.</p>
<h2 id="when-you-kind-of-remember-the-function">When you kind of remember the function</h2>
<p>If you’re not sure what package a function is in, or how it’s specifically spelled you can do a fuzzy search:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">??function_name</code></pre></div>
<h2 id="when-you-have-no-idea-where-to-begin">When you have no idea where to begin</h2>
<p>If you don’t know what function or package you need to use <a href="http://cran.at.r-project.org/web/views">CRAN Task Views</a> is a specially maintained list of packages grouped into fields. This can be a good starting point.</p>
<h2 id="when-your-code-doesnt-work-seeking-help-from-your-peers">When your code doesn’t work: seeking help from your peers</h2>
<p>If you’re having trouble using a function, 9 times out of 10, the answers you are seeking have already been answered on <a href="http://stackoverflow.com/">Stack Overflow</a>. You can search using the <code>[r]</code> tag.</p>
<p>If you can’t find the answer, there are a few useful functions to help you ask a question from your peers:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">?dput</code></pre></div>
<p>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.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">sessionInfo</span>()</code></pre></div>
<pre class="output"><code>R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.1 (El Capitan)
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 base
other attached packages:
[1] knitr_1.11
loaded via a namespace (and not attached):
[1] magrittr_1.5 formatR_1.2.1 tools_3.2.2 stringi_1.0-1 methods_3.2.2
[6] stringr_1.0.0 evaluate_0.8
</code></pre>
<p>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.</p>
<section class="challenge panel panel-success">
<div class="panel-heading">
<h2 id="challenge-1"><span class="glyphicon glyphicon-pencil"></span>Challenge 1</h2>
</div>
<div class="panel-body">
<p>Look at the help for the <code>c</code> function. What kind of vector do you expect you will create if you evaluate the following:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">c</span>(<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>)
<span class="kw">c</span>(<span class="st">'d'</span>, <span class="st">'e'</span>, <span class="st">'f'</span>)
<span class="kw">c</span>(<span class="dv">1</span>, <span class="dv">2</span>, <span class="st">'f'</span>)<span class="st">`</span></code></pre></div>
</div>
</section>
<section class="challenge panel panel-success">
<div class="panel-heading">
<h2 id="challenge-2"><span class="glyphicon glyphicon-pencil"></span>Challenge 2</h2>
</div>
<div class="panel-body">
<p>Look at the help for the <code>paste</code> function. You’ll need to use this later. What is the difference between the <code>sep</code> and <code>collapse</code> arguments?</p>
</div>
</section>
<h2 id="other-ports-of-call">Other ports of call</h2>
<ul>
<li><a href="http://www.statmethods.net/">Quick R</a></li>
<li><a href="http://www.rstudio.com/resources/cheatsheets/">RStudio cheat sheets</a></li>
<li><a href="http://www.cookbook-r.com/">Cookbook for R</a></li>
</ul>
<h2 id="challenge-solutions">Challenge solutions</h2>
<section class="challenge panel panel-success">
<div class="panel-heading">
<h2 id="solution-to-challenge-1"><span class="glyphicon glyphicon-pencil"></span>Solution to Challenge 1</h2>
</div>
<div class="panel-body">
<p>The <code>c()</code> 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.</p>
</div>
</section>
<section class="challenge panel panel-success">
<div class="panel-heading">
<h2 id="solution-to-challenge-2"><span class="glyphicon glyphicon-pencil"></span>Solution to Challenge 2</h2>
</div>
<div class="panel-body">
<p>Look at the help for the <code>paste</code> function. You’ll need to use this later.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">help</span>(<span class="st">"paste"</span>)
?paste</code></pre></div>
</div>
</section>
</div>
</div>
</article>
<div class="footer">
<a class="label swc-blue-bg" href="http://software-carpentry.org">Software Carpentry</a>
<a class="label swc-blue-bg" href="https://github.com/swcarpentry/lesson-template">Source</a>
<a class="label swc-blue-bg" href="mailto:[email protected]">Contact</a>
<a class="label swc-blue-bg" href="LICENSE.html">License</a>
</div>
</div>
<!-- Javascript placed at the end of the document so the pages load faster -->
<script src="http://software-carpentry.org/v5/js/jquery-1.9.1.min.js"></script>
<script src="css/bootstrap/bootstrap-js/bootstrap.js"></script>
</body>
</html>