A wrapper around gsub
so that control files may be modified using gsub
syntax. Can be useful for simple find replace operations in a control
stream. Ensure you use the "view diff" app afterwards to make sure the find
replace proceeded as intended.
gsub_ctl(m, pattern, replacement, ..., dollar = NA_character_)
An nm object with modified ctl_contents
field.
# create example object m1 from package demo files
exdir <- system.file("extdata", "examples", "theopp", package = "NMproject")
m1 <- new_nm(run_id = "m1",
based_on = file.path(exdir, "Models", "ADVAN2.mod"),
data_path = file.path(exdir, "SourceData", "THEOPP.csv"))
m1 %>% dollar("EST")
#> $`execute.Models/m1`
#> 1| ; Parameter estimation - FOCE
#> 2| ;$EST METHOD=1 INTER NOABORT MAXEVAL=9999 PRINT=1 NSIG=3 SIGL=9
#> 3|
#> 4| ; Parameter estimation - IMP
#> 5| $EST METHOD=IMP ISAMPLE=300 NITER=300 RANMETHOD=3S2P
#> 6| CTYPE=3 CITER=10 CALPHA=0.05 CINTERVAL=3
#> 7| PRINT=1 NOABORT INTERACTION
#> 8|
#> 9| ; Parameer estimation - SAEM
#> 10| ;$EST METHOD=SAEM ISAMPLE=2 NBURN=1000 NITER=500 RANMETHOD=3S2P
#> 11| ;CTYPE=3 CITER=10 CALPHA=0.05 CINTERVAL=10
#> 12| ;PRINT=1 NOABORT INTERACTION
#> 13|
#> 14| ; Objective function and covariance evaluation
#> 15| $EST METHOD=IMP INTER EONLY= 1 MAPITER=0 ISAMPLE = 2000 NITER = 10 RANMETHOD=3S2P NOABORT PRINT=1 NSIG=3 SIGL=9
#> 16|
#>
m1 <- m1 %>% gsub_ctl("ISAMPLE=300", "ISAMPLE=600")
m1 %>% dollar("EST")
#> $`execute.Models/m1`
#> 1| ; Parameter estimation - FOCE
#> 2| ;$EST METHOD=1 INTER NOABORT MAXEVAL=9999 PRINT=1 NSIG=3 SIGL=9
#> 3|
#> 4| ; Parameter estimation - IMP
#> 5| $EST METHOD=IMP ISAMPLE=600 NITER=300 RANMETHOD=3S2P
#> 6| CTYPE=3 CITER=10 CALPHA=0.05 CINTERVAL=3
#> 7| PRINT=1 NOABORT INTERACTION
#> 8|
#> 9| ; Parameer estimation - SAEM
#> 10| ;$EST METHOD=SAEM ISAMPLE=2 NBURN=1000 NITER=500 RANMETHOD=3S2P
#> 11| ;CTYPE=3 CITER=10 CALPHA=0.05 CINTERVAL=10
#> 12| ;PRINT=1 NOABORT INTERACTION
#> 13|
#> 14| ; Objective function and covariance evaluation
#> 15| $EST METHOD=IMP INTER EONLY= 1 MAPITER=0 ISAMPLE = 2000 NITER = 10 RANMETHOD=3S2P NOABORT PRINT=1 NSIG=3 SIGL=9
#> 16|
#>