SelectVarDlg {DescToolsAddIns}R Documentation

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, ...)

## Default S3 method:
SelectVarDlg(x, useIndex = FALSE, ...)

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

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

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.

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:

file the keywords to be interpreted as a filename, defaults to c("fn","file","filename")
dir the keywords to be interpreted as a directory name, defaults to c("path","dir")
col the keywords to be interpreted as a color, defaults to c("col","color")
pch the 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"))
  )              

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.

Author(s)

Andri Signorell <andri@signorell.net>

See Also

select.list

Examples

## Not run: 
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)

## End(Not run)

[Package DescToolsAddIns version 1.10 Index]