Updates row definition table created by function defData or defRead. (For tables created using defDataAdd and defReadAdd use updateDefAdd.) Does not modify in-place.

updateDef(
  dtDefs,
  changevar,
  newformula = NULL,
  newvariance = NULL,
  newdist = NULL,
  newlink = NULL,
  remove = FALSE
)

Arguments

dtDefs

Definition table that will be modified

changevar

Name of field definition that will be changed

newformula

New formula definition (defaults to NULL)

newvariance

New variance specification (defaults to NULL)

newdist

New distribution definition (defaults to NULL)

newlink

New link specification (defaults to NULL)

remove

If set to TRUE, remove `changevar`from definition (defaults to FALSE).

Value

The updated data definition table.

Examples


# Example 1

defs <- defData(varname = "x", formula = 0, variance = 3, dist = "normal")
defs <- defData(defs, varname = "y", formula = "2 + 3*x", variance = 1, dist = "normal")
defs <- defData(defs, varname = "z", formula = "4 + 3*x - 2*y", variance = 1, dist = "normal")

defs
#>    varname       formula variance   dist     link
#> 1:       x             0        3 normal identity
#> 2:       y       2 + 3*x        1 normal identity
#> 3:       z 4 + 3*x - 2*y        1 normal identity

updateDef(dtDefs = defs, changevar = "y", newformula = "x + 5", newvariance = 2)
#>    varname       formula variance   dist     link
#> 1:       x             0        3 normal identity
#> 2:       y         x + 5        2 normal identity
#> 3:       z 4 + 3*x - 2*y        1 normal identity
updateDef(dtDefs = defs, changevar = "z", newdist = "poisson", newlink = "log")
#>    varname       formula variance    dist     link
#> 1:       x             0        3  normal identity
#> 2:       y       2 + 3*x        1  normal identity
#> 3:       z 4 + 3*x - 2*y        1 poisson      log

# Example 2

defs <- defData(varname = "w", formula = 0, variance = 3, dist = "normal")
defs <- defData(defs, varname = "x", formula = "1 + w", variance = 1, dist = "normal")
defs <- defData(defs, varname = "z", formula = 4, variance = 1, dist = "normal")

defs
#>    varname formula variance   dist     link
#> 1:       w       0        3 normal identity
#> 2:       x   1 + w        1 normal identity
#> 3:       z       4        1 normal identity

updateDef(dtDefs = defs, changevar = "x", remove = TRUE)
#>    varname formula variance   dist     link
#> 1:       w       0        3 normal identity
#> 2:       z       4        1 normal identity
updateDef(dtDefs = defs, changevar = "z", remove = TRUE)
#>    varname formula variance   dist     link
#> 1:       w       0        3 normal identity
#> 2:       x   1 + w        1 normal identity

# No changes to original definition:
defs
#>    varname formula variance   dist     link
#> 1:       w       0        3 normal identity
#> 2:       x   1 + w        1 normal identity
#> 3:       z       4        1 normal identity