Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create unit tests #26

Closed
wants to merge 95 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
cea7392
update(plot_recruitment): break up recruitment plot
Schiano-NOAA Nov 13, 2024
2af046d
Fix(spawning_biomass): fxn documentation
Schiano-NOAA Nov 13, 2024
121a9b3
update(plots): update documentation and formatting of plot recruitmen…
Schiano-NOAA Nov 13, 2024
1f424ae
update(documentation): and other part of the function for running
Schiano-NOAA Nov 14, 2024
74aa50c
fix(bugs in fxns): minor adjustments to rec devs, SR, and SB plots
Schiano-NOAA Nov 15, 2024
8f9aa62
fix(plot_biomass): reformat fxn
Schiano-NOAA Nov 21, 2024
e15dad7
fix(plot_landings): reformat fxn
Schiano-NOAA Nov 21, 2024
1f3059a
update(table_indices): reformat fxn - DOES NOT WORK
Schiano-NOAA Nov 21, 2024
c601eda
Update(documentation): result after running devtools::check
Schiano-NOAA Nov 22, 2024
464fb00
update(fxns): ones using write.csv now have added utils call
Schiano-NOAA Nov 22, 2024
8166f59
Merge branch 'master' into reformat-fxns
Schiano-NOAA Nov 22, 2024
d887a3d
took code that (locally, but not in the package) identified the fxn a…
sbreitbart-NOAA Nov 22, 2024
a0a4ba6
Merge branch 'add-rda' of https://github.com/nmfs-ost/satf into add-rda
Schiano-NOAA Nov 22, 2024
b89148f
set up testthat; wrote first test for write_captions()
sbreitbart-NOAA Nov 22, 2024
4bc8a40
added test for add_theme() (mostly copied from asar)
sbreitbart-NOAA Nov 22, 2024
d4a575d
added packages to DESCRIPTION
sbreitbart-NOAA Nov 22, 2024
225d6ce
Merge branch 'reformat-fxns' into add-rda
Schiano-NOAA Nov 25, 2024
90b8de7
Merge pull request #25 from nmfs-ost/add-rda
Schiano-NOAA Nov 25, 2024
cef948a
Merge pull request #27 from nmfs-ost/reformat-fxns
Schiano-NOAA Nov 25, 2024
201573a
updated names of 2 table functions to match naming pattern
sbreitbart-NOAA Nov 25, 2024
3b2b9df
recreated utils script that was deleted in this commit: https://githu…
sbreitbart-NOAA Nov 25, 2024
b501e6b
adding back code (mostly for tables and fxns focused on exporting obj…
sbreitbart-NOAA Nov 25, 2024
abb54f5
adding back code (for captions/alt text-related materials) that was d…
sbreitbart-NOAA Nov 25, 2024
ba5a4db
adding back code (for captions/alt template csv) that was deleted in …
sbreitbart-NOAA Nov 25, 2024
5817275
adding back code (for old plots) that was deleted in this commit: htt…
sbreitbart-NOAA Nov 25, 2024
f576286
fixed bug in write_captions; updated gitignore; updated output dir fo…
sbreitbart-NOAA Nov 26, 2024
fab0735
delete old function that exported a figure and its alt text
sbreitbart-NOAA Nov 26, 2024
24eeef8
created first draft of function that makes (and, if make_rda = T, exp…
sbreitbart-NOAA Nov 26, 2024
06c26a5
updated function to include (placeholders for) tables
sbreitbart-NOAA Nov 26, 2024
77174f1
Updated documentation
sbreitbart-NOAA Nov 26, 2024
8d7fa6f
Update(plot_recruitment_deviations.R): return the figure when running…
Schiano-NOAA Nov 27, 2024
b27e5b7
fix(plotting fxns): move associated rds needs into if statement
Schiano-NOAA Nov 27, 2024
d12eb83
fix(spawning_biomass): plt_fin moved into wrong statement
Schiano-NOAA Nov 27, 2024
13b10ff
Wrote code to extract numeric quantities for values associated with b…
sbreitbart-NOAA Nov 27, 2024
c429faa
Wrote code to extract numeric quantities for values associated with r…
sbreitbart-NOAA Dec 2, 2024
9434cfb
minor fixes to plots to successfully exclude specific values for year
sbreitbart-NOAA Dec 2, 2024
5468e3c
Stored vector of strings as internal data (year_exclusions in utils.R…
sbreitbart-NOAA Dec 2, 2024
677b512
created internal data rda and moved year_exclusions string into it an…
sbreitbart-NOAA Dec 2, 2024
6b591d1
removed "div" from Kobe plot object names; shortened est stock recrui…
sbreitbart-NOAA Dec 2, 2024
94e9239
Merge pull request #30 from nmfs-ost/fix-fxns
sbreitbart-NOAA Dec 2, 2024
e5dd1e2
Minor fix to plot (subbing in year_exclusions variable)
sbreitbart-NOAA Dec 3, 2024
00937c2
-changed rda filename to include fig/table, vs. "rda"
sbreitbart-NOAA Dec 3, 2024
cd12bc2
Merge pull request #28 from nmfs-ost/make-all-rdas
sbreitbart-NOAA Dec 3, 2024
18d3a2c
Wrote code to extract numeric quantities for values associated with b…
sbreitbart-NOAA Nov 27, 2024
6fe9e26
Wrote code to extract numeric quantities for values associated with r…
sbreitbart-NOAA Dec 2, 2024
f52c894
removed "div" from Kobe plot object names; shortened est stock recrui…
sbreitbart-NOAA Dec 2, 2024
e46e85e
Merge branch 'key-quantities' of https://github.com/nmfs-ost/satf int…
sbreitbart-NOAA Dec 3, 2024
60004af
replacing repeated string with internal data
sbreitbart-NOAA Dec 3, 2024
baf5ab0
fixing bug in exp_all_figs_tables.R related to @exports and @return; …
sbreitbart-NOAA Dec 6, 2024
03ff4c9
update(write_captions):
sbreitbart-NOAA Dec 10, 2024
403751e
update(utils): updated file.path() --> fs:::path()
sbreitbart-NOAA Dec 10, 2024
1cb2682
fixed documentation for multiple plotting fxns, and updated associate…
sbreitbart-NOAA Dec 10, 2024
f75554f
Merge branch 'master' into key-quantities
sbreitbart-NOAA Dec 10, 2024
c652a4d
feature(plot_recruitment): add option to append relative recruitment …
Schiano-NOAA Dec 11, 2024
a491edb
update(write_captions):
sbreitbart-NOAA Dec 12, 2024
284aee5
removed make_rda param from exp_all_figs_tables.R and updated documen…
sbreitbart-NOAA Dec 12, 2024
f5952b5
Merge pull request #33 from nmfs-ost/update-rda
sbreitbart-NOAA Dec 12, 2024
6e4a3de
feature(plot_biomass, plot_spawning_biomass): add option to append re…
sbreitbart-NOAA Dec 13, 2024
12d369d
Updating captions and alt text with quantities for relative B, SSB, r…
sbreitbart-NOAA Dec 16, 2024
d23331e
-updated write_captions quantities to be numeric and round to nearest…
sbreitbart-NOAA Dec 16, 2024
6eac0bd
update documentation
sbreitbart-NOAA Dec 16, 2024
a92e893
fix(b and sb plots): reformat plots so they still fxn even missing th…
Schiano-NOAA Dec 16, 2024
91a77c3
feature(plot_biomass): add annotation for reference line
Schiano-NOAA Dec 17, 2024
bf38ef8
fix double + in plot_biomass plot
Schiano-NOAA Dec 17, 2024
742c212
Merge pull request #34 from nmfs-ost/fix-b-sb-lines
Schiano-NOAA Dec 17, 2024
094ac58
Wrote code to extract numeric quantities for values associated with b…
sbreitbart-NOAA Nov 27, 2024
c73caa5
Wrote code to extract numeric quantities for values associated with r…
sbreitbart-NOAA Dec 2, 2024
69fcf9a
removed "div" from Kobe plot object names; shortened est stock recrui…
sbreitbart-NOAA Dec 2, 2024
884446a
replacing repeated string with internal data
sbreitbart-NOAA Dec 3, 2024
9574048
update(write_captions):
sbreitbart-NOAA Dec 10, 2024
f36fff3
update(utils): updated file.path() --> fs:::path()
sbreitbart-NOAA Dec 10, 2024
97feaba
fixed documentation for multiple plotting fxns, and updated associate…
sbreitbart-NOAA Dec 10, 2024
37eb7c2
feature(plot_recruitment): add option to append relative recruitment …
Schiano-NOAA Dec 11, 2024
7b020fc
update(write_captions):
sbreitbart-NOAA Dec 12, 2024
ce8a5e3
feature(plot_biomass, plot_spawning_biomass): add option to append re…
sbreitbart-NOAA Dec 13, 2024
9371371
Updating captions and alt text with quantities for relative B, SSB, r…
sbreitbart-NOAA Dec 16, 2024
27ca83b
-updated write_captions quantities to be numeric and round to nearest…
sbreitbart-NOAA Dec 16, 2024
8978341
Merge branch 'key-quantities' of https://github.com/nmfs-ost/satf int…
sbreitbart-NOAA Dec 17, 2024
dc2cc92
update(write_captions):
sbreitbart-NOAA Dec 17, 2024
dc17837
Changed underscores to periods in key quantities to avoid issues with…
sbreitbart-NOAA Dec 18, 2024
dfb93d9
Merge pull request #29 from nmfs-ost/key-quantities
sbreitbart-NOAA Dec 19, 2024
0b2d054
Reformat fxns and add new functions (#37)
Schiano-NOAA Dec 23, 2024
fb43ea6
update(README): add disclaimer that package is still in dev
sbreitbart-NOAA Dec 23, 2024
03031d9
Update(exp_all_figs_tables): make unit labels more specific to each f…
sbreitbart-NOAA Dec 23, 2024
5e9fddf
Update(exp_all_figs_tables):
sbreitbart-NOAA Dec 27, 2024
78f33bc
Merge pull request #39 from nmfs-ost/integrate-new-fxns
sbreitbart-NOAA Dec 27, 2024
80dba1f
Fix(exp_all_figs_tables): Fixed parameter definitions and documentation
sbreitbart-NOAA Dec 27, 2024
7db2f37
update(table_indies): reflect new naming conventions in SS3
Schiano-NOAA Dec 30, 2024
e8ddca2
set up testthat; wrote first test for write_captions()
sbreitbart-NOAA Nov 22, 2024
a64fb88
added test for add_theme() (mostly copied from asar)
sbreitbart-NOAA Nov 22, 2024
350f226
added packages to DESCRIPTION
sbreitbart-NOAA Nov 22, 2024
1c0cadf
Merge branch 'make-tests' of https://github.com/nmfs-ost/satf into ma…
sbreitbart-NOAA Dec 30, 2024
3f30307
Fix(test-write_captions)
sbreitbart-NOAA Dec 30, 2024
b278570
update write_captions test and add small dataset
sbreitbart-NOAA Dec 30, 2024
cc93de2
created tests for plot_biomass
sbreitbart-NOAA Dec 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
.Ruserdata
petrale_convert_output.csv
captions_alt_text.csv
converted_file_1126.csv
rda_files
6 changes: 6 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.2
Imports:
data.table,
dplyr,
flextable,
ggplot2,
glue,
gt,
kableExtra,
naniar,
nmfspalette,
stringr,
Expand All @@ -34,3 +37,6 @@ Remotes:
nmfs-fish-tools/nmfspalette
Depends:
R (>= 2.10)
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
8 changes: 6 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Generated by roxygen2: do not edit by hand

export(add_theme)
export(exp_fig_accessible)
export(exp_all_figs_tables)
export(plot_biomass)
export(plot_indices)
export(plot_landings)
export(plot_recruitment)
export(plot_recruitment_deviations)
export(plot_spawn_recruitment)
export(plot_spawning_biomass)
export(plot_total_biomass)
export(table_bnc)
export(table_indices)
export(write_captions)
15 changes: 13 additions & 2 deletions R/add_theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@
add_theme <- function(x) {
# this is bad coding practice, but what I have for now
if (class(x)[1] == "flextable") {
FitFlextableToPage <- function(ft, pgwidth = 6){

ft_out <- ft |> flextable::autofit()

ft_out <- flextable::width(ft_out, width = dim(ft_out)$widths*pgwidth /(flextable::flextable_dim(ft_out)$widths))
return(ft_out)
}
theme_obj <- x |>
flextable::merge_h(i = 1, part = "header") |>
flextable::align(part = "header", align = "center") |>
# flextable::font(fontname = "cambria",
# flextable::font(fontname = "arial narrow",
# part = "all") |>
flextable::add_header_lines(top = FALSE)
flextable::bold(part = "header") |>
flextable::add_header_lines(top = FALSE) |>
flextable::align(align = "center", part = "body") |>
flextable::autofit()
# FitFlextableToPage()
} else if (class(x)[1] == "gt_tbl") {
theme_obj <- x
# gt object
Expand Down
183 changes: 183 additions & 0 deletions R/exp_all_figs_tables.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
#' Export all figures and tables
#'
#' Export all figures and tables to Rda files within one function.
#'
#' @inheritParams plot_recruitment
#' @param recruitment_unit_label Units for recruitment
#' @param ref_line A string specifying the type of reference you want to
#' compare biomass to. The default is `"target"`, which looks for
#' `"biomass_target"` in the `"label"` column of `dat`. The actual
#' searching in `dat` is case agnostic and will work with either upper- or
#' lower-case letters but you must use one of the options specified in the
#' default list to ensure that the label on the figure looks correct
#' regardless of how it is specified in `dat`.
#' @param ref_point A known value of the reference point along with the label
#' for the reference point as specified in the output file. Please use this
#' option if the ref_line cannot find your desired point. Indicate the
#' reference point in the form c("label" = value).
#' @param landings_unit_label Units for landings
#' @param biomass_unit_label Units for biomass
#' @param spawning_biomass_label Units for spawning biomass
#' @param ref_line_sb Identical definition as `ref_line`, but this argument is
#' applied to plot_spawning_biomass.
#' @param ref_point_sb Identical definition as `ref_point`, but this argument is
#' applied to plot_spawning_biomass.
#' @param indices_unit_label Units for index of abundance/CPUE
#' @param biomass_unit_label Abbreviated units for biomass
#' @param catch_unit_label Abbreviated units for catch
#'
#' @return Rda files for each figure/table.
#'
#' @export
#'
#' @examples
#' \dontrun{
#' exp_all_figs_tables(dat, end_year = 2022, ref_line = "unfished", ref_point = 13000,
#' ref_point_sb = 13000, ref_line_sb = "target", indices_unit_label = "CPUE")
#' }

exp_all_figs_tables <- function(

# imported from plot_recruitment
dat,
recruitment_unit_label = "mt", # changed from unit_label to recruitment_unit_label for specificity
scale_amount = 1,
end_year = NULL,
n_projected_years = 10,
relative = FALSE,
rda_dir = getwd(),

# imported from plot_biomass
ref_line = c("target", "MSY", "msy", "unfished"),
ref_point = NULL,

# imported from plot_landings
landings_unit_label = "mt",

# imported from plot_recruitment_deviations- zero unique arguments

# imported from plot_spawn_recruitment
spawning_biomass_label = "mt",

# imported from plot_spawning_biomass
ref_line_sb = c("target", "MSY", "msy", "unfished"),
ref_point_sb = NULL,

# imported from plot_indices
indices_unit_label = NULL,

# imported from table_afsc_tier- add potential unique arguments after dev

# imported from table_bnc
biomass_unit_label = "mt",
catch_unit_label = "mt"

# imported from table_harvest_projection- add potential unique arguments after dev

# imported from table_indices- zero unique arguments

) {

make_rda <- TRUE

message("Starting export of figures and tables:")

# figures

satf::plot_recruitment(dat,
unit_label = recruitment_unit_label,
scale_amount,
end_year,
n_projected_years,
relative,
make_rda,
rda_dir) |> suppressWarnings() |> invisible()

message("Exported plot_recruitment")

satf::plot_biomass(dat,
unit_label = biomass_unit_label,
scale_amount,
ref_line,
ref_point,
end_year,
relative,
make_rda,
rda_dir) |> suppressWarnings() |> invisible()

message("Exported plot_biomass")

satf::plot_landings(dat,
unit_label = landings_unit_label,
make_rda,
rda_dir) |> suppressWarnings() |> invisible()

message("Exported plot_landings")

satf::plot_recruitment_deviations(dat,
end_year,
n_projected_years,
make_rda,
rda_dir) |> suppressWarnings() |> invisible()

message("Exported plot_recruitment_deviations")

# satf::plot_spawn_recruitment(dat,
# spawning_biomass_label,
# recruitment_label = recruitment_unit_label,
# end_year,
# make_rda,
# rda_dir) |> suppressWarnings() |> invisible()
#
# message("Exported plot_spawn_recruitment")

satf::plot_spawning_biomass(dat,
unit_label = spawning_biomass_label,
scale_amount,
ref_line = ref_line_sb,
ref_point = ref_point_sb,
end_year,
relative,
n_projected_years,
make_rda,
rda_dir) |>
# suppressWarnings() |>
invisible()

message("Exported plot_spawning_biomass")

# uncomment when this is working properly
# satf::plot_indices(dat,
# unit_label = indices_unit_label,
# make_rda,
# rda_dir) |> suppressWarnings() |> invisible()
#
# message("Exported plot_indices")

# tables
satf::table_bnc(dat,
end_year,
biomass_unit_label,
catch_unit_label,
make_rda,
rda_dir) |> suppressWarnings() |> invisible()

message("Exported table_bnc")

satf::table_indices(dat,
make_rda,
rda_dir) |> suppressWarnings() |> invisible()

message("Exported table_indices")

# uncomment when finished
# satf::table_landings(dat) |> suppressWarnings() |> invisible()
#
# message("Exported table_landings")
#
# undeveloped tables - add arguments after more development
# table_afsc_tier() |> suppressWarnings() |> invisible()
# table_harvest_projection() |> suppressWarnings() |> invisible()
message("Finished export of figures and tables.")

}
69 changes: 0 additions & 69 deletions R/exp_fig_accessible.R

This file was deleted.

Loading
Loading