Learn R Programming

DescToolsAddIns (version 1.11)

SelectVarDlg: Select Elements of a Set by Click

Description

SelectVarDlg() is a GUI utility, which brings up a dialog and lets the user select elements (either variables of a data.frame or levels of a factor) by point and click in a listbox. The list of selected items is written to the clipboard so that the code can afterwards easily be pasted in the source file.
This function is best used together with the package DescToolsAddIns, with which the functions can be assigned to a keystroke in RStudio.

Usage

SelectVarDlg(x, ...)

# S3 method for default SelectVarDlg(x, useIndex = FALSE, ...)

# S3 method for factor SelectVarDlg(x, ...)

# S3 method for data.frame SelectVarDlg(x, ...)

Value

A comma separated list with the selected values enquoted is returned invisibly as well as written to clipboard for easy inserting the text in an editor afterwards.

Arguments

x

the object containing the elements to be selected. x can be a data.frame, a factor or any other vector.

useIndex

defines, if the enquoted variablenames (default) or the index values should be returned.

...

further arguments to be passed to the default function.

Author

Andri Signorell <andri@signorell.net>

Details

When working with big data.frames with many variables it is often tedious to build subsets by typing the columnnames. Here is where the function comes in offering a "point and click" approach for selecting the interesting columns. When x is a data.frame the columnnames are listed, when x is a factor the according levels are listed and in all other cases the list is filled with the unique elements of x.

SelectVarDlg() checks for an option "selkey" for defining the selection keywords, defined as a list of this structure:

filethe keywords to be interpreted as a filename, defaults to c("fn","file","filename")
dirthe keywords to be interpreted as a directory name, defaults to c("path","dir")
colthe keywords to be interpreted as a color, defaults to c("col","color")
pchthe keywords to be interpreted as a point character, defaults to c("pch")

It can be set with


  options(selkey = list(file=c("fn","file","filename"),
                        dir=c("path","dir", "dirname"),
                        col=c("color", "col"),
                        pch=c("pch"))
  )              

See Also

Examples

Run this code
if (FALSE) {
SelectVarDlg(x = d.pizza$driver)
SelectVarDlg(x = d.pizza, useIndex=TRUE)

SelectVarDlg(d.pizza$driver)

x <- replicate(10, paste(sample(LETTERS, 5, replace = TRUE), collapse=""))
SelectVarDlg(x)
}

Run the code above in your browser using DataLab