#'
#' @title Set global values for this package
#'
#' @description Function to set global values, like key/value maps and dimensions.
#'
#' @param force - flag (T/F) to force (re)setting global variables
#'
#' @details Must be called prior to any other functions. The following global values are created:
#' \itemize{
#' \item{.GLOBAL_VARIABLES_rTCtoGmacs - flag indicating global variables have been created}
#' \item{.KV_MAP - list of named value vectors with keys as the associated names}
#' \item{.DIMS - list of model dimensions}
#' \item{.DIMNAMES - list of names associated with the model dimensions}
#' }
#'
#' @note If global variables have already been set, this function will not overwrite
#' them unless \code{force} is TRUE, so there is no downside to calling it.
#'
#' @export
#'
setGlobals<-function(force=FALSE){
if ((!exists(".GLOBAL_VARIABLES_rTCtoGmacs",where=".GlobalEnv"))||force){
#--define keywords
KEYWORDS<-list();
KEYWORDS[["FLEET_TYPES"]] <-c("SURVEY","FISHERY");
KEYWORDS[["AGGREGATED_CATCH_DATA_TYPES"]]<-c("AGGREGATE_ABUNDANCE","AGGREGATE_BIOMASS");
KEYWORDS[["SIZE_FREQUENCY_DATA_TYPES"]] <-"SIZE_FREQUENCY_DATA";
KEYWORDS[["EFFORT_DATA_TYPES"]] <-"EFFORT_DATA";
.KEYWORDS<<-KEYWORDS;#make global variable
#--define key/value maps
#----the values are defined as a named vector
#----the keys are the names associated with the values
KV_MAP<-list();
KV_MAP[["ON_OFF"]]<-c(TRUE,FALSE);
names(KV_MAP[["ON_OFF"]])<-c("ON","OFF");
.KV_MAP<<-KV_MAP;#make global variable
DIMS<-list(); DIMNAMES<-list();
DIMS[["y"]]<-1; DIMNAMES[["y"]]<-"UNDETERMINED"; #model years
DIMS[["r"]]<-1; DIMNAMES[["r"]]<-"EBS"; #model regions
DIMS[["a"]]<-1; DIMNAMES[["a"]]<-"UNDETERMINED"; #model age classes
DIMS[["x"]]<-3; DIMNAMES[["x"]]<-c("MALE", "FEMALE", "UNDETERMINED");#model sexes
DIMS[["m"]]<-3; DIMNAMES[["m"]]<-c("IMMATURE", "MATURE", "UNDETERMINED");#model maturity state
DIMS[["s"]]<-3; DIMNAMES[["s"]]<-c("NEW SHELL","OLD SHELL","UNDETERMINED");#model shell conditions
DIMS[["z"]]<-1; DIMNAMES[["z"]]<-"UNDETERMINED"; #model size bins
.DIMS<<-DIMS; .DIMNAMES<<-DIMNAMES;#make global variables
.nSXs = 2;#--number of modeled sexes
.nSCs = 2;#--number of modeled shell conditions
.nMTs = 2;#--number of maturity states
.SXs = c(UNDETERMINED=0,MALE =1,FEMALE= 2);
.SCs = c(UNDETERMINED=0,NEW_SHELL=1,OLD_SHELL=2);
.MTs = c(UNDETERMINED=0,IMMATURE =1,MATURE= 2);
.GLOBAL_VARIABLES_rTCtoGmacs = TRUE;
}
return(invisible(NULL));
}
#'
#' @title Substitute value for key
#'
#' @description Function to substitute values for key words.
#'
#' @param ks - vector of key words
#' @param map_kv - map from keyword to value
#'
#' @details None.
#'
#' @export
#'
subForKey<-function(ks,map_kv){
res<-map_kv[ks];
return(res);
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.