fillDefaults: Assign object defaults to missing values

Description Usage Arguments Value See Also Examples

Description

This function takes care of investigating the enclosing functions arguments and identifying the missing ones. If they are missing and a default is given this value is assigned to the enclosing functions environment

Usage

1

Arguments

def

A named list of default values

Value

This function is called for its side effects

See Also

Set and get pangenome defaults with defaults

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Should only be called within methods/functions

# This will obviously fail
## Not run: 
  t <- function(x) {
    x+1
  }
  t()

## End(Not run)

# Using .fillDefaults
t <- function(x, defs) {
  .fillDefaults(defs)
  x+1
}

# With defaults
t(defs=list(x=5))

# Direct setting takes precedence
t(x=2, defs=list(x=5))

# Still fails if defs doesn't contain the needed parameter
## Not run: 
  t(defs=list(y='no no'))

## End(Not run)

# Usually defs are derived from the object in a method:
## Not run: 
  setMethod('fillDefExample', 'pgFull',
    function(object, x, y) {
      .fillDefaults(defaults(object))
      x+y
    }
  )

## End(Not run)

thomasp85/FindMyFriends documentation built on April 25, 2020, 1:06 p.m.