R/post.recover.state.R

Defines functions recover.state

Documented in recover.state

recover.state <- function(tr, dead.trees, removed.trees){

  ## add dead trees
  if (!is.null(dead.trees)){
    new.trees <- list(  plot.id = dead.trees$data$plot.id
                    , treeid    = dead.trees$data$treeid
                    , dbh.mm    = dead.trees$data$dbh.mm
                    , height.dm = dead.trees$data$height.dm
                    , yrs.sim   = dead.trees$data$yrs.sim
                    , tree.sp   = dead.trees$data$tree.sp
                    )
    tr$addTrees(new.trees)
    dead.trees$last.measurement$treeid <- dead.trees$data$treeid
    attr(tr, 'last.measurement.dead') <- dead.trees$last.measurement
  }
  
  ## add removed trees if there are any
  if (!is.null(removed.trees)){
    new.trees <- list(  plot.id = removed.trees$data$plot.id
                    , treeid   = removed.trees$data$treeid
                    , dbh.mm   = removed.trees$data$dbh.mm
                    , height.dm = removed.trees$data$height.dm
                    , yrs.sim   = removed.trees$data$yrs.sim
                    , tree.sp   = removed.trees$data$tree.sp
                      )
    tr$addTrees(new.trees)
    removed.trees$last.measurement$treeid <- removed.trees$data$treeid
    attr(tr, 'last.measurement.removed') <- removed.trees$last.measurement
  }
    
  return (tr)
}
##  reassignInPackage("recover.state", "sitree", recover.state)

Try the sitree package in your browser

Any scripts or data that you put into this service are public.

sitree documentation built on June 1, 2018, 5:06 p.m.