Interactive application of selected function a list of objects.

Share:

Description

This function was originally written to do the same as the unix rm -i command. The user supplies a list of items and the name of a function which is optionally applied to each item in turn.

Usage

1
askrm(items = ls(parent.frame()), fn = "rm", ask = TRUE)

Arguments

items

A character vector of names of the objects to be acted upon (such as ls() returns). The default is all objects in the parent working environment.

fn

The name of the function to be applied, supplied as a character string. Possible future upgrades may allow function names to be entered without quotes.

ask

If TRUE , the user is prompted for "y/n" before performing the function on each object in the list. Be cautious about setting to FALSE for obvious reasons. Note that the only accepted positive response is exactly "y" so, e.g. "yes" will be treated as "no."

Value

A list with three elements.

func

Echo back the input function, for archival reference.

selected

All the items from the input list to which the function fn was applied. In the default case, these are the items deleted from the environment.

evout

A list of the value(s) returned by the function, if any, each time it was executed.

Author(s)

Carl Witthoft, carl@witthoft.com

See Also

When interactive prompting is not desired, sapply or its brethren are recommended.

Examples

1
2
3
4
5
6
7
8
9
# get rid of junky objects left around from testing
foo<-1
afoo<-c(foo,2)
foob <- c('a','b','d')
askrm(ls(pattern="foo") )

x<- rep(1,10)
y<- runif(10)
askrm(c('x','y'),'sd',ask=FALSE)