Difference between revisions of "RPR-Help"

From "A B C"
Jump to navigation Jump to search
m
m
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
<div id="BIO">
+
<div id="ABC">
  <div class="b1">
+
<div style="padding:5px; border:1px solid #000000; background-color:#b3dbce; font-size:300%; font-weight:400; color: #000000; width:100%;">
 
Getting help for R
 
Getting help for R
  </div>
+
<div style="padding:5px; margin-top:20px; margin-bottom:10px; background-color:#b3dbce; font-size:30%; font-weight:200; color: #000000; ">
 
+
(The internal R help system; other help resources.)
  {{Vspace}}
+
</div>
 
 
<div class="keywords">
 
<b>Keywords:</b>&nbsp;
 
The R help system, other help resources
 
 
</div>
 
</div>
  
{{Vspace}}
+
{{Smallvspace}}
 
 
 
 
__TOC__
 
 
 
{{Vspace}}
 
 
 
  
{{DEV}}
 
  
{{Vspace}}
+
<div style="padding:5px; border:1px solid #000000; background-color:#b3dbce33; font-size:85%;">
 
+
<div style="font-size:118%;">
 
+
<b>Abstract:</b><br />
</div>
 
<div id="ABC-unit-framework">
 
== Abstract ==
 
 
<section begin=abstract />
 
<section begin=abstract />
<!-- included from "../components/RPR-Help.components.wtxt", section: "abstract" -->
 
 
This unit discusses the available Help resources for R programming and develops effective strategies for solving problems.
 
This unit discusses the available Help resources for R programming and develops effective strategies for solving problems.
 
<section end=abstract />
 
<section end=abstract />
 +
</div>
 +
<!-- ============================  -->
 +
<hr>
 +
<table>
 +
<tr>
 +
<td style="padding:10px;">
 +
<b>Objectives:</b><br />
 +
This unit will ...
 +
* ... introduce the inbuilt R help system;
 +
* ... point you to useful alternatives;
 +
* ... discuss how to write effective questions on technical forums and mailing lists.
 +
</td>
 +
<td style="padding:10px;">
 +
<b>Outcomes:</b><br />
 +
After working through this unit you ...
 +
* ... have used the R help system;
 +
* ... are able to get help on a function:
 +
** via R's internal system,
 +
** via Web searches, or
 +
** by asking effective questions (including Minimal Working Examples - MWE) on mailing lists.
  
{{Vspace}}
+
</td>
 +
</tr>
 +
</table>
 +
<!-- ============================  -->
 +
<hr>
 +
<b>Deliverables:</b><br />
 +
<section begin=deliverables />
 +
<li><b>Time management</b>: Before you begin, estimate how long it will take you to complete this unit. Then, record in your course journal: the number of hours you estimated, the number of hours you worked on the unit, and the amount of time that passed between start and completion of this unit.</li>
 +
<li><b>Journal</b>: Document your progress in your [[FND-Journal|Course Journal]]. Some tasks may ask you to include specific items in your journal. Don't overlook these.</li>
 +
<li><b>Insights</b>: If you find something particularly noteworthy about this unit, make a note in your [[ABC-Insights|'''insights!''' page]].</li>
 +
<section end=deliverables />
 +
<!-- ============================  -->
 +
<hr>
 +
<section begin=prerequisites />
 +
<b>Prerequisites:</b><br />
 +
This unit builds on material covered in the following prerequisite units:<br />
 +
*[[RPR-Installation|RPR-Installation (Installing R and RStudio)]]
 +
<section end=prerequisites />
 +
<!-- ============================  -->
 +
</div>
  
 +
{{Smallvspace}}
  
== This unit ... ==
 
=== Prerequisites ===
 
<!-- included from "../components/RPR-Help.components.wtxt", section: "prerequisites" -->
 
<!-- included from "ABC-unit_components.wtxt", section: "notes-prerequisites" -->
 
You need to complete the following units before beginning this one:
 
*[[RPR-Installation]]
 
  
{{Vspace}}
 
  
 +
{{Smallvspace}}
  
=== Objectives ===
 
