Expected Preparations:
|
|||||||
|
|||||||
Keywords: The internal R help system; other help resources. | |||||||
|
|||||||
Objectives:
|
Outcomes:
After working through this unit you …
|
||||||
|
|||||||
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. |
|||||||
|
|||||||
Evaluation: NA: This unit is not evaluated for course marks. |
This unit discusses the available Help resources for R programming and develops effective strategies for solving problems.
Task…
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:
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:
sd()
and var()
).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.
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:
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!Task…
Read “How to write a reproducible example” and “How to make a great R reproducible example”.
BTW: the same principles apply to questions you post on the course Forum.
Question 1
Is the apropos()
command case-sensitive?
If in doubt, ask! If anything about this contents is not clear to you, do not proceed but ask for clarification. If you have ideas about how to make this material better, let’s hear them. We are aiming to compile a list of FAQs for all learning units, and your contributions will count towards your participation marks.
Improve this page! If you have questions or comments, please post them on the Quercus Discussion board with a subject line that includes the name of the unit.
[END]