Skip to content

Commit

Permalink
doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
smwoodman committed Feb 28, 2024
1 parent 03b301d commit 3b0f9d0
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 146 deletions.
61 changes: 0 additions & 61 deletions R/global-vars.R

This file was deleted.

7 changes: 4 additions & 3 deletions R/mod_afs_study_beach_census.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,17 @@ mod_afs_study_beach_census_server <- function(id, src, season.df, tab) {
grepl("_count", census.names) | grepl("_sum", census.names)]

validate(
need(all(afs.study.beach.counts %in% census.names) &
all(choices.names.cs %in% afs.study.beach.counts),
need(all(tamatoamlr::afs.study.beach.counts %in% census.names) &
all(choices.names.cs %in% tamatoamlr::afs.study.beach.counts),
paste("The column names from afs.study.beach.counts",
"and names(census_df_collect()) are not identical -",
"please adjust the afs.study.beach.counts variable"))
)

selectInput(
session$ns("age_sex"), tags$h5("Columns to plot"),
choices = afs.study.beach.counts, selected = c("pup_live_count"),
choices = tamatoamlr::afs.study.beach.counts,
selected = c("pup_live_count"),
multiple = TRUE, selectize = TRUE
)
})
Expand Down
21 changes: 10 additions & 11 deletions R/mod_season_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#'
#' @name mod_season_info
#'
#' @param id character used to specify namespace, see \code{\link[shiny]{NS}}
#' @param id character used to specify namespace, see [shiny::NS()]
#' @param col.width integer; column width of column of UI widgets
#'
#' @export
Expand All @@ -25,18 +25,17 @@ mod_season_info_ui <- function(id, col.width = 7) {

#' @name mod_season_info
#'
#' @param pool reactive; a DBI database connection pool,
#' intended to be the output of \code{\link{mod_database_server}}
#' @param si.name character; name of season information table.
#' Default is 'season_info'
#' @param src reactive; a DBI database connection src, intended to be the output
#' of `mod_database_server()`
#' @param si.name character; name of season information table. Default is
#' 'season_info'
#'
#' @returns
#' \code{mod_season_server} returns a list with one component:
#' a reactive of the season information data frame
#' @returns `mod_season_server()` returns a list with one component: a reactive
#' of the season information data frame
#'
#' @export
mod_season_info_server <- function(id, pool, si.name = "season_info") {
stopifnot(is.reactive(pool))
mod_season_info_server <- function(id, src, si.name = "season_info") {
stopifnot(is.reactive(src))

moduleServer(
id,
Expand All @@ -50,7 +49,7 @@ mod_season_info_server <- function(id, pool, si.name = "season_info") {

# Get data from table
season_info <- reactive({
df.out <- tbl(req(pool()), si.name) %>%
df.out <- tbl(req(src()), si.name) %>%
select(-ts) %>%
arrange(desc(season_open_date)) %>%
collect()
Expand Down
20 changes: 11 additions & 9 deletions R/mutate_factor_species.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#' Convert species column to a factor
#'
#' A 'wrapper' around mutate that converts the species column to a factor with the specified levels
#' A 'wrapper' around mutate that converts the species column to a factor with
#' the specified levels
#'
#' @param x data frame that at minimum contains a 'species' column
#' @param levels character; passed to 'levels' argument of \code{\link[base]{factor}}.
#' Default is \code{names(\link{pinniped.sp})}
#' @param levels character; passed to 'levels' argument of
#' \code{\link[base]{factor}}. Default is \code{names(\link{pinniped.sp})}
#'
#' @details A wrapper around \code{\link[dplyr]{mutate}} that converts
#' the species column to a factor with the specified levels.
#' This allows this function to be used directly in dplyr pipelines.
#' @details A wrapper around \code{\link[dplyr]{mutate}} that converts the
#' species column to a factor with the specified levels. This allows this
#' function to be used directly in dplyr pipelines.
#'
#' @return \code{x}, with the column 'species' converted to a \link[base]{factor} that
#' has levels: \code{\link[base]{names}(\link{pinniped.sp})}, i.e.
#' \code{c("Fur seal", "Crabeater seal", etc.)}
#' @return \code{x}, with the column 'species' converted to a
#' \link[base]{factor} that has levels:
#' \code{\link[base]{names}(\link{pinniped.sp})}, i.e. \code{c("Fur seal",
#' "Crabeater seal", etc.)}
#'
#' @examples
#' x <- data.frame(species = c("Fur seal", "Weddell seal"), count = c(2, 1))
Expand Down
22 changes: 10 additions & 12 deletions R/shiny-modules.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#' Modules for the different tabs of Tamatoa, the tamatoamlr Shiny app
#' Tamatoa data modules
#'
#' Modules for the different tabs of Tamatoa, the tamatoamlr Shiny app
#' Modules for the different tabs of Tamatoa, the `tamatoamlr` Shiny app
#'
#' @name shiny_modules
#'
#' @param id character used to specify namespace, see \code{shiny::\link[shiny]{NS}}
#' @param src reactive; a DBI database connection.
#' Intended to be the output of \code{\link{mod_database_server}},
#' i.e. a pool object
#' @param season.df reactive; the season info data frame.
#' Intended to be the first element (\code{season.df}) of
#' the (list) output of \code{\link{mod_filter_season_server}}
#' @param tab reactive; the selected tab.
#' Used by the modules to only collect data from database if the
#' relevant tab is chosen
#' @param id character used to specify namespace, see [shiny::NS()]
#' @param src reactive; a DBI database connection. Intended to be the output of
#' [mod_database_server()], i.e. a pool object
#' @param season.df reactive; the season info data frame. Intended to be the
#' first element (`season.df`) of the (list) output of
#' [mod_filter_season_server()]
#' @param tab reactive; the selected tab. Used by the modules to only collect
#' data from database if the relevant tab is chosen
NULL
3 changes: 3 additions & 0 deletions R/tamatoa.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ tamatoa <- function(...,
if (dbIsValid(pool.remote.prod)) poolClose(pool.remote.prod)
if (isTruthy(pool.remote.test))
if (dbIsValid(pool.remote.test)) poolClose(pool.remote.test)
if (isTruthy(pool.local.prod))
if (dbIsValid(pool.local.prod)) poolClose(pool.local.prod)
})


Expand Down Expand Up @@ -161,6 +163,7 @@ tamatoa <- function(...,
### Quit GUI
session$onSessionEnded(function() {
# Close current pool object. Needed here in case working off 'other' db
# on.exit(dbDisconnect(conn))
isolate({
if (inherits(db.pool(), "Pool")) {
if (dbIsValid(db.pool())) {
Expand Down
75 changes: 75 additions & 0 deletions R/tamatoamlr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,82 @@
#' @keywords package
"_PACKAGE"



# https://github.com/hadley/r-pkgs/issues/828
ignore_unused_imports <- function() {
dbplyr::sql
}



# https://github.com/r-lib/tidyselect/issues/248
# https://r-pkgs.org/package-within.html#echo-a-working-package
utils::globalVariables(c(
"where", ".",

# Commonly used variables
"observer", "location", "location_group", "beach_id", "species",
"Beach", "Beaches", "loc_lower", "loc_clean", "week_num", "header_id",
"capture_id",

# Plotting
"count_class", "count_value", "species_lty",

# season_info
"season_name", "season_open_date", "season_close_date", "season_days",
"diet_scat_date", "date_median_pupping", "ts",

# Phocid census
"census_phocid_header_id", "census_id", "census_type",
"census_date_start", "census_date_end",
"census_date", "time_start", "time_end",
"ad_female_count", "ad_male_count", "ad_unk_count",
"juv_female_count", "juv_male_count", "juv_unk_count",
"pup_live_count", "pup_dead_count",
"unk_female_count", "unk_male_count", "unk_unk_count",
"census_notes", "census_created_dt",


# AFS Capewide Pup Census
"pup_count", "pup_live_count", "pup_dead_count", "date_min",
"count_loc_mean", "count_loc_var", "count_loc_sd", "study_beach_count",
"count_mean", "count_var", "count_sd", "count_range", "group",
"census_date_min", "count_range_perc_diff",

# AFS Study Beach Census
"ad_male_count_sum", "adult_male_non_terr_count", "adult_male_terr_count",
"adult_male_terr_noFem_count", "adult_male_terr_wFem_count",
"adult_male_unk_count",


# Misc
"Code", "Day", "Hr", "ID", "Mass", "Mn", "Sig", "Yr", "action",
"attendance_study", "body_condition", "box_time",
"capt_to_release", "capt_to_reunion", "capture_date", "capture_date_rm",
"capture_datetime", "capture_location", "capture_time", "capture_time_rm",
"ccamlr_pup_weights_notes", "census_afs_capewide_pup_sort", "cohort",
"combined_number", "d", "datetime", "datetime_prev", "days_diff",
"device_inventory_id", "device_num", "device_type", "exclude_count", "freq",
"frequency", "gas_off", "gas_on", "gas_time", "head", "header_notes", "in_box",
"location_fctr", "location_lty", "m", "mass_kg", "mass_std_deviation",
"mass_std_error", "mass_total_kg", "max_dt", "mean_mass_kg", "min_dt", "n_records",
"n_resights", "n_trips", "n_weights", "name", "notes_tmp", "number_of_captures",
"parturition", "parturition_date", "pinniped_id", "pinniped_season_id",
"primary_tag", "pup_alive", "pup_mortality", "pup_mortality_date", "pup_num",
"pup_total_count", "release_time", "research_program", "resight_date",
"resight_time", "reunion_time", "round_date", "round_num", "sd", "season_date",
"season_info_id", "sex", "sig", "station", "std_length_cm", "tag_freq_code", "tag_letter",
"tag_numeric", "tag_sort", "tag_type", "tagging_date", "tare_check", "tare_kg", "time",
"time_diff_hr", "trip_length_hr", "trip_length_hr_mean", "trip_num",
"trip_num_completed", "trip_num_completed_max", "notes",

"freq_chr", "recovery_date", "deployment_date", "end_date", "tag_primary",
"tag_type_primary", "tag_unique_primary", "non_amlr_tag_primary",
"tag_sort_primary", "amlr_tag_primary", "apw_collect", "unk_group_id",
"deployment_season", "pinniped_sex", "arrival_date", 'twins', "status", "age",
"on_the_fly_id", "sample_type", "sample_type_group", "age_class",
"individual_seals_count", "n_adults_juveniles", "n_pups", "ad_male_sum",
"tag_resights_leopards_id", "id_unique", "package_count"
))

11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
[![R-CMD-check](https://github.com/us-amlr/tamatoamlr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/us-amlr/tamatoamlr/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

tamatoamlr and Tamatoa, the package's accompanying Shiny app, are for analyzing and visualizing data collected by the [U.S. AMLR Program's](https://www.fisheries.noaa.gov/about/antarctic-ecosystem-research-division-southwest-fisheries-science-center) [Pinniped Research Group](https://www.fisheries.noaa.gov/international/science-data/pinniped-research-antarctic).
`tamatoamlr` and Tamatoa, the package's accompanying Shiny app, are for analyzing and visualizing data collected by the [U.S. AMLR Program's](https://www.fisheries.noaa.gov/about/antarctic-ecosystem-research-division-southwest-fisheries-science-center) [Pinniped Research Group](https://www.fisheries.noaa.gov/international/science-data/pinniped-research-antarctic).

## Installation

You can install the development version of tamatoamlr from [GitHub](https://github.com/) with:
You can install the development version of `tamatoamlr` from [GitHub](https://github.com/) with:

``` r
# install.packages("devtools")
Expand All @@ -18,7 +18,7 @@ devtools::install_github("us-amlr/tamatoamlr")

## Tamatoa: Shiny app

To run Tamatoa, the tamatoamlr Shiny app, locally, you must have R and [RStudio](https://www.rstudio.com/products/rstudio/download/#download) installed. From within RStudio, install tamatoamlr as described above, and then run the following code in your RStudio console to launch the Shiny app:
To run Tamatoa, the `tamatoamlr` Shiny app, locally, you must have R and [RStudio](https://www.rstudio.com/products/rstudio/download/#download) installed. From within RStudio, install `tamatoamlr` as described above, and then run the following code in your RStudio console to launch the Shiny app:

``` r
tamatoamlr::tamatoa()
Expand All @@ -30,10 +30,9 @@ By default, Tamatoa attempts to connect to the database on the SWFSC server. For

* `mod_database_server`, from [amlrDatabases](https://github.com/us-amlr/amlrDatabases), returns the connection to the user-specified database via a [pool](https://github.com/rstudio/pool) object that is used by the rest of the tamatoamlr Shiny App modules. Pool connections to the four possible databases (remote/local and AMLR_PINNIPEDS/AMLR_PINNIPEDS_Test) may be generated and passed to `mod_database_server`, depending on the arguments passed to `tamatoa()`.

* `mod_season_info_server` returns the season information data for the rest of the modules
* `mod_season_info_server` returns the season information data used by the rest of the modules

* The 'Database and season info' tab relies on mod_database and mod_season_info. The rest of the tabs all have a dedicated module that takes at least the pool object from mod_database, and generally season.df and season.id.list from mod_season_info_server, as inputs. These modules pass both a table and a plot to mod_output_server from [amlrDatabases](https://github.com/us-amlr/amlrDatabases), which displays the table and plot along with associated visualization and download options. These modules generally depend on views created in the database.
TODO: this needs a system that is more robust to changes in the SQL server views. For instance, each view has a function that checks for required column names, and returns a df with standardized capitalization things?
* The 'Database and season info' tab relies on `mod_database` and `mod_season_info`. The rest of the tabs all have a dedicated module that takes at least the pool object from `mod_database`, and generally the season.df data frame output from `mod_season_info_server`, as inputs. These modules pass both a table and a plot to `mod_output_server` from [amlrDatabases](https://github.com/us-amlr/amlrDatabases), which displays the table and plot along with associated visualization and download options. These modules generally depend on views created in the database.

## Disclaimer

Expand Down
4 changes: 2 additions & 2 deletions man/afs.study.beach.counts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/csphoc.core.location.groups.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions man/mod_season_info.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3b0f9d0

Please sign in to comment.