lifecycle::badge("experimental")
Inserts relevant expect_*
tests based
on the evaluation of the selected code.
Example: If the selected code is the name of a data.frame
object,
it will create an expect_equal
test for each column,
along with a test of the column names.
Currently supports side effects (error
, warning
s, message
s),
data.frame
s, and vector
s.
List columns in data.frame
s (like nested tibble
s) are currently skipped.
See `Details`
for how to set a key command.
insertExpectationsAddin(
selection = NULL,
insert = TRUE,
indentation = 0,
copy_env = FALSE
)insertExpectationsCopyEnvAddin(
selection = NULL,
insert = TRUE,
indentation = 0,
copy_env = TRUE
)
Inserts testthat::expect_*
unit tests for the selected code.
Returns NULL
invisibly.
String of code. (Character)
E.g. "stop('This gives an expect_error test')"
.
N.B. Mainly intended for testing the addin programmatically.
Whether to insert the expectations via
rstudioapi::insertText()
or return them. (Logical)
N.B. Mainly intended for testing the addin programmatically.
Indentation of the selection. (Numeric)
N.B. Mainly intended for testing the addin programmatically.
Whether to work in a deep copy of the environment. (Logical)
Side effects will be captured in copies of the copy, why two copies of the environment will exist at the same time.
Disabled by default to save memory but is often preferable to enable, e.g. when the function changes non-local variables.
Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk
Parses and evaluates the selected code string
within the parent environment (or a deep copy thereof).
Depending on the output, it creates a set of unit tests
(like expect_equal(data[["column"]], c(1,2,3))
),
and inserts them instead of the selection.
After installing the package. Go to:
Tools >> Addins >> Browse Addins >> Keyboard Shortcuts
.
Find "Insert Expectations"
and press its field under Shortcut
.
Press desired key command, e.g. Alt+E
.
Press Apply
.
Press Execute
.
Other expectation generators:
gxs_function()
,
gxs_selection()
,
initializeGXSFunctionAddin()
Other addins:
assertCollectionAddin()
,
dputSelectedAddin()
,
initializeGXSFunctionAddin()
,
initializeTestthatAddin()
,
navigateTestFileAddin()
,
wrapStringAddin()