zprint {zfit}R Documentation

Print the result of a function in a pipe but return original object

Description

Given x and f, this function prints f(x) before returning the original x. It is useful in a pipe, when one wants a to print the derivative of an object in the pipe but then return or assign the original object. A common use case is printing the 'summary() of an estimated model but then assigning the original model (rather than the summary object) to a variable for further processing.

Usage

zprint(x, f = NULL, ...)

Arguments

x

An object, typically in a pipe.

f

A function to be applied to x before printing.

...

Other arguments to be passed to f.

Value

The original object x.

Examples

if (getRversion() >= "4.1.0" && require("dplyr")) {

  # Print summary before assigning model to variable
  m <- lm( speed ~ dist, cars) |>
    zprint(summary) # prints summary(x)
  m                 # m is the original model object

  # Print grouped data before filtering original
  cw_subset <- chickwts |>
    zprint(count, feed, sort=TRUE) |> # prints counts by feed
    filter(feed=="soybean")
  cw_subset # cw_subset is ungrouped, but filtered by feed
}


[Package zfit version 0.4.0 Index]