bam2r: BAM inputs to R object conversion function

View source: R/bam2r.r

bam2rR Documentation

BAM inputs to R object conversion function

Description

This script reads in BAM dat, tpl, and cxx files, and converts them to R objects (character vectors of each line of the code). It also builds an R list on the tpl init objects, from the tpl and dat files.

Usage

bam2r(
  CommonName = NULL,
  init = NULL,
  dat_file = NULL,
  tpl_file = NULL,
  cxx_file = NULL,
  dat_obj = NULL,
  tpl_obj = NULL,
  cxx_obj = NULL,
  object_labels = list(bounded_point = c("init", "lower", "upper", "phase", "prior_mean",
    "prior_var", "prior_pdf"), bounded_vector = c("lower", "upper", "phase"))
)

bam_to_r(
  CommonName = NULL,
  init = NULL,
  dat_file = NULL,
  tpl_file = NULL,
  cxx_file = NULL,
  dat_obj = NULL,
  tpl_obj = NULL,
  cxx_obj = NULL,
  object_labels = list(bounded_point = c("init", "lower", "upper", "phase", "prior_mean",
    "prior_var", "prior_pdf"), bounded_vector = c("lower", "upper", "phase"))
)

Arguments

CommonName

Common name of species modeled in BAM files. Only used when accessing dat, tpl, and cxx character vectors named as e.g. dat_CommonName

init

user supplied list of tpl "init" object names defined in tpl Data Section. If missing, the function builds one from values in the dat and tpl files.

dat_file

dat file path

tpl_file

tpl file path

cxx_file

cxx file path

dat_obj

dat file read in as a character vector with readLines(con=dat_file)

tpl_obj

tpl file read in as a character vector with readLines(con=tpl_file)

cxx_obj

cxx file read in as a character vector with readLines(con=cxx_file)

object_labels

list of labels for bounded points and vectors

Examples

## Not run: 
# Read in any of the current BAM models
bam_AtMe <- bam2r("AtlanticMenhaden")
bam_BlSB <- bam2r("BlackSeaBass")
bam_BlTi <- bam2r("BluelineTilefish")
bam_Cobi <- bam2r("Cobia")
bam_GagG <- bam2r("GagGrouper")
bam_GrTr <- bam2r("GrayTriggerfish")
bam_GrAm <- bam2r("GreaterAmberjack")
bam_ReGr <- bam2r("RedGrouper")
bam_RePo <- bam2r("RedPorgy")
bam_ReSn <- bam2r("RedSnapper")
bam_ScGr <- bam2r("ScampGrouper")
bam_SnGr <- bam2r("SnowyGrouper")
bam_Tile <- bam2r("Tilefish")
bam_VeSn <- bam2r("VermilionSnapper")

# Run a bam model and assign rdat output to object
rdat_RePo <- run_bam(bam=bam_RePo,fileName="RePo")

# Modify data input from a BAM model and incorporate it back into the dat file object
init2 <- bam_RePo$init
init2$set_steep[c(1,5)] <- paste(0.6) # Change steepness
init2$set_steep[4] <- paste(-abs(as.numeric(init2$set_steep[4]))) # Fix steepness
bam_RePo2 <- bam2r("RedPorgy",init=init2)
rdat_RePo2 <- run_bam(bam=bam_RePo2,fileName="RePo2")

# Compare models
plot(rdat_RePo$t.series$year, rdat_RePo$t.series$SSB.msst,type="o", ylim=range(c(rdat_RePo$t.series$SSB.msst,rdat_RePo2$t.series$SSB.msst),na.rm=TRUE), xlab="year",ylab="SSB.msst")
points(rdat_RePo2$t.series$year,rdat_RePo2$t.series$SSB.msst,type="o",col="blue")
legend("topright",legend=c("RePo","RePo2"),pch=1,lty=1,col=c("black","blue"),bty="n")

## End(Not run)

nikolaifish/bamExtras documentation built on July 21, 2023, 8:26 a.m.