DescToolsAddIns: Some Functions to be Used as Shortcuts in 'RStudio'

RStudio AddInsR Documentation

Some Functions to be Used as Shortcuts in 'RStudio'

Description

A simply great new feature in RStudio is the option to define add-ins and bind shortcuts to them. This package includes add-ins for some of the most frequently used functions in a data scientist's (at least mine) daily work (like str(), example(), plot(), head(), view(), Desc()).
Most of these functions use the current selection in RStudios source panel and send the specific command to the console where it is executed immediately. Assigning shortcuts to these add-ins saves you tons of keystrokes and brings a breeze of liberating and brake-releasing GUI-interaction into your R-life.

Usage

NewObject()
FileOpen()
FileBrowserOpen()
FileImport()
FileSaveAs()
GetExcelRange(env = .GlobalEnv, header = FALSE, echo = TRUE)
GetExcelRangeH(env = .GlobalEnv)
GetExcelTable(env = .GlobalEnv)
XLView()
IntView()

Edit()
FlushToSource()
Select()

Str()
Str1()
Abstract()
Head()
Some()
Summary()
Cat()
Desc()
Example()
Info()
Unclass()

Plot()
PlotD()
SetArrow()
InspectPnt()

BuildModel()

Enquote()
EnquoteS()
RemoveDuplicates()
SortAsc()
SortDesc()
Shuffle()
EvalEnquote()
FlipBackSlash()

Arguments

env

Environment for GetExcelRange to write the data. GlobalEnv is default.

header

logical determining if the import from XL should use a header or not

echo

should the function return an echo

Details

The following add-ins are available:

  • NewObject:
    starts the good old internal editor and allows to enter values. In dependence of the initial selection in the code panel different objects will be returned. If the selection was m the code for a matrix will be created, if the selection is d then the code for a data.frame will be returned and a c will be interpreted as vector. Default is m. Note that column names can be defined within the editor, but not rownames (don't ask me why ...).

  • FileOpen:
    get the path of a file to open and insert in code. (See also: Select())

  • FileBrowserOpen:
    get a selected path and opens the systems filebrowser with the according directory.

  • FileImport:
    display the import file dialog for importing SAS, SPSS, Stata, Systat and MiniTab files. (See FileImportDlg())

  • FileSaveAs:
    display a file dialog, get the desired path and filename and save the selected object in the given place. Several file types are supported csv/xlsx for data.frames, text/binary for other objects.

  • GetXLRange:
    run DescTools command XLGetRange() by taking the current selection as name for the imported data and replace the current selection by the used code.

  • GetXLTable:
    run DescTools command XLGetRange() by taking the current 3-fold selection as data matrix, rownames and columnnames and replace the current selection by the structure code.

  • XLView:
    view selected object in MS-Excel, which makes sense for data.frames.

  • IntView:
    view selected object with internal viewer (here again: only data.frames)

  • Edit:
    run R-command fix() on the current selection. This is nice for editing data frames interactively.

  • FlushToSource:
    run dput on the current selection and replace the selection with the result.

  • Select:
    select or pick things interactively. This function as well evaluates the current selection. If the selection corresponds to pch a dialog for selecting point characters will be displayed. If it's col the ColPicker() dialog will be displayed. If it's any of path, fn, file the FileOpen() dialog will be displayed. In all other case the SelectVarDlg() on the current selection will be run. This can be used to select variablenames of a data.frame by mouse click or the levels of a factor (all depending on the class of the selected object). The variable names will be returned as string, enquoted and separated by a comma.

  • Str, Str1:
    run DescTools command Str() on the current selection, Str1() shows only the first level ;

  • Abstract:
    run DescTools command Abstract() (a less technical description than str(), meant for using with data.frames) on the current selection

  • Head:
    run R-command head() on the current selection

  • Some:
    run DescTools command Some() on the current selection

  • Summary:
    run R-command summary() on the current selection

  • Cat:
    run R-command cat(..., sep="\n") on the current selection

  • Desc:
    run DescTools command Desc() on the current selection

  • Example:
    run R-command example() on the current selection

  • Info:
    print object properties of the currently selected object

  • Unclass:
    run R-command unclass() on the current selection

  • Plot:
    run plot() on the current selection

  • PlotD:
    run plot(Desc()) on the current selection

  • SetArrow:
    place an arrow in a plot and insert code into source file

  • InspectPnt:
    Lauch IdentifyA(... , poly=TRUE) with the current selection as argument and returns the selected points on the plot.

  • BuildModel:
    display dialog for building up a model formula interactively by point and click. (See ModelDlg())

  • Enquote, EnquoteS:
    split the selected text in the source panel using line breaks as separators, enquote the sections using either double or single quotation marks, and paste them separated by comma.

  • RemoveDuplicates:
    remove all the duplicates (by row) of the selected text.

  • SortAsc, SortDesc, Shuffle:
    sorts the selected text by row in ascending, descending, resp. random order.

  • EvalEnquote:
    evaluates the selection before enquoting the parts and paste them separated by comma. This can be used to enquote factors.

  • FlipBackSlash:
    Handling backslashes in pathnames can be really annoying on Windows. This function replaces all backslashes in the selected text by simple slashes. In the first step all backlashes are replaced by slashes, in further applications of the function, flipflops are performed between slashes and backslashes. The option ReplaceDoubleSlash controls whether double slashes should be replaced by simple ones.
    It's cool to set this command to the keyboard shortcut: Ctrl+Shift+/

As soon as the package is loaded once, the AddIns will be listed in RStudios AddIns listbox:

AddIns listbox

The keyboard shortcuts can then be assigned by clicking on the menu Tools | Modify Keyboard Shortcuts... and scroll down to the Addin scope:

Keyboard Shortcuts

Author(s)

Andri Signorell <andri@signorell.net>

Examples

if (interactive()){
  Str()
}

DescToolsAddIns documentation built on May 9, 2022, 5:07 p.m.