default_undesirable_functions: Default undesirable functions and operators

all_undesirable_functionsR Documentation

Default undesirable functions and operators

Description

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

Format

A named list of character strings.

Details

The following functions are sometimes regarded as undesirable:

  • .libPaths() As an alternative, use withr::with_libpaths() for a temporary change instead of permanently modifying the library location.

  • attach() As an alternative, use roxygen2's @importFrom statement in packages, or :: in scripts. attach() modifies the global search path.

  • browser() As an alternative, remove this likely leftover from debugging. It pauses execution when run.

  • debug() As an alternative, remove this likely leftover from debugging. It traps a function and causes execution to pause when that function is run.

  • debugcall() As an alternative, remove this likely leftover from debugging. It traps a function and causes execution to pause when that function is run.

  • debugonce() As an alternative, remove this likely leftover from debugging. It traps a function and causes execution to pause when that function is run.

  • detach() As an alternative, avoid modifying the global search path. Detaching environments from the search path is rarely necessary in production code.

  • library() As an alternative, use roxygen2's @importFrom statement in packages and :: in scripts, instead of modifying the global search path.

  • mapply() As an alternative, use Map() to guarantee a list is returned and simplify accordingly.

  • options() As an alternative, use withr::with_options() for a temporary change instead of permanently modifying the session options.

  • par() As an alternative, use withr::with_par() for a temporary change instead of permanently modifying the graphics device parameters.

  • require() As an alternative, use roxygen2's @importFrom statement in packages and library() or :: in scripts, instead of modifying the global search path.

  • sapply() As an alternative, use vapply() with an appropriate FUN.VALUE= argument to obtain type-stable simplification.

  • setwd() As an alternative, use withr::with_dir() for a temporary change instead of modifying the global working directory.

  • sink() As an alternative, use withr::with_sink() for a temporary redirection instead of permanently redirecting output.

  • source() As an alternative, manage dependencies through packages. source() loads code into the global environment unless local = TRUE is used, which can cause hard-to-predict behavior.

  • structure() As an alternative, Use class<-, names<-, and attr<- to set attributes.

  • Sys.setenv() As an alternative, use withr::with_envvar() for a temporary change instead of permanently modifying global environment variables.

  • Sys.setlocale() As an alternative, use withr::with_locale() for a temporary change instead of permanently modifying the session locale.

  • trace() As an alternative, remove this likely leftover from debugging. It traps a function and causes execution of arbitrary code when that function is run.

  • undebug() As an alternative, remove this likely leftover from debugging. It is only useful for interactive debugging with debug().

  • untrace() As an alternative, remove this likely leftover from debugging. It is only useful for interactive debugging with trace().

The following operators are sometimes regarded as undesirable:

  • <<-. It assigns 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 with assign(). Recall that you can create an environment at the desired scope with new.env().

  • :::. It 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.

  • <<-. It assigns 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 with assign(). Recall that you can create an environment at the desired scope with new.env().


r-lib/lintr documentation built on Dec. 20, 2024, 7:24 p.m.