[Experimental]

Loop over an nm object when a vectorized operation is not available.

map_nm(.x, .f, ...)

map2_nm(.x, .y, .f, ...)

imap_nm(.x, .f, ...)

pmap_nm(.l, .f, ...)

Arguments

.x

An nm object.

.f

A function, formula, or vector (not necessarily atomic).

If a function, it is used as is.

If a formula, e.g. ~ .x + 2, it is converted to a function. There are three ways to refer to the arguments:

  • For a single argument function, use .

  • For a two argument function, use .x and .y

  • For more arguments, use ..1, ..2, ..3 etc

This syntax allows you to create very compact anonymous functions.

If character vector, numeric vector, or list, it is converted to an extractor function. Character vectors index by name and numeric vectors index by position; use a list to index by position and name at different levels. If a component is not present, the value of .default will be returned.

...

Additional arguments passed on to the mapped function.

.y

An optional nm object.

.l

A list of vectors, such as a data frame. The length of .l determines the number of arguments that .f will be called with. List names will be used if present.

Value

A modified nm object.

Examples


# 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"))
                                       
## vectorized run
m1 %>% child(1:3) %>% run_id(paste0(run_id(.), "modified"))
#> List of 3
#>  $ execute.Models/1modified
#>   ..$ type              : chr "execute"
#>   ..$ run_id            : chr "1modified"
#>   ..$ run_in            : chr "Models"
#>   ..$ parent_run_id     : chr "m1"
#>   ..$ parent_run_in     : chr "Models"
#>   ..$ parent_ctl_name   : chr "runm1.mod"
#>   ..$ parent_results_dir: chr "Results"
#>   ..$ executed          : logi FALSE
#>   ..$ ctl_contents      : chr collapsed - view with ctl_contents()
#>   ..$ ctl_orig          : chr collapsed - view with ctl_orig()
#>   ..$ data_path         : chr "/Users/runner/work/_temp/Library/NMproject/extdata/examples/theopp/SourceData/THEOPP.csv"
#>   ..$ cmd               : chr "execute run1modified.mod -dir=1modified"
#>   ..$ cores             : int 1
#>   ..$ parafile          : chr "path/to/parafile.pnm"
#>   ..$ run_dir           : chr "1modified"
#>   ..$ ctl_name          : chr "run1modified.mod"
#>   ..$ results_dir       : chr "Results"
#>   ..$ unique_id         : chr "execute.Models/1modified"
#>   ..$ lst_path          : chr "1modified/NM_run1/psn.lst"
#>   ..- attr(*, "class")= chr [1:3] "nm_execute" "nm_generic" "list"
#>  $ execute.Models/2modified
#>   ..$ type              : chr "execute"
#>   ..$ run_id            : chr "2modified"
#>   ..$ run_in            : chr "Models"
#>   ..$ parent_run_id     : chr "m1"
#>   ..$ parent_run_in     : chr "Models"
#>   ..$ parent_ctl_name   : chr "runm1.mod"
#>   ..$ parent_results_dir: chr "Results"
#>   ..$ executed          : logi FALSE
#>   ..$ ctl_contents      : chr collapsed - view with ctl_contents()
#>   ..$ ctl_orig          : chr collapsed - view with ctl_orig()
#>   ..$ data_path         : chr "/Users/runner/work/_temp/Library/NMproject/extdata/examples/theopp/SourceData/THEOPP.csv"
#>   ..$ cmd               : chr "execute run2modified.mod -dir=2modified"
#>   ..$ cores             : int 1
#>   ..$ parafile          : chr "path/to/parafile.pnm"
#>   ..$ run_dir           : chr "2modified"
#>   ..$ ctl_name          : chr "run2modified.mod"
#>   ..$ results_dir       : chr "Results"
#>   ..$ unique_id         : chr "execute.Models/2modified"
#>   ..$ lst_path          : chr "2modified/NM_run1/psn.lst"
#>   ..- attr(*, "class")= chr [1:3] "nm_execute" "nm_generic" "list"
#>  $ execute.Models/3modified
#>   ..$ type              : chr "execute"
#>   ..$ run_id            : chr "3modified"
#>   ..$ run_in            : chr "Models"
#>   ..$ parent_run_id     : chr "m1"
#>   ..$ parent_run_in     : chr "Models"
#>   ..$ parent_ctl_name   : chr "runm1.mod"
#>   ..$ parent_results_dir: chr "Results"
#>   ..$ executed          : logi FALSE
#>   ..$ ctl_contents      : chr collapsed - view with ctl_contents()
#>   ..$ ctl_orig          : chr collapsed - view with ctl_orig()
#>   ..$ data_path         : chr "/Users/runner/work/_temp/Library/NMproject/extdata/examples/theopp/SourceData/THEOPP.csv"
#>   ..$ cmd               : chr "execute run3modified.mod -dir=3modified"
#>   ..$ cores             : int 1
#>   ..$ parafile          : chr "path/to/parafile.pnm"
#>   ..$ run_dir           : chr "3modified"
#>   ..$ ctl_name          : chr "run3modified.mod"
#>   ..$ results_dir       : chr "Results"
#>   ..$ unique_id         : chr "execute.Models/3modified"
#>   ..$ lst_path          : chr "3modified/NM_run1/psn.lst"
#>   ..- attr(*, "class")= chr [1:3] "nm_execute" "nm_generic" "list"
#>  - attr(*, "class")= chr [1:2] "nm_list" "list"
  
