map_nm: A purrr-like looping function over nm objects

View source: R/utils.R

map_nmR Documentation

A purrr-like looping function over nm objects

Description

[Experimental]

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

Usage

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"))
  
m1 %>% child(1:3) %>% 
  map_nm(~ .x %>% run_id(paste0(run_id(.), "modified")))
  



tsahota/NMproject documentation built on Oct. 1, 2022, 11:51 a.m.