R/io.ADMB.R

# io.ADMB.R - 
# FLCore/R/io.ADMB.R

# Copyright 2003-2012 FLR Team. Distributed under the GPL 2 or later
# Maintainer: Iago Mosqueira, JRC
# $Id:  $

readADMB<-function(file){
    ## read in data from ADMB Par or Rep file
    dat  <-scan(file,what="",sep="\n",skip=1)
    ## Get values
    vals <-lapply(strsplit(dat[grep("#",dat,invert=TRUE)]," "), function(x) as.numeric(x[nchar(x)>0]))
    ## name elements
    names(vals)<-lapply(grep("#",dat,value=T),function(x) substr(x,3,nchar(x)))
    return(vals)}
  
writeADMB<-function(x,file,append=FALSE){
    cat("#", names(x[1]),"\n",file=file,append=append)
    cat(x[[1]],"\n",file=file,append=TRUE)
    for (i in 2:length(x)){
      cat("#", names(x[i]),"\n",file=file,append=TRUE)
      cat(x[[i]],"\n",file=file,append=TRUE)}}
      

# # readADMB {{{
# readADMB <- function(file) {
#   
#   # read in data from ADMB Par or Rep file
#   dat  <-scan(file, what="", sep="\n", skip=1)
#   # Get values
#   vals <- lapply(strsplit(dat[grep("#", dat, invert=TRUE)], " "),
#     function(x) as.numeric(x[nchar(x)>0]))
#   # name elements
#   names(vals) <- lapply(grep("#", dat, value=T),
#     function(x) substr(x,3,nchar(x)))
#   return(vals)
# } # }}}
#   
# # writeADMB {{{
# writeADMB <- function(x,file) {
#   cat("#", names(x[1]), "\n",file=file, append=FALSE)
#   cat(x[[1]], "\n", file=file, append=TRUE)
#   
#   for (i in 2:length(x)) {
#     cat("#", names(x[i]), "\n", file=file, append=TRUE)
#     cat(x[[i]], "\n", file=file, append=TRUE)}
# } # }}}

Try the FLCore package in your browser

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

FLCore documentation built on May 2, 2019, 5:46 p.m.