R/optansout.R

Defines functions optansout

Documented in optansout

optansout <- function(ansdf, filename) {
    ##### OPEN ISSUES: (any date order)
    # 120709 Not printing parameters == but does when source'd!    
    ##### IMPLEMENTED: (reverse date order)
    
    # A funtion to display and print to file (if present) the
    #   output of optimx
    if (!is.null(filename)) {
        sink(filename)
    }
    # if (! exists(filename)) { sink(filename) } # may need to
    #   check paths
    tpar <- ansdf$par
    tdf <- ansdf
#    ltvec <- length(tpar[[1]]) 
    for (i in 1:length(tpar)) {
        tvec <- tpar[[i]]
        ltvec <- length(tvec)
        if (ltvec > 5) {
            tvec <- tvec[1:5]
        }
        tpar[[i]] <- tvec
    }
    tdf$par <- tpar
    if (ltvec > 5) {
        names(tdf)[2] <- "first.5.par"
    } else {
        names(tdf)[2] <- "par"
    }
    print(tdf)
    if (!is.null(filename)) {
        sink()
    }
    rm(tdf)
    rm(tpar)
    return(TRUE)
}

Try the optplus package in your browser

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

optplus documentation built on May 2, 2019, 6:48 p.m.