m1 %>% child(1:3) %>% 
  map_nm(~ .x %>% run_id(paste0(run_id(.), "modified")))
#> List of 3
#>  $ execute.Models/1modified
#>   ..$ type              : chr "execute"
#>   ..$ run_id            : chr "1modified"
#>   ..$ run_in            : chr "Models"
#>   ..$ parent_run_id     : chr "m1"
#>   ..$ parent_run_in     : chr "Models"
#>   ..$ parent_ctl_name   : chr "runm1.mod"
#>   ..$ parent_results_dir: chr "Results"
#>   ..$ executed          : logi FALSE
#>   ..$ ctl_contents      : chr collapsed - view with ctl_contents()
#>   ..$ ctl_orig          : chr collapsed - view with ctl_orig()
#>   ..$ data_path         : chr "/Users/runner/work/_temp/Library/NMproject/extdata/examples/theopp/SourceData/THEOPP.csv"
#>   ..$ cmd               : chr "execute run1modified.mod -dir=1modified"
#>   ..$ cores             : int 1
#>   ..$ parafile          : chr "path/to/parafile.pnm"
#>   ..$ run_dir           : chr "1modified"
#>   ..$ ctl_name          : chr "run1modified.mod"
#>   ..$ results_dir       : chr "Results"
#>   ..$ unique_id         : chr "execute.Models/1modified"
#>   ..$ lst_path          : chr "1modified/NM_run1/psn.lst"
#>   ..- attr(*, "class")= chr [1:3] "nm_execute" "nm_generic" "list"
#>  $ execute.Models/2modified
#>   ..$ type              : chr "execute"
#>   ..$ run_id            : chr "2modified"
#>   ..$ run_in            : chr "Models"
#>   ..$ parent_run_id     : chr "m1"
#>   ..$ parent_run_in     : chr "Models"
#>   ..$ parent_ctl_name   : chr "runm1.mod"
#>   ..$ parent_results_dir: chr "Results"
#>   ..$ executed          : logi FALSE
#>   ..$ ctl_contents      : chr collapsed - view with ctl_contents()
#>   ..$ ctl_orig          : chr collapsed - view with ctl_orig()
#>   ..$ data_path         : chr "/Users/runner/work/_temp/Library/NMproject/extdata/examples/theopp/SourceData/THEOPP.csv"
#>   ..$ cmd               : chr "execute run2modified.mod -dir=2modified"
#>   ..$ cores             : int 1
#>   ..$ parafile          : chr "path/to/parafile.pnm"
#>   ..$ run_dir           : chr "2modified"
#>   ..$ ctl_name          : chr "run2modified.mod"
#>   ..$ results_dir       : chr "Results"
#>   ..$ unique_id         : chr "execute.Models/2modified"
#>   ..$ lst_path          : chr "2modified/NM_run1/psn.lst"
#>   ..- attr(*, "class")= chr [1:3] "nm_execute" "nm_generic" "list"
#>  $ execute.Models/3modified
#>   ..$ type              : chr "execute"
#>   ..$ run_id            : chr "3modified"
#>   ..$ run_in            : chr "Models"
#>   ..$ parent_run_id     : chr "m1"
#>   ..$ parent_run_in     : chr "Models"
#>   ..$ parent_ctl_name   : chr "runm1.mod"
#>   ..$ parent_results_dir: chr "Results"
#>   ..$ executed          : logi FALSE
#>   ..$ ctl_contents      : chr collapsed - view with ctl_contents()
#>   ..$ ctl_orig          : chr collapsed - view with ctl_orig()
#>   ..$ data_path         : chr "/Users/runner/work/_temp/Library/NMproject/extdata/examples/theopp/SourceData/THEOPP.csv"
#>   ..$ cmd               : chr "execute run3modified.mod -dir=3modified"
#>   ..$ cores             : int 1
#>   ..$ parafile          : chr "path/to/parafile.pnm"
#>   ..$ run_dir           : chr "3modified"
#>   ..$ ctl_name          : chr "run3modified.mod"
#>   ..$ results_dir       : chr "Results"
#>   ..$ unique_id         : chr "execute.Models/3modified"
#>   ..$ lst_path          : chr "3modified/NM_run1/psn.lst"
#>   ..- attr(*, "class")= chr [1:3] "nm_execute" "nm_generic" "list"
#>  - attr(*, "class")= chr [1:2] "nm_list" "list"