rcompletion {rcompletion} | R Documentation |
This package provides pseudo-intelligent TAB completion for a readline enabled instance of R when it is run from a terminal (or more specifically, an interface which uses readline to accept user input). It has no effect on the various GUI interfaces to R, including ESS and the standard Windows interface.
This package does not define any functions. It is of interest solely
for the wonderful things that start to happen when you press the TAB
key inside R after loading this package. Strictly speaking, this
package only provides a binding to the GNU Readline library, and uses
the rcompgen
package to generate potential completions. That
package exports a few functions (notably
rc.settings
), providing a simple
control and query mechanism, that are also available when the
rcompletion
package is attached. The help page for those
functions should be consulted for details (some of which this page
refers to in passing).
There are several types of completion, some of which can be disabled
using rc.settings
. The most basic level, which can not be
turned off once the package is loaded, provides completion on names
visible on the search path, along with a few special keywords
(e.g. TRUE
). This type of completion is not attempted if the
partial ‘word’ (a.k.a. token) being completed is empty (since
there would be too many completions). The more advanced types of
completion are briefly described below (and in more detail in the help
page for rcompgen
).
$
and @
:ops
setting is turned on, completion after
$
and @
is attempted.
ns
setting is turned on, completion inside
namespaces is attempted when a token is preceded by the ::
or :::
operators. Additionally, the basic completion
mechanism is extended to include attached namespaces, or more
precisely, foopkg::
becomes a valid completion of
foo
if the return value of search()
includes
the string "package:foopkg"
.
args
setting is turned on, completion on function
arguments is attempted whenever deemed appropriate. The algorithm
used is imperfect for generic functions, but hopefully still
useful.
This file assumes throughout that the TAB key is bound to the default
readline complete
function, but this can be modified through an
inputrc
file. The details are dicussed in the Bash reference
manual, under “Readline Initialization” (under “Command
Line Editing”) and the subsequent sections. Conditional constructs
can use the application name "RCustomCompletion"
for settings
affecting this package.
Warning: No attention is paid to locale settings. This is for the most part not a problem, but it does mean that the computed start and end positions of the token in the line buffer may be wrong when multibyte characters are used, which may in turn lead to various kinds of misbehaviour.
Deepayan Sarkar, deepayan.sarkar@r-project.org
GNU Readline manual, http://cnswww.cns.cwru.edu/php/chet/readline/readline.html
GNU Bash manual, http://www.gnu.org/software/bash/manual/bashref.html
rcompgen
for further details and utilities
that allow customization.
## Not run: ## sample ~/.Rprofile file to load rcompletion at startup local({ if (interactive()) { library(rcompgen) library(rcompletion) ## recognizes installed packages rc.settings(ipck = TRUE) ## creates cache, so that subsequent calls are faster invisible(utils::installed.packages()) } }) ## End(Not run)