[R] Generating help files for a function

Duncan Murdoch murdoch.duncan at gmail.com
Sat Dec 16 18:08:13 CET 2017


On 16/12/2017 10:15 AM, Berwin A Turlach wrote:
> G'day Erin,
> 
> On Sat, 16 Dec 2017 08:00:38 -0600
> Erin Hodgess <erinm.hodgess at gmail.com> wrote:
> 
>> I'm in the process of writing a package, and I'm using the lovely "R
>> Package" book as a guideline.
>>
>> However, in the midst of my work,  I discovered that I had omitted a
>> function and am now putting in it the package.  Not a problem.  But
>> the problem is the help file.  What is the best way to generate a
>> help file "after the fact" like that, please?
> 
> It depends on how you decided to write the documentation.  If you
> follow the "R Package" guidelines and use roxygen2, just add the
> comments for the documentation at the beginning of the file and follow
> the procedure outline in "R Packages" book.
> 
> If you are writing the documentation separate, more like the "Writing R
> Extensions" manual, then (1) start R, (2) source the file in which the
> function is so that is is in your workspace, (3) say "prompt(foo)" if
> the function's name is foo and (4) copy the resulting foo.Rd into
> the /man directory of your package.

I'm in the latter camp, but my workflow is slightly different from Berwin's:

After writing a new function and putting it into the package:

1. install the package, and attach it (using library() or require()).
2. use setwd() to change to the man directory.
3. use prompt() to create the skeleton help page.

After that, you edit that new .Rd file, and build the package again.

The first two steps are particularly easy in RStudio:  for 1, just click 
"Install and restart" in the build pane, and for 2, navigate in the file 
pane to the man directory, and choose "Set as working directory" from 
the "More" tab.

Duncan Murdoch



More information about the R-help mailing list