Skip to content

Commit

Permalink
Step one to start organizgin working examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jimianelli committed Feb 21, 2024
1 parent 8fac635 commit 540b42e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions R/readData.R
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -87,48 +87,48 @@ 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))
rownames(tab)<-c()
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)

tab <- (data.frame(tB))
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)
#
Expand Down

0 comments on commit 540b42e

Please sign in to comment.