Learn R Programming

xpectr (version 0.4.4)

wrapStringAddin: Wraps the selection with paste0

Description

lifecycle::badge("experimental")

Splits the selection every n characters and inserts it in a paste0() call.

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

Usage

wrapStringAddin(
  selection = NULL,
  indentation = 0,
  every_n = NULL,
  tolerance = 10,
  insert = TRUE
)

Value

Inserts the following (with newlines and correct indentation):

paste0("first n chars", "next n chars")

Returns NULL invisibly.

Arguments

selection

String of code. (Character)

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

indentation

Indentation of the selection. (Numeric)

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

every_n

Number of characters per split.

If NULL, the following is used to calculate the string width:

max(min(80 - indentation, 70), 50)

N.B. Strings shorter than every_n + tolerance will not be wrapped.

tolerance

Tolerance. Number of characters.

We may prefer not to split a string that's only a few characters too long. Strings shorter than every_n + tolerance will not be wrapped.

insert

Whether to insert the wrapped text via rstudioapi::insertText() or return it. (Logical)

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

Author

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

Details

How to set up a key command in RStudio

After installing the package. Go to:

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

Find "Wrap String with paste0" and press its field under Shortcut.

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

Press Apply.

Press Execute.

See Also

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