Lists of function names and operators for undesirable_function_linter()
and undesirable_operator_linter()
.
There is a list for the default elements and another that contains all available elements.
Use modify_defaults()
to produce a custom list.
Usage
all_undesirable_functions
default_undesirable_functions
all_undesirable_operators
default_undesirable_operators
Details
The following functions are sometimes regarded as undesirable:
attach()
modifies the global search path. Use roxygen2's @importFrom statement in packages, or::
in scripts.browser()
pauses execution when run and is likely a leftover from debugging. It should be removed.debug()
traps a function and causes execution to pause when that function is run. It should be removed.debugcall()
works similarly todebug()
, causing execution to pause. It should be removed.debugonce()
is only useful for interactive debugging. It should be removed.detach()
modifies the global search path. Detaching environments from the search path is rarely necessary in production code.ifelse()
isn't type stable. Use anif
/else
block for scalar logic, or usedplyr::if_else()
/data.table::fifelse()
for type stable vectorized logic..libPaths()
permanently modifies the library location. Usewithr::with_libpaths()
for a temporary change instead.library()
modifies the global search path. Use roxygen2's @importFrom statement in packages, or::
in scripts.loadNamespace()
doesn't provide an easy way to signal failures. Use the return value ofrequireNamespace()
instead.mapply()
isn't type stable. UseMap()
to guarantee a list is returned and simplify accordingly.options()
permanently modifies the session options. Usewithr::with_options()
for a temporary change instead.par()
permanently modifies the graphics device parameters. Usewithr::with_par()
for a temporary change instead.require()
modifies the global search path. Use roxygen2's @importFrom statement in packages, andlibrary()
or::
in scripts.sapply()
isn't type stable. Usevapply()
with an appropriateFUN.VALUE=
argument to obtain type stable simplification.setwd()
modifies the global working directory. Usewithr::with_dir()
for a temporary change instead.sink()
permanently redirects output. Usewithr::with_sink()
for a temporary redirection instead.source()
loads code into the global environment unlesslocal = TRUE
is used, which can cause unexpected behavior.substring()
should be replaced bysubstr()
with appropriatestop=
value.Sys.setenv()
permanently modifies the global environment variables. Usewithr::with_envvar()
for a temporary change instead.Sys.setlocale()
permanently modifies the session locale. Usewithr::with_locale()
for a temporary change instead.trace()
traps a function and causes execution of arbitrary code when that function is run. It should be removed.undebug()
is only useful for interactive debugging withdebug()
. It should be removed.untrace()
is only useful for interactive debugging withtrace()
. It should be removed.
The following operators are sometimes regarded as undesirable:
:::
accesses non-exported functions inside packages. Code relying on these is likely to break in future versions of the package because the functions are not part of the public interface and may be changed or removed by the maintainers without notice. Use public functions via::
instead.<<-
and->>
assign outside the current environment in a way that can be hard to reason about. Prefer fully-encapsulated functions wherever possible, or, if necessary, assign to a specific environment withassign()
. Recall that you can create an environment at the desired scope withnew.env()
.