This function copies handy utility functions to a new script in a specified location. Currently, the script contains the following utility functions:
.assertScalar()
- convenience function to check the validity
of scalar variables.
.assertVector()
- convenience function to check the validity
of vector variables.
.assertPackagesAvailable()
- convenience function to check if
packages are available, and suggest how to install them otherwise.
.message()
- a drop-in replacement for message() that only
prints a message if a variable named verbose is available in the
calling environment and is set to TRUE.
In addition to copying the files, the function also runs
usethis::use_package("cli")
to add the cli
package to the
Imports
of your package.
addUtilsFunctions(outFile = "R/utils.R", copyTests = TRUE)
Character scalar, giving the path to which the script should be copied. The path is relative to the root of the active project. If a file with this name already exists, the function will ask for confirmation before overwriting it.
Logical scalar, defining whether to copy unit tests for
the utility functions to tests/testthat/test-<name>.R
,
where <name>
is the base name of outFile
. If the
target package is not yet set up to use testthat
, the function
will also run usethis::use_testthat()
to generate the required
folder structure and add testthat
to the list of suggested
package in the DESCRIPTION file.