## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup--------------------------------------------------------------------
library(nlmixr2targets)

## ----both-forms, eval = FALSE-------------------------------------------------
# # Form 1: native nlmixr2 DSL syntax (works in nlmixr2 directly and
# # inside nlmixr2targets)
# model({
#   d / dt(central) <- -kel * central
#   central(0) <- 0          # initial value at time 0
#   cp <- central / vc
#   cp ~ add(cpaddSd)
# })
# 
# # Form 2: `cmt(initial) <- value` -- a `nlmixr2targets`-only
# # workaround. Use this only when something prevents the natural
# # `central(0) <- 0` form from being walked by `targets` (see the
# # "Known limitation" section below). `nlmixr2targets` rewrites this
# # back to `central(0) <- 0` before passing the model to nlmixr2.
# model({
#   d / dt(central) <- -kel * central
#   # nlmixr2targets-only; not understood by bare nlmixr2
#   central(initial) <- 0
#   cp <- central / vc
#   cp ~ add(cpaddSd)
# })

## ----print-body, eval = FALSE-------------------------------------------------
# body(my_model)

## ----pipe-forms, eval = FALSE-------------------------------------------------
# tar_nlmixr(
#   name = m1,
#   object = pheno |> model({
#     central(0) <- 0
#   }, append = TRUE),
#   data  = nlmixr2data::pheno_sd,
#   est   = "saem"
# )
# 
# tar_nlmixr(
#   name = m2,
#   object = pheno |> ini(cpaddSd = 0.3),
#   data  = nlmixr2data::pheno_sd,
#   est   = "saem"
# )

## ----unused-function, eval = FALSE--------------------------------------------
# sketch <- function() {
#   ini({
#     a <- 1
#   })
#   model({
#     central(0) <- 0
#   })
# }