<!-- included from "../components/RPR-Help.components.wtxt", section: "objectives" -->
 
...
 
  
{{Vspace}}
+
__TOC__
 
 
 
 
=== Outcomes ===
 
<!-- included from "../components/RPR-Help.components.wtxt", section: "outcomes" -->
 
...
 
 
 
{{Vspace}}
 
 
 
 
 
=== Deliverables ===
 
<!-- included from "../components/RPR-Help.components.wtxt", section: "deliverables" -->
 
<!-- included from "ABC-unit_components.wtxt", section: "deliverables-time_management" -->
 
*<b>Time management</b>: Before you begin, estimate how long it will take you to complete this unit. Then, record in your course journal: the number of hours you estimated, the number of hours you worked on the unit, and the amount of time that passed between start and completion of this unit.
 
<!-- included from "ABC-unit_components.wtxt", section: "deliverables-journal" -->
 
*<b>Journal</b>: Document your progress in your [[FND-Journal|Course Journal]]. Some tasks may ask you to include specific items in your journal. Don't overlook these.
 
<!-- included from "ABC-unit_components.wtxt", section: "deliverables-insights" -->
 
*<b>Insights</b>: If you find something particularly noteworthy about this unit, make a note in your [[ABC-Insights|'''insights!''' page]].
 
  
 
{{Vspace}}
 
{{Vspace}}
Line 72: Line 71:
  
 
=== Evaluation ===
 
=== Evaluation ===
<!-- included from "../components/RPR-Help.components.wtxt", section: "evaluation" -->
 
<!-- included from "ABC-unit_components.wtxt", section: "eval-none" -->
 
 
<b>Evaluation: NA</b><br />
 
<b>Evaluation: NA</b><br />
:This unit is not evaluated for course marks.
+
<div style="margin-left: 2rem;">This unit is not evaluated for course marks.</div>
 
 
{{Vspace}}
 
 
 
 
 
</div>
 
<div id="BIO">
 
 
== Contents ==
 
== Contents ==
<!-- included from "../components/RPR-Help.components.wtxt", section: "contents" -->
 
 
====The Help system====
 
====The Help system====
  
Line 92: Line 82:
  
  
 +
If all you need is the correct name of a function (eg. was it <code>list_files()</code>, <code>list.files()</code>, or <code>listFiles()</code>?), just type the first three characters of the function name and use RStudio's autocomplete mechanism to find what you need.
  
Help is available for all commands as well as for the '''R''' syntax. As well, help is available to find the names of commands when you are not sure of them. You can get help through the command line, or from a search field in the '''Help''' tab of the lower-right pane.
+
If you are wondering about the parameters of a function, just hover the cursor over the function name in the script pane or the command line in the console and wait a moment: a little window with the function signature will pop up.
  
 +
But for more detailed information, help is available for all commands as well as for the '''R''' syntax. As well, help is available to find the names of commands when you are not sure of them. You can get help through the command line, or from a search field in the '''Help''' tab of the lower-right pane.
  
 
<small>(<code>help()</code> is a function in '''R''', arguments to a function are passed in parentheses "()")</small>
 
<small>(<code>help()</code> is a function in '''R''', arguments to a function are passed in parentheses "()")</small>
<source lang="rsplus">
+
<pre>
 
> help(rnorm)
 
> help(rnorm)
 
>
 
>
</source>
+
</pre>
  
  
 
<small>(shorthand for the same thing)</small>
 
<small>(shorthand for the same thing)</small>
<source lang="rsplus">
+
<pre>
 
> ?rnorm
 
> ?rnorm
 
>
 
>
</source>
+
</pre>
  
  
 
<small>(what was the name of that again ... ?)</small>
 
<small>(what was the name of that again ... ?)</small>
<source lang="rsplus">
+
<pre>
 
> ?binom
 
> ?binom
 
No documentation for 'binom' in specified packages and libraries:
 
No documentation for 'binom' in specified packages and libraries:
Line 117: Line 109:
 
> ??binom
 
> ??binom
 
>
 
>
</source>
+
</pre>
  
  
 
