% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/save_functions.R
\name{save_forest}
\alias{save_forest}
\title{Save a forest_reg() output}
\usage{
save_forest(
  forest,
  filename = "forest",
  format = c("pdf", "png", "tiff", "jpg"),
  width = NULL,
  height = NULL,
  scale = 1,
  auto_size = TRUE,
  padding = 0.25,
  dpi = 300
)
}
\arguments{
\item{forest}{A \code{gtregression_forest} object returned by
\code{forest_reg()}, or a compatible \pkg{forestploter}/grid object.}

\item{filename}{File name for the output, with or without extension. If no
directory is supplied, the file is saved in \code{tempdir()}.}

\item{format}{Output format. One of \code{"pdf"}, \code{"png"},
\code{"tiff"}, or \code{"jpg"}.}

\item{width, height}{Optional export width and height in inches. If either is
\code{NULL} and \code{auto_size = TRUE}, the size is measured from the
intrinsic \pkg{forestploter} gtable dimensions. If measurement is not
possible, a practical fallback is estimated from the number of rows and
columns in the \code{forest_reg()} output.}

\item{scale}{Positive multiplier applied to the export width and height. This
is a quick way to make a large forest plot roomier.}

\item{auto_size}{Logical. If \code{TRUE}, measure the intrinsic forest plot
size when \code{width} or \code{height} is not supplied. If \code{FALSE},
use the fallback row/column-based sizing.}

\item{padding}{White space around the forest plot in inches.}

\item{dpi}{Resolution for raster formats.}
}
\value{
Saves the file to disk. Invisibly returns the normalized file path.
}
\description{
Saves a \code{forest_reg()} output, or a compatible
\pkg{forestploter}/grid object, to a fixed graphics device. This is useful
when the RStudio Viewer or operating-system graphics device crops wide forest
plots or compresses forest columns.
}
\examples{
birthwt_data <- data_birthwt |>
  transform(
    smoke = factor(smoke, levels = c(0, 1), labels = c("No", "Yes")),
    ht = factor(ht, levels = c(0, 1), labels = c("No", "Yes")),
    low = factor(low, levels = c(0, 1), labels = c("Normal BW", "Low BW"))
  )

uni_or <- uni_reg(
  birthwt_data,
  outcome = "low",
  exposures = c("age", "smoke", "ht"),
  approach = "logit"
)

forest <- forest_reg(uni = uni_or)
save_forest(forest, filename = tempfile("forest"), format = "pdf")

# For large forest plots, increase width, height, scale, or padding.
save_forest(
  forest,
  filename = tempfile("forest-wide"),
  format = "png",
  scale = 1.2,
  padding = 0.35,
  dpi = 300
)
}
