wrapStringAddin: Wraps the selection with paste0

View source: R/wrap_string_addin.R

wrapStringAddinR Documentation

Wraps the selection with paste0

Description

\Sexpr[results=rd, stage=render]{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
)

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.

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.

Value

Inserts the following (with newlines and correct indentation):

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

Returns NULL invisibly.

Author(s)

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

See Also

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


xpectr documentation built on Nov. 18, 2022, 5:10 p.m.