<small>(I see "Binomial" in the list of keywords...)</small>
 
<small>(I see "Binomial" in the list of keywords...)</small>
<source lang="rsplus">
+
<pre>
 
> ?Binomial
 
> ?Binomial
 
>
 
>
</source>
+
</pre>
  
  
 
<small>(Alternatively: use the apropos() function.</small>
 
<small>(Alternatively: use the apropos() function.</small>
<source lang="rsplus">
+
<pre>
 
> ?apropos
 
> ?apropos
 
> apropos("med")  # all functions that contain the string "med"
 
> apropos("med")  # all functions that contain the string "med"
 
> apropos("^med")  # all functions that begin with the string
 
> apropos("^med")  # all functions that begin with the string
 
> apropos("med$")  # all functions that end with the string
 
> apropos("med$")  # all functions that end with the string
</source>
+
</pre>
  
  
  
 
If you need help on '''operators''', place them in quotation marks. Try:
 
If you need help on '''operators''', place them in quotation marks. Try:
<source lang="rsplus">
+
<pre>
 
> ?"+"
 
> ?"+"
 
> ?"~"
 
> ?"~"
Line 144: Line 136:
 
> ?"%in%"
 
> ?"%in%"
 
>
 
>
</source>
+
</pre>
  
  
That's all fine, but you will soon notice that '''R''''s help documentation is not all that helpful for newcomers (who need the most help). To illustrate, open the help window for the function {{c|var()}}.
+
That's all fine, but you will soon notice that '''R''''s help documentation is very technical and precise but not all that helpful for newcomers (who need the most help). To illustrate, open the help window for the function {{c|var()}}.
<source lang="rsplus">
+
<pre>
 
> ?var
 
> ?var
</source>
+
</pre>
  
  
Line 158: Line 150:
 
* The '''Arguments''' section provides detailed information . You should read it, especially regarding whether the arguments are single values, vectors, or other objects, and what effect missing arguments will have.
 
* The '''Arguments''' section provides detailed information . You should read it, especially regarding whether the arguments are single values, vectors, or other objects, and what effect missing arguments will have.
 
* The '''Details''' section might provide common usage and context information. It might also not. Often functions have crucial information buried in an innocuous note here.
 
* The '''Details''' section might provide common usage and context information. It might also not. Often functions have crucial information buried in an innocuous note here.
* You have to really understand the '''Value''' section. It explains the output. Importantly, it explains the type of object a function returns - it could be a list, a matrix or something else (we'll discuss these data types in detail below.). The value could also be an object that has special methods defined e.g. for plotting it. In that case, the object is formally a "list", and its named "components" can be retrieved with the usual list syntax (see below).
+
* You really have to read and understand the '''Value''' section. It explains the output of the function (its return'''value'''). The object a function returns could be a list, a matrix or something else (we'll discuss these data types in detail elsewhere.). The value could also be an object that has special methods defined e.g. for plotting it. In that case, the object is formally a "list", and its named "components" can be retrieved with the usual list syntax.
  
 
If you look at the bottom of the help text, you will usually find examples of the function's usage; these sometimes make matters more clear than the terse and principled help-text above.
 
If you look at the bottom of the help text, you will usually find examples of the function's usage; these sometimes make matters more clear than the terse and principled help-text above.
Line 183: Line 175:
  
  
If you want a quick and constructive answer from the '''R''' mailing list or stackoverflow, you '''must''' do a bit of homework first. If you ask your question well, you will get incredibly insightful and helpful responses, but you need to help the helpers help you:
+
If you want a quick and constructive answer from the '''R''' mailing list or stackoverflow (or from me, in a course or workshop for that matter), you '''must''' do a bit of homework first. If you ask your question well, you will get incredibly insightful and helpful responses, but you need to help the helpers to help you:
  
* Use the {{c|dput()}} function, perhaps combined with {{c|head()}} to create a '''small, reproducible dataset''' with which your problem can be reproduced or your question illustrated. Keep this as small as possible. Post that.
+
* Use the {{c|dput()}} function, perhaps combined with {{c|head()}} to create a '''small, reproducible dataset''' with which your problem can be reproduced or your question illustrated. Keep this as small as possible. Post that. '''Don't post screenshots!'''
 
* Post minimal '''code''' that reproduces the problem with the data you have supplied. Together the code and data have to form an '''MWE''' – a minimal working example. People love to play with your code and get it to work, but they '''hate''' having to copy, paste, reformat or otherwise edit someone's stuff just so they can answer their question.
 
* Post minimal '''code''' that reproduces the problem with the data you have supplied. Together the code and data have to form an '''MWE''' – a minimal working example. People love to play with your code and get it to work, but they '''hate''' having to copy, paste, reformat or otherwise edit someone's stuff just so they can answer their question.
* Don't waste too much time on explaining what you did (since that didn't work), but explain clearly '''what you want to achieve'''. Focus on the desired result - not on how to fix your algorithm; your algorithm may be the wrong mental model in the first place.
+
* Don't waste too much time on explaining what you did (since that didn't work) - just enough to help your readers understand that you did indeed invest some effort in trying to solve the problem yourself. Spend your time to explain clearly '''what you want to achieve'''. Focus on the desired result - not on how to fix your algorithm; your algorithm may be the wrong mental model in the first place.
 
* Don't post in HTML, be sure to post in '''plain text''' only.
 
* Don't post in HTML, be sure to post in '''plain text''' only.
* Read [http://adv-r.had.co.nz/Reproducibility.html "How to write a reproducible example"] and [http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example "How to make a great R reproducible example"] before you post.
 
  
{{Vspace}}
 
  
 +
{{task|1=
 +
* Read [http://adv-r.had.co.nz/Reproducibility.html "How to write a reproducible example"] and [http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example "How to make a great R reproducible example"].
  
{{Vspace}}
+
BTW: the same principles apply to questions you post on the course mailing list.
 
+
}}
 
 
== Further reading, links and resources ==
 
<!-- {{#pmid: 19957275}} -->
 
<!-- {{WWW|WWW_GMOD}} -->
 
<!-- <div class="reference-box">[http://www.ncbi.nlm.nih.gov]</div> -->
 
 
 
{{Vspace}}
 
 
 
 
 
== Notes ==
 
<!-- included from "../components/RPR-Help.components.wtxt", section: "notes" -->
 
<!-- included from "ABC-unit_components.wtxt", section: "notes" -->
 
<references />
 
  
 
{{Vspace}}
 
{{Vspace}}
  
 
</div>
 
<div id="ABC-unit-framework">
 
 
== Self-evaluation ==
 
== Self-evaluation ==
<!-- included from "../components/RPR-Help.components.wtxt", section: "self-evaluation" -->
 
 
<!--
 
<!--
 
=== Question 1===
 
=== Question 1===
Line 233: Line 208:
  
 
-->
 
-->
 +
=== Question 1===
  
{{Vspace}}
+
Is the <code>apropos()</code> command case-sensitive?
  
 +
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px">
 +
Answer ...
 +
<div class="mw-collapsible-content">
 +
Try it out:
 +
<pre>
 +
apropos("^med")
 +
apropos("^MED")
 +
</pre>
  
 +
</div>
 +
  </div>
  
{{Vspace}}
+
  {{Vspace}}
  
 
+
== Further reading, links and resources ==
<!-- included from "ABC-unit_components.wtxt", section: "ABC-unit_ask" -->
+
<!-- {{#pmid: 19957275}} -->
 
+
<!-- {{WWW|WWW_GMOD}} -->
----
+
<!-- <div class="reference-box">[http://www.ncbi.nlm.nih.gov]</div> -->
 +
== Notes ==
 +
<references />
  
 
{{Vspace}}
 
{{Vspace}}
  
<b>If in doubt, ask!</b> If anything about this learning unit is not clear to you, do not proceed blindly but ask for clarification. Post your question on the course mailing list: others are likely to have similar problems. Or send an email to your instructor.
 
 
----
 
 
{{Vspace}}
 
  
 
<div class="about">
 
<div class="about">
Line 261: Line 244:
 
:2017-08-05
 
:2017-08-05
 
<b>Modified:</b><br />
 
<b>Modified:</b><br />
:2017-08-05
+
:2020-09-15
 
<b>Version:</b><br />
 
<b>Version:</b><br />
:0.1
+
:1.1
 
<b>Version history:</b><br />
 
<b>Version history:</b><br />
*0.1 First stub
+
*1.1 Maintenance, and removed GeSHi calls
 +
*1.0.1 Maintenance
 +
*1.0 Completed to first live version
 +
*0.1 Material collected from previous tutorial
 
</div>
 
</div>
[[Category:ABC-units]]
 
<!-- included from "ABC-unit_components.wtxt", section: "ABC-unit_footer" -->
 
  
 
{{CC-BY}}
 
{{CC-BY}}
  
 +
[[Category:ABC-units]]
 +
{{UNIT}}
 +
{{LIVE}}
 
</div>
 
</div>
 
<!-- [END] -->
 
<!-- [END] -->

Latest revision as of 09:28, 25 September 2020

Getting help for R

(The internal R help system; other help resources.)


 


Abstract:

This unit discusses the available Help resources for R programming and develops effective strategies for solving problems.


Objectives:
This unit will ...

  • ... introduce the inbuilt R help system;
  • ... point you to useful alternatives;
  • ... discuss how to write effective questions on technical forums and mailing lists.

Outcomes:
After working through this unit you ...

  • ... have used the R help system;
  • ... are able to get help on a function:
    • via R's internal system,
    • via Web searches, or
    • by asking effective questions (including Minimal Working Examples - MWE) on mailing lists.

Deliverables:

  • Time management: Before you begin, estimate how long it will take you to complete this unit. Then, record in your course journal: the number of hours you estimated, the number of hours you worked on the unit, and the amount of time that passed between start and completion of this unit.
  • Journal: Document your progress in your Course Journal. Some tasks may ask you to include specific items in your journal. Don't overlook these.
  • Insights: If you find something particularly noteworthy about this unit, make a note in your insights! page.

  • Prerequisites:
    This unit builds on material covered in the following prerequisite units:


     



     



     


    Evaluation

    Evaluation: NA

    This unit is not evaluated for course marks.

    Contents

    The Help system

    Task:

    • Start RStudio (if it's not already open) and as you work through the sections below, type the commands and explore what they do.


    If all you need is the correct name of a function (eg. was it list_files(), list.files(), or listFiles()?), just type the first three characters of the function name and use RStudio's autocomplete mechanism to find what you need.

    If you are wondering about the parameters of a function, just hover the cursor over the function name in the script pane or the command line in the console and wait a moment: a little window with the function signature will pop up.

    But for more detailed information, help is available for all commands as well as for the R syntax. As well, help is available to find the names of commands when you are not sure of them. You can get help through the command line, or from a search field in the Help tab of the lower-right pane.

    (help() is a function in R, arguments to a function are passed in parentheses "()")

    > help(rnorm)
    >
    


    (shorthand for the same thing)

    > ?rnorm
    >
    


    (what was the name of that again ... ?)

    > ?binom
    No documentation for 'binom' in specified packages and libraries:
    you could try '??binom'
    > ??binom
    >
    


    (I see "Binomial" in the list of keywords...)

    > ?Binomial
    >
    


    (Alternatively: use the apropos() function.

    > ?apropos
    > apropos("med")   # all functions that contain the string "med"
    > apropos("^med")  # all functions that begin with the string
    > apropos("med$")  # all functions that end with the string
    


    If you need help on operators, place them in quotation marks. Try:

    > ?"+"
    > ?"~"
    > ?"["
    > ?"%in%"
    >
    


    That's all fine, but you will soon notice that R's help documentation is very technical and precise but not all that helpful for newcomers (who need the most help). To illustrate, open the help window for the function var().

    > ?var
    


    Here's what you might look for.

    • The Description section describes the function in general technical terms.
    • The Usage section tells you what arguments are required (these don't have defaults), what arguments have defaults, and what the defaults are, and whether additional arguments ("...") are allowed. Often a function comes in several variants, you will find them here.
    • The Arguments section provides detailed information . You should read it, especially regarding whether the arguments are single values, vectors, or other objects, and what effect missing arguments will have.
    • The Details section might provide common usage and context information. It might also not. Often functions have crucial information buried in an innocuous note here.
    • You really have to read and understand the Value section. It explains the output of the function (its returnvalue). The object a function returns could be a list, a matrix or something else (we'll discuss these data types in detail elsewhere.). The value could also be an object that has special methods defined e.g. for plotting it. In that case, the object is formally a "list", and its named "components" can be retrieved with the usual list syntax.

    If you look at the bottom of the help text, you will usually find examples of the function's usage; these sometimes make matters more clear than the terse and principled help-text above.

    What you often won't find:

    • Clear commented, examples that relate to the most frequent use cases.
    • Explanations why a particular function is done in a particular way (e.g. why the denominator is n-1 for sd() and var()).
    • Notes on common errors.
    • A (reasonably) exhaustive list of alternatives and related functions. There are usually some entries, but there is no guarantee that all alternatives are listed – especially if they are provided by an external package.


    Therefore, my first approach for R information is usually to Google for what interests me and this is often the quickest way to find working example code. R has a very large user base and it is becoming very rare that a reasonable question will not have a reasonable answer among the top three hits of a Google search. Also, as a result of a Google search, it may turn out that something can't be done (easily) – and you won't find things that can't be done in the help system at all. You may want to include "r language" in your search terms, although Google is usually pretty good at figuring out what kind of "r" you are looking for, especially if your query includes a few terms vaguely related to statistics or programming.

    • There is an active R-help mailing list to which you can post–or at least search the archives: your question probably has been asked and answered before. A number of SIGs (Special Interest Groups) exist for more specific discussions - e.g. for mac OS, geography, ecology etc. They are listed here.
    • Most of the good responses these days are on stack overflow, discussion seems to be shifting to there from the R mailing list. Information on statistics questions can often be found or obtained from the CrossValidated forum of stackexchange.
    • Rseek is a specialized Google search on R-related sites. Try "time series analysis" for an example.


    If you want a quick and constructive answer from the R mailing list or stackoverflow (or from me, in a course or workshop for that matter), you must do a bit of homework first. If you ask your question well, you will get incredibly insightful and helpful responses, but you need to help the helpers to help you:

    • Use the dput() function, perhaps combined with head() to create a small, reproducible dataset with which your problem can be reproduced or your question illustrated. Keep this as small as possible. Post that. Don't post screenshots!
    • Post minimal code that reproduces the problem with the data you have supplied. Together the code and data have to form an MWE – a minimal working example. People love to play with your code and get it to work, but they hate having to copy, paste, reformat or otherwise edit someone's stuff just so they can answer their question.
    • Don't waste too much time on explaining what you did (since that didn't work) - just enough to help your readers understand that you did indeed invest some effort in trying to solve the problem yourself. Spend your time to explain clearly what you want to achieve. Focus on the desired result - not on how to fix your algorithm; your algorithm may be the wrong mental model in the first place.
    • Don't post in HTML, be sure to post in plain text only.


    Task:

    BTW: the same principles apply to questions you post on the course mailing list.


     

    Self-evaluation

    Question 1

    Is the apropos() command case-sensitive?

    Answer ...

    Try it out:

    apropos("^med")
    apropos("^MED")
    


     

    Further reading, links and resources

    Notes


     


    About ...
     
    Author:

    Boris Steipe <boris.steipe@utoronto.ca>

    Created:

    2017-08-05

    Modified:

    2020-09-15

    Version:

    1.1

    Version history:

    • 1.1 Maintenance, and removed GeSHi calls
    • 1.0.1 Maintenance
    • 1.0 Completed to first live version
    • 0.1 Material collected from previous tutorial

    CreativeCommonsBy.png This copyrighted material is licensed under a Creative Commons Attribution 4.0 International License. Follow the link to learn more.