Learn R Programming

xpectr (version 0.4.4)

dputSelectedAddin: Replaces selected code with its dput() output

Description

lifecycle::badge("experimental")

RStudio Addin: Runs dput() on the selected code and inserts it instead of the selection.

See `Details` for how to set a key command.

Usage

dputSelectedAddin(selection = NULL, insert = TRUE, indentation = 0)

Value

Inserts the output of running dput() on the selected code.

Does not return anything.

Arguments

selection

String of code. (Character)

E.g. "stop('This gives an expect_error test')".

N.B. Mainly intended for testing the addin programmatically.

insert

Whether to insert the expectations via rstudioapi::insertText() or return them. (Logical)

N.B. Mainly intended for testing the addin programmatically.

indentation

Indentation of the selection. (Numeric)

N.B. Mainly intended for testing the addin programmatically.

Author

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

Details

How

Parses and evaluates the selected code string, applies dput() and inserts the output instead of the selection.

How to set up a key command in RStudio

After installing the package. Go to:

Tools >> Addins >> Browse Addins >> Keyboard Shortcuts.

Find "dput() Selected" and press its field under Shortcut.

Press desired key command, e.g. Alt+D.

Press Apply.

Press Execute.

See Also

Other addins: assertCollectionAddin(), initializeGXSFunctionAddin(), initializeTestthatAddin(), insertExpectationsAddin(), navigateTestFileAddin(), wrapStringAddin()