Writes a new .ferx file pre-filled with a skeleton for the chosen model type, then opens it in an editor. Pass print = TRUE instead of supplying a path to print the skeleton to the console without writing any file — useful for copy-pasting or piping in a scripted workflow.

ferx_model_new(
  path = NULL,
  template = "1cpt_oral",
  overwrite = FALSE,
  edit = TRUE,
  print = FALSE
)

Arguments

path

Path for the new .ferx file. Must not already exist unless overwrite = TRUE. Ignored when print = TRUE.

template

One of "1cpt_oral" (default), "1cpt_iv", "2cpt_oral", "2cpt_iv", or "ode".

overwrite

Logical. Overwrite path if it already exists? Defaults to FALSE.

edit

Logical. Open the file in an editor after writing? Defaults to TRUE. Ignored when print = TRUE.

print

Logical. If TRUE, print the skeleton to the console instead of writing a file. No file is created and no editor is opened. Defaults to FALSE.

Value

path invisibly, or NULL invisibly when print = TRUE.

Examples

# Print a skeleton to the console (no file written, no editor opened)
ferx_model_new(print = TRUE)
#> # One-compartment oral PK model
#> 
#> [parameters]
#>   theta TVCL(1.0, 0.001, 100.0)
#>   theta TVV(10.0, 0.1, 1000.0)
#>   theta TVKA(1.0, 0.01, 50.0)
#> 
#>   omega ETA_CL ~ 0.09
#>   omega ETA_V  ~ 0.09
#>   omega ETA_KA ~ 0.25
#> 
#>   sigma PROP_ERR ~ 0.01
#> 
#> [individual_parameters]
#>   CL = TVCL * exp(ETA_CL)
#>   V  = TVV  * exp(ETA_V)
#>   KA = TVKA * exp(ETA_KA)
#> 
#> [structural_model]
#>   pk one_cpt_oral(cl=CL, v=V, ka=KA)
#> 
#> [error_model]
#>   DV ~ proportional(PROP_ERR)
#> 
#> [fit_options]
#>   method     = foce
#>   maxiter    = 300
#>   covariance = true
#> 
ferx_model_new(template = "2cpt_iv", print = TRUE)
#> # Two-compartment IV bolus PK model
#> 
#> [parameters]
#>   theta TVCL(5.0, 0.1, 100.0)
#>   theta TVV1(15.0, 1.0, 500.0)
#>   theta TVQ(3.0, 0.01, 100.0)
#>   theta TVV2(30.0, 1.0, 500.0)
#> 
#>   omega ETA_CL ~ 0.10
#>   omega ETA_V1 ~ 0.10
#>   omega ETA_Q  ~ 0.10
#>   omega ETA_V2 ~ 0.10
#> 
#>   sigma PROP_ERR ~ 0.01
#> 
#> [individual_parameters]
#>   CL = TVCL * exp(ETA_CL)
#>   V1 = TVV1 * exp(ETA_V1)
#>   Q  = TVQ  * exp(ETA_Q)
#>   V2 = TVV2 * exp(ETA_V2)
#> 
#> [structural_model]
#>   pk two_cpt_iv_bolus(cl=CL, v1=V1, q=Q, v2=V2)
#> 
#> [error_model]
#>   DV ~ proportional(PROP_ERR)
#> 
#> [fit_options]
#>   method     = foce
#>   maxiter    = 500
#>   covariance = true
#> 

# Write a skeleton to a temp file and show it
tmp <- ferx_model_new(tempfile(fileext = ".ferx"), edit = FALSE)
#> Created /tmp/RtmpFO1fSO/file257c3107b747.ferx
ferx_model_show(tmp)
#> # model: file257c3107b747.ferx 
#> # One-compartment oral PK model
#> 
#> [parameters]
#>   theta TVCL(1.0, 0.001, 100.0)
#>   theta TVV(10.0, 0.1, 1000.0)
#>   theta TVKA(1.0, 0.01, 50.0)
#> 
#>   omega ETA_CL ~ 0.09
#>   omega ETA_V  ~ 0.09
#>   omega ETA_KA ~ 0.25
#> 
#>   sigma PROP_ERR ~ 0.01
#> 
#> [individual_parameters]
#>   CL = TVCL * exp(ETA_CL)
#>   V  = TVV  * exp(ETA_V)
#>   KA = TVKA * exp(ETA_KA)
#> 
#> [structural_model]
#>   pk one_cpt_oral(cl=CL, v=V, ka=KA)
#> 
#> [error_model]
#>   DV ~ proportional(PROP_ERR)
#> 
#> [fit_options]
#>   method     = foce
#>   maxiter    = 300
#>   covariance = true
#> 

if (FALSE) { # \dontrun{
# Write a file and open it for editing
ferx_model_new("my_model.ferx")

# Write a file without opening an editor
ferx_model_new("my_model.ferx", edit = FALSE)
} # }