@@ -1204,12 +1204,13 @@ modify_in_place <- function(x, value = x){
12041204# '
12051205# ' This is a thin wrapper around [base::replace()] that allows `list`
12061206# ' and/or `values` to be functions that are evaluated on `x` to obtain
1207- # ' the replacement indices and values.
1207+ # ' the replacement indices and values. The assignment version replaces
1208+ # ' `x`.
12081209# '
12091210# ' `list` function is passed the whole vector `x` at once (not
12101211# ' elementwise) and any additional arguments to `replace()`, and must
12111212# ' return an indexing vector (numeric, logical, character,
1212- # ' etc.). `values` function is passed `x` after subsetting it by the
1213+ # ' etc.). `values`/`value` function is passed `x` after subsetting it by the
12131214# ' result of calling `list()`.
12141215# '
12151216# ' If passing named arguments, `x`, `list`, and `values` may cause a
@@ -1218,7 +1219,7 @@ modify_in_place <- function(x, value = x){
12181219# ' @param x a vector.
12191220# ' @param list either an index vector or a function (*not* a function
12201221# ' name).
1221- # ' @param values either a vector of replacement values or a function
1222+ # ' @param values,value either a vector of replacement values or a function
12221223# ' (*not* a function name).
12231224# ' @param ... additional arguments to `list` if it is a function;
12241225# ' otherwise ignored.
@@ -1247,9 +1248,20 @@ modify_in_place <- function(x, value = x){
12471248# ' stopifnot(identical(replace(x, \(.x) .x < 0, \(.x) .x * 1i),
12481249# ' base::replace(x, x < 0, x[x < 0] * 1i)))
12491250# '
1251+ # ' ### Modify the list in place.
1252+ # '
1253+ # ' y <- x
1254+ # ' replace(x, `<`, 1/4) <- 0
1255+ # ' x
1256+ # ' stopifnot(identical(x, replace(y, `<`, 0, 1/4)))
1257+ # '
12501258# ' @export
12511259replace <- function (x , list , values , ... ) {
12521260 if (is.function(list )) list <- list (x , ... )
12531261 if (is.function(values )) values <- values(x [list ], ... )
12541262 base :: replace(x , list , values )
12551263}
1264+
1265+ # ' @rdname replace
1266+ # ' @export
1267+ `replace<-` <- function (x , list , ... , value ) replace(x , list , value , ... )
0 commit comments