MODULE 2.6 Help in R

baseR-V2016.2 - Data Management and Manipulation using R

Tested on R versions 3.0.X through 3.3.1
Last update: 15 August 2016


Objective:

  • Obtain a working knowledge of Help in R

Let’s begin by calling for …



Help!


R is written by technically, mathematically, statistically, and computationally savvy people. They can be snarky towards those lacking such (social??) skills. You - an end-user - are expected to understand:

  • Terms like “deviance” and “residual,”
  • Operations like “loop” and “function” and “Boolean,”
  • Statistical verbiage like “GAM” and “GLM” and “link function,”
  • or when a “quasi-” vs. “maximum likelihood” process is best used, and
  • Much, much more …

R Help will not help you overcome these knowledge limitations, and they must be part of your background before you can use R to achieve your analytical goals. Effective use of R Help requires logical, methodical and educated searches on key words and phrases

Most important, you are expected to have done diligent web-based searching on a topic before you query listerves for R.


Where to find Help!


From within Plain Vanilla R, both:

  • toolbar => Help => FAQ on R, and
  • Help => FAQ on R for Windows

provide excellent browser-based FAQs, as does …

  • Help => Manuals

RStudio has a built-in Help tab in lower right panel.

Numerous listserves and blogs are found on web where you can post questions to the R User Community. However, be advised that uninformed questions to listserves and blogs can result in snarky answers, especially if you have not done basic web searching and simple code experimentation yourself.

The help() call:
Basic Help! in R starts with the help() call, and its analogues ? and ??. Both help(FunctionName) and ?FunctionName return a browser-based description of how the function operates. These descriptions are standardized across all R functions. Running the code will open browser-based R help on the ls() call.

When a function name is known, use the ? or help() calls.

# basic help in package or function when name is known
  help(ls)  # basic help
## starting httpd help server ...
##  done
  ?ls  # basic help

The help.search() call:
Often you merely have a key-word or phrase to work with, such a desire to run a “t-test” or “regression.” Here, use the help.search(KeyWordPhrase) or ??KeyWordPhrase. Both are identical and return to your browser a list of packages meeting the conditions of the KeyWordPhrase. You can then peruse the list until you find the one of interest.

It is important, however, to be as precise as possible. A search for the “t-test”, for example, returns a huge list whereas refining the search phrase to the “student t-test” returns only a single package.

# alternatives using key words - note pop-up windows
  help.search("t test")  # search help for keyword t test
  ??"student t-test"  # more refined t-test search

Try some searches based on statistical tests you know about so you can get a better feel for important phrases and terms to use when searching for R packages and functions.

The example() call:
Another useful Help! call is example(). This call returns example code associated with a named function.

# example code of how function is used
  example(ls)  # example code for a function
## 
## ls> .Ob <- 1
## 
## ls> ls(pattern = "O")
## character(0)
## 
## ls> ls(pattern= "O", all.names = TRUE)    # also shows ".[foo]"
## [1] ".Ob"
## 
## ls> # shows an empty list because inside myfunc no variables are defined
## ls> myfunc <- function() {ls()}
## 
## ls> myfunc()
## character(0)
## 
## ls> # define a local variable inside myfunc
## ls> myfunc <- function() {y <- 1; ls()}
## 
## ls> myfunc()                # shows "y"
## [1] "y"

R vignettes:
One last approach to help is the R vignettes. These are more user-friendly versions of the documentation associated with a package, and typically contain better “real-world” examples of how the package and its associated functions work. The call browseVignettes() opens a browser-based of links to which packages have vignettes. I find it useful to open this browser page and then use the browser “Find” button and search for key-word and phrases relevant to my work. Open the link and try some searches.

# finding vignettes
  browseVignettes()  # opens in browser

Other options for Help! in R


Web-based help for R is at unimaginable levels now. The somewhat cryptic R Help per se can be bypassed with logical searches in engines like Google. For example, a Google search for “regression in r” returned ~59.7 million hits in 0.3 s. As a search for regression in R, it is clearly too broad-based a search phrase for actual utility.

More narrow searches, such a specifying a desire for “Poisson regression in r” still returned a huge number of hits (~0.4 million hits in 0.4 s), but clearly found some potential sites that could help you perform a Poisson regression using R. Clearly, more precise search phrasing returns more useful help for R. One last note: including “in r” at end, or “r” at start, of search, e.g., “data input in r”, “chi square test in r” will weed out those hits not related to R.


Exercise #3


Use R Help on these calls and answer queries below:

  • setwd() What is the argument to this function?
  • getwd() What is returned from this function?
  • save() What is the “list” mean for this function?
  • save.image() What does the function option “compress=T“ do?

From help(options) consider and implement 2-3 possible options for your R session

A Challenge Exercise !! Use any help source and determine how configure options in your R to automatically load a file of pathnames whenever R is loaded (Hint: search .Rprofile)


END MODULE 2.6


Printable Version