mappy: Assign an alias to an R expression in the interactive...

Description Usage Arguments Details Value Examples

View source: R/mappy.R

Description

Assign an alias to an R expression in the interactive console.

This package provides the ability to create shortcuts for use in the interactive R console to prevent yourself from writing commonly used expressions multiple times.

Usage

1
2
3
4
mappy(..., envir = globalenv(), register = identical(envir, globalenv()))

unmappy(expression_names, envir = globalenv(), deregister = identical(envir,
  globalenv()))

Arguments

...

The named arguments will be translated to the aliases. See the accompanying examples.

envir

environment. The environment to bind the aliases in using makeActiveBinding. By default, the global environment.

register

logical. Whether or not to register the shortcut in the registry. By default, TRUE if envir is the global environment, and FALSE otherwise.

expression_names

character. The expressions to unmap.

deregister

logical. Whether or not to deregister the shortcut in the registry. By default, TRUE if envir is the global environment, and FALSE otherwise.

Details

For example, if you frequently find yourself typing some_annoyingly$long_expression, you can bind it to S by writing mappy(S = some_annoyingly$long_expression). Now, typing S in your interactive R console executes the expression in full each time. Note that mappy relies on the ~/.R/mappy file to make this work between sessions. If you wish to use a different file, set options(mappy.file = "/your/dir/file").

Mappy shortcuts do not apply outside of interactive R sessions (see interactive.

Value

the names of the bound shortcuts.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## Not run: 
  mappy(hi = cat("Hello world"))
  hi # Now, writing "hi" executes cat("Hello world")
  stopifnot(bindingIsActive("hi", globalenv()))
  unmappy("hi") # Now the shortcut is gone.

## End(Not run)

env <- new.env()
mappy(m = lm(Sepal.Width ~ Sepal.Length, data = iris)$model, envir = env)
# Now, env$m will refer to the lm model object. Note that since the
# expression will be re-computed each time, so will the model!
model <- env$m

robertzk/mappy documentation built on May 25, 2017, 6:31 a.m.