pass output from custom geom

I have created a custom geom to plot a line on a figure. Its use is

p<- df |>
ggplot2::ggplot() +
ggplot2::geom_line() +
mypackage::geom_lm(n=n)

The geom works fine in that it plots all it should. However under the hood in the STATLM.r function a few other things are being calculated. Like a pvalue for example.

How do i pass this pvalue from the geom to the resulting ggplot object?

The return statement in the geom currently passes the fitted values used in the plotting

Seems that 4.7 Building New Graphical Elements | Mastering Software Development in R 4.7.3 Building a Stat is what you are looking for.

Thanks for the link. Very helpful. After reading this, it seems like the geoms outlined in this article are only concerned with returning dataframes for plotting purposes, and not for returning additional info.