diff --git a/R/readData.R b/R/readData.R index 247032c..8053f3d 100644 --- a/R/readData.R +++ b/R/readData.R @@ -74,7 +74,7 @@ dat2list <- function(fn) { #' @param stock Name of the stock, defaults to "BSAI Atka mackerel". #' @return HTML tables for the specified Tier 3 data. #' @export -#' @importFrom xtable xtable +#' @importFrom xtable #' @importFrom dplyr select, group_by, summarise, spread #' @examples #' # Example usage: @@ -87,18 +87,18 @@ print_Tier3_tables <- function(df, modname="base", stock="BSAI Atka mackerel") { tabcap[4]=paste0("Tier 3 projections of ",stock," spawning biomass for the 7 scenarios.") # Stock Alt Sim Yr SSB Rec Tot_biom SPR_Implied F Ntot Catch ABC OFL AvgAge AvgAgeTot SexRatio FABC FOFL - bfsum <- df %>% select(Alt,Yr,SSB,F,ABC ,Catch) %>% group_by(Alt,Yr) %>% summarise(Catch=mean(Catch),SSB=mean(SSB),F=mean(F),ABC=mean(ABC)) + bfsum <- df %>% select(Alternative,Yr,SSB,F,ABC ,Catch) %>% group_by(Alternative,Yr) %>% summarise(Catch=mean(Catch),SSB=mean(SSB),F=mean(F),ABC=mean(ABC)) - tC <- bfsum %>% select(Alt,Yr,Catch) %>% spread(Alt,Catch) + tC <- bfsum %>% select(Alternative,Yr,Catch) %>% spread(Alternative,Catch) names(tC) <- c("Catch","Scenario 1","Scenario 2","Scenario 3","Scenario 4","Scenario 5","Scenario 6","Scenario 7") - tB <- bfsum %>% select(Alt,Yr,SSB) %>% spread(Alt,SSB) + tB <- bfsum %>% select(Alternative,Yr,SSB) %>% spread(Alternative,SSB) names(tB) <- c("SSB","Scenario 1","Scenario 2","Scenario 3","Scenario 4","Scenario 5","Scenario 6","Scenario 7") - tF <- bfsum %>% select(Alt,Yr,F) %>% spread(Alt,F) + tF <- bfsum %>% select(Alternative,Yr,F) %>% spread(Alternative,F) names(tF) <- c("F","Scenario 1","Scenario 2","Scenario 3","Scenario 4","Scenario 5","Scenario 6","Scenario 7") - tA <- bfsum %>% select(Alt,Yr,ABC) %>% spread(Alt,ABC) + tA <- bfsum %>% select(Alternative,Yr,ABC) %>% spread(Alternative,ABC) names(tA) <- c("ABC","Scenario 1","Scenario 2","Scenario 3","Scenario 4","Scenario 5","Scenario 6","Scenario 7") tab <- (data.frame(tC)) @@ -106,7 +106,7 @@ print_Tier3_tables <- function(df, modname="base", stock="BSAI Atka mackerel") { cap <- tabcap[1] for (i in 2:length(tab[1,]) ) tab[,i] <- formatC((tab[,i]), format="d", big.mark=",") - tab <- xtable(tab, caption = cap, label=paste0("tab:",tablab[1]), + tab <- xtable::xtable(tab, caption = cap, label=paste0("tab:",tablab[1]), digits=0, auto=TRUE, align=rep("r",(length(tab[1,])+1)) ) print(tab, "html", caption.placement = "top",include.rownames = FALSE, sanitize.text.function = function(x){x}, scalebox=.85) @@ -114,21 +114,21 @@ print_Tier3_tables <- function(df, modname="base", stock="BSAI Atka mackerel") { cap <- tabcap[2] for (i in 2:length(tab[1,]) ) tab[,i] <- formatC(as.numeric(tab[,i]), format="d", big.mark=",") - tab <- xtable(tab, caption = cap, label=paste0("tab:",tablab[2]),digits=0, auto=TRUE, align=rep("r",(length(tab[1,])+1)) ) + tab <- xtable::xtable(tab, caption = cap, label=paste0("tab:",tablab[2]),digits=0, auto=TRUE, align=rep("r",(length(tab[1,])+1)) ) print(tab, "html", caption.placement = "top",include.rownames = FALSE, sanitize.text.function = function(x){x}, scalebox=.85) tab <- (data.frame(tF)) cap <- tabcap[3] for (i in 2:length(tab[1,]) ) tab[,i] <- formatC(as.numeric(tab[,i]), format="f",digits=3) - tab <- xtable(tab, caption = cap, label=paste0("tab:",tablab[3]), digits=3, align=rep("r",(length(tab[1,])+1)) ) + tab <- xtable::xtable(tab, caption = cap, label=paste0("tab:",tablab[3]), digits=3, align=rep("r",(length(tab[1,])+1)) ) print(tab, "html", caption.placement = "top",include.rownames = FALSE, sanitize.text.function = function(x){x}, scalebox=.85) tab <- (data.frame(tA)) cap <- tabcap[4] for (i in 2:length(tab[1,]) ) tab[,i] <- formatC(as.numeric(tab[,i]), format="d", big.mark=",") - tab <- xtable(tab, caption = cap, label=paste0("tab:",tablab[4]),digits=0, auto=TRUE, align=rep("r",(length(tab[1,])+1)) ) + tab <- xtable::xtable(tab, caption = cap, label=paste0("tab:",tablab[4]),digits=0, auto=TRUE, align=rep("r",(length(tab[1,])+1)) ) print(tab, "html", caption.placement = "top",include.rownames = FALSE, sanitize.text.function = function(x){x}, scalebox=.85) return(tab) #