Package 'icecream'

Title: Print Debugging Made Sweeter
Description: Provides user-friendly and configurable print debugging via a single function, ic(). Wrap an expression in ic() to print the expression, its value and (where available) its source location. Debugging output can be toggled globally without modifying code.
Authors: Lewin Appleton-Fox [aut, cre], Dominik Rafacz [aut] , Ben Stiles [ctb]
Maintainer: Lewin Appleton-Fox <[email protected]>
License: MIT + file LICENSE
Version: 0.2.2
Built: 2024-11-14 02:42:27 UTC
Source: https://github.com/lewinfox/icecream

Help Index


Enable or disable ic()

Description

These functions enable or disable the ic() function. While disabled ic() will do nothing except evaluate and return its input.

Usage

ic_enable()

ic_disable()

Details

These are just convenience wrappers for options(icecream.enabled = TRUE/FALSE) used to align the API with the Python version.

Value

Returns the old value of the option, invisibly.

Functions

  • ic_enable(): Enable ic().

  • ic_disable(): Disable ic().


User-friendly debug statements

Description

User-friendly debug statements

Usage

ic(x)

Arguments

x

An expression, or nothing

Value

If x is an expression, returns the result of evaluating x. If x is missing nothing is returned.

Examples

f <- function(x) x < 0

ic(f(1))

ic(f(-1))

Temporarily enable or disable ic()

Description

These functions let you evaluate an expression with either ic() enabled or disabled without affecting if ic() is enabled globally.

Usage

with_ic_enable(expr)

with_ic_disable(expr)

Arguments

expr

An expression containing the ic() function.

Value

Returns the result of evaluating the expression.

Functions

  • with_ic_enable(): evaluates the expression with ic() enabled.

  • with_ic_disable(): evaluates the expression with ic() disabled.

Examples

ic_enable()

fun <- function(x) {
  ic(x * 100)
}

fun(2)

with_ic_disable(fun(2))

fun(4)

ic_disable()

fun(1)

with_ic_enable(fun(1))