Skip to content

Commit

Permalink
Added latex version of table to US AP Report
Browse files Browse the repository at this point in the history
Instead of having a function and saving a csv file. Last year it was
not even used. And, who knows how they will supply the information for
future years if they do. Also, 99% of this information is already in the
document.

Close #966
  • Loading branch information
kellijohnson-NOAA committed Jan 25, 2023
1 parent dbb81ff commit 400451e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 82 deletions.
69 changes: 0 additions & 69 deletions R/catches.R
Original file line number Diff line number Diff line change
Expand Up @@ -275,75 +275,6 @@ further.tac.details <- function(fn){
read.csv(fn, header = TRUE, sep = ",", comment.char = "#")
}

make.catches.table.us.ap <- function(catches,
xcaption = "default",
xlabel = "default",
font.size = 9,
space.size = 10,
placement = "H"){
## Returns an xtable for the US AP appendix
##
## catches - data frame of catches in the format of data/us-ap-catch.csv
## xcaption - caption to appear in the calling document
## xlabel - the label used to reference the table in latex
## font.size - size of the font for the table
## space.size - size of the vertical spaces for the table
## placement - latex code for the placement of the table in the document

make.true.NA <- function(x){
## Change <NA> to NA
if(is.character(x) || is.factor(x)){
is.na(x) <- x %in% c("NA", "<NA>")
x
}else{
as.numeric(x)
}
}

colnames(catches)[1] <- ""
nr <- nrow(catches)
nc <- ncol(catches)
## Make value cells be comma-separated
catches[!grepl("\\%", catches[, 1]), -1] <- apply(
catches[!grepl("\\%", catches[, 1]), -1], 1:2,
function(x) format(as.numeric(x), big.mark = ","))

## Change factorized version <NA> to NA
catches <- apply(catches, c(1,2), make.true.NA)
catches <- apply(catches, c(1,2), function(x){gsub("NA", NA, x)})
## Replace NA with --
catches[is.na(catches)] <- ""

## Make percent cells have percent signs
catches <- apply(catches, 1:2, function(x) gsub("\\%", "\\\\%", x))
## Fix Total for Util Init. Alloc cell
catches[
grep("Init", catches[, 1], ignore.case = TRUE),
grep("total", colnames(catches), ignore.case = TRUE)] <- ""

## Make column and row headers bold
catches[,1] <- latex.bold(catches[,1])
colnames(catches) <- gsub("\\.{2}", " ", colnames(catches))
colnames(catches) <- gsub(" (\\D+)\\.$", " \\(\\1\\)", colnames(catches))
colnames(catches) <- gsub("US |U.S ", "U.S. ", colnames(catches))
colnames(catches) <- gsub("([[:lower:]])\\.([[:upper:]])", "\\1 \\2", colnames(catches))
colnames(catches)[-1] <- latex.bold(colnames(catches)[-1])
## Make it so that the first row heading doesn't appear.
## This must be a space and not the null string
colnames(catches)[1] <- " "

size.string <- latex.size.str(font.size, space.size)
print(xtable(catches,
caption = xcaption,
label = xlabel,
align = get.align(ncol(catches))),
caption.placement = "top",
include.rownames = FALSE,
table.placement = placement,
sanitize.text.function = function(x){x},
size = size.string)
}

make.catches.plot <- function(ct,
mar = c(4, 4, 6, 2) + 0.1,
leg.y.loc = 430,
Expand Down
4 changes: 0 additions & 4 deletions data/us-ap-catch.csv

This file was deleted.

27 changes: 18 additions & 9 deletions doc/appendix-fishery-reports/appendix-fishery-report-US.rnw
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@
**

%**Table was used in 2020 assessment but not in 2021 or 2022 so commenting out
%
%<<catches.us.ap, results='asis', echo=FALSE>>=
%make.catches.table.us.ap(us.ap.catch,
% xcaption = "2019 allocations and catch totals (metric tons, mt). Note that 441,433 mt
% U.S. TAC reduced by 1,500 mt for research and incidental catch set aside.",
% xlabel = "tab:us-ap-catch",
% font.size = 12,
% space.size = 13)
%@
% \begin{table}[H]
% \centering
% \caption{2019 allocations and catch totals (metric tons, mt). Note that
% 441,433 mt U.S. TAC reduced by 1,500 mt for research and incidental catch set
% aside.}
% \label{tab:us-ap-catch}
% \begingroup\fontsize{12}{13}\selectfont
% \begin{tabular}{lrrrrr}
% \hline
% & \textbf{U.S. TAC} & \textbf{Shoreside (SS)} & \textbf{Catcher Processor (CP)} & \textbf{Mothership (MS)} & \textbf{Tribal} \\
% \hline
% \textbf{Allocation (mt)} & 423,310 & 146,567 & 118,649 & 83,752 & 74,342 \\
% \textbf{Catch (mt)} & 287,908 & 138,650 & 111,147 & 37,978 & 133 \\
% \textbf{\% Utilization} & 68.01\% & 94.60\% & 93.68\% & 45.35\% & 0.18\% \\
% \hline
% \end{tabular}
% \endgroup
% \end{table}

\clearpage

0 comments on commit 400451e

Please sign in to comment.