% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/use_renv.R
\name{use_renv}
\alias{use_renv}
\title{Activate an renv Project for the Current Session}
\usage{
use_renv(project = NULL, quiet = TRUE)
}
\arguments{
\item{project}{Optional path to a project root. If \code{NULL}
(the default), search upward from the script's directory
when known, otherwise from \code{getwd()}. The script directory
is taken from \code{Rscript}'s \verb{--file=} argument when present,
or from source references under littler.}

\item{quiet}{If \code{TRUE} (the default), suppress messages.}
}
\value{
The project root path (invisibly) if renv was activated
or was already active; otherwise \code{NULL}.
}
\description{
Make sure \code{renv} is activated, even if a script is run from
Rscript or littler.
}
\details{
Package \href{https://rstudio.github.io/renv/}{renv}
makes workflows reproducible by locking down the versions of
R packages. Normal \code{renv} mechanisms can fail, however,
if a script is run from Rscript or littler.
Adding

\if{html}{\out{<div class="sourceCode">}}\preformatted{command::use_renv()
}\if{html}{\out{</div>}}

to the top of R scripts fixes the problem.

For more details, see the article
\href{https://bayesiandemography.github.io/command/articles/a5_renv.html}{Using command with renv}.
}
\examples{
command::use_renv() ## if renv not used here, no effect

## see article for full example
}
\seealso{
\itemize{
\item \code{\link[=cmd_assign]{cmd_assign()}} Process command line arguments
\item \href{https://bayesiandemography.github.io/command/articles/a5_renv.html}{Using command with renv}
}
}
