The typical use of reprompt
is with one argument, as in
reprompt(infile = "./Rdpack/man/reprompt.Rd")
reprompt(reprompt)
reprompt("reprompt")
reprompt
updates the requested documentation and writes the new
Rd file in the current working directory. When argument infile
is used, the descriptions of all objects described in the input file
are updated. When an object or its name is given, reprompt
looks first for installed documentation and processes it in the same
way as in the case of infile
. If there is no documentation for
the object, reprompt
creates a skeleton Rd file similar to the
one produced by the base R functions from the prompt
family (if
final = TRUE
, the default, it modifies the output of
prompt()
, so that the package can be built).
To document a function, say myfun
, in an existing Rd file, just
add myfun()
to the usage section in the file and call
reprompt()
on that file. Put quotes around the function name if
it is non-syntactic. For replacement functions (functions with names
ending in <-
) reprompt()
will insert the proper usage
statement. For example, if the signature of xxx<-
is (x,
..., value)
then both, "xxx<-"()
and xxx() <- value
will be replaced by xxx(x, ...) <- value
.
For S4 methods and classes the argument "package" is often needed to
restrict the output to methods defined in the package of interest.
reprompt("myfun-methods") reprompt("[<--methods", package = "mypackage")
reprompt("[<-", type = "methods", package = "mypackage") # same
reprompt("myclass", type = "class", package = "mypackage")
reprompt("myclass-class", package = "mypackage") # same
Without the "package" argument the reprompt for "[<-"
would give
all methods defined by loaded packages at the time of the call.
Currently reprompt
functionality is not implemented for topic
"package" but if object
has the form "name-package" (or the
equivalent with argument topic
) and there is no documentation
for package?name
, reprompt
calls
promptPackageSexpr
to create the required shell.
Note that the shell produced by promptPackageSexpr
does not
need `reprompting' since the automatically generated information is
included by \Sexpr
's, not literal strings.
Below are the details.
Typically, only one of object
, infile
, and Rdtext
is supplied. Warning messages are issued if this is not the case.
The object must have been made available by the time when
reprompt()
is issued. If the object is in a package this is
typically achieved by a library()
command.
object
may be a function or a name, as accepted by the ?
operator. If it has the form "name-class" and "name-methods" a
documentation shell for class "name" or the methods for generic function
"name" will be examined/created. Alternatively, argument type
may be set to "class" or "methods" to achieve the same effect.
infile
specifies a documentation file to be updated. If it
contains the documentation for one or more functions, reprompt
examines their usage statements and updates them if they have
changed. It also adds arguments to the "arguments" section if not all
arguments in the usage statements have entries there. If infile
describes the methods of a function or a class, the checks made are as
appropriate for them. For example, new methods and/or slots are added
to the corresponding sections.
It is all too easy in interactive use to forget to name the
infile
argument, compare
reprompt("./man/reprompt.Rd")
vs.
reprompt(infile = "./man/reprompt.Rd")
).
A convenience feature is that if infile
is missing
and object
is a character string ending in ".Rd" and containing
a forward slash (i.e. it looks like Rd file in a directory), then it
is taken to be infile
.
Rdtext
is similar to infile
but the Rd content is taken
from a character vector.
If Rd content is supplied by infile
or Rdtext
,
reprompt
uses it as a basis for comparison. Otherwise it tries
to find installed documentation for the object or topic requested.
If that fails, it resorts to one of the promptXXX
functions to
generate a documentation shell. If that also fails, the requested
object or topic does not exist.
If the above succeeds, the function examines the current definition of
the requested object(s), methods, or class and amends the
documentation with any additional items it finds.
For Rd objects describing one or more functions, the usage expressions
are checked and replaced, if they have changed. Arguments appearing in
one or more usage expressions and missing from section "Arguments" are
amended to it with content "Describe ..." and a message is
printed. Arguments no longer in the usage statements are NOT removed
but a message is issued to alert the user. Alias sections are inserted
for any functions with "usage" but without "alias" section.
If filename
is a character string, it is used as is, so any
path should be included in the string. Argument filename
usuallly is omitted since the automatically generated file name is
suitable in most cases. Exceptions are functions with non-standard
names (such as replacement functions whose names end in "<-"
)
for which the generated file names may not be acceptable on some
operating systems.
If filename
is missing or NULL
, a suitable name is
generated as follows. If infile
is supplied, filename
is
set to a file with the same name in the current working directory
(i.e. any path information in infile
is dropped). Otherwise,
filename
is obtained by appending the name tag of the Rd object
with ".Rd"
.
If filename
is TRUE
, it is set to infile
or, if
infile
is missing or NULL
, a suitable name is generated
as above. This can be used to change infile
in place.
If filename
is FALSE
, the Rd text is returned as a
character vector and not written to a file.
If edit
is TRUE
, the reprompted file is opened in an
editor, see also ereprompt
(`e' for `edit') which is
like reprompt
but has as default edit = TRUE
and some
other related settings.
file.edit()
is used to call the editor. Which editor is opened
depends on the OS and on the user configuration. RStudio users will
probably prefer the 'Reprompt' add-in or the underlying function
RStudio_reprompt
. Emacs users would normally have set
up emacsclient
as their editor and this is automatically done
by EMACS/ESS (even on Windows).
If argument sec_copy
is TRUE
(the default),
reprompt
will, effectively, copy the contents of (some)
unchanged sections, thus ensuring that they are exactly the same as in
the original. This needs additional work, since parsing an Rd file
and then exporting the created Rd object to an Rd file does not
necessarilly produce an identical Rd file (some escape sequences may
be changed in the process, for example). Even though the new version
should be functionally equivalent to the original, such changes are
usually not desirable. For example, if such changes creep into the
Details section (which reprompt
never changes) the user may be
annoyed or worried.