decr: Decrease Value In Place

Description Usage Arguments Value Examples

View source: R/incr.R

Description

Decrease the value of an object on the search path. Equivalent to x-- or x -= by in other languages. See incr for details on implementation.

Usage

1
decr(x, by = 1)

Arguments

x

object to be decreased; can be a symbol, character, or extraction language object.

by

value to decrease x by; defaults to 1.

Value

the value of x decreased by by, invisibly

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
z <- 1:10

incr(z)
identical(z, 2:11)       # TRUE

incr(z[1:3], by=2)
identical(z[1:3], 4:6)   # TRUE

l <- list(a = 1, b = 2)
decr(l$a)
l$a == 0   # TRUE

decr(l$b, by = 4)
l$b == -2  # TRUE

refer documentation built on Nov. 8, 2021, 5:08 p.m.