Skip to content

Commit

Permalink
Merge pull request #13 from IDEMSInternational/sub_branch
Browse files Browse the repository at this point in the history
Adding display daily file bits
  • Loading branch information
lilyclements authored Nov 1, 2024
2 parents 12a1b63 + 46232b9 commit 8f3ebcb
Show file tree
Hide file tree
Showing 6 changed files with 508 additions and 4 deletions.
330 changes: 330 additions & 0 deletions R/DisplayDaily.R

Large diffs are not rendered by default.

23 changes: 20 additions & 3 deletions R/data_book.R
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@
#' \item{\code{wrap_or_unwrap_data(data_name, col_name, column_data, width, wrap = TRUE)}}{Wraps or unwraps the specified column data in the given data table to the specified width.}
#' \item{\code{anova_tables2(data_name, x_col_names, y_col_name, signif.stars = FALSE, sign_level = FALSE, means = FALSE)}}{Generate ANOVA tables for specified columns in a dataset.}
#' \item{\code{define_as_options_by_context(data_name, obyc_types = NULL, key_columns = NULL)}}{Define options by context for a specified dataset.}


#' \item{\code{display_daily_table(data_name, climatic_element, date_col, year_col, station_col, Misscode, Tracecode, Zerocode, monstats = c("min", "mean", "median", "max", "IQR", "sum"))}}{Display a daily summary table for a specified climatic data element.}
#' @export
DataBook <- R6::R6Class("DataBook",
public = list(
Expand Down Expand Up @@ -4249,13 +4248,31 @@ DataBook <- R6::R6Class("DataBook",
self$get_data_objects(data_name)$anova_tables2(x_col_names = x_col_names, y_col_name = y_col_name, signif.stars = signif.stars, sign_level = sign_level, means = means)
},

#' @description
#' Display a daily summary table for a specified climatic data element.
#'
#' @param data_name A character string representing the name of the dataset.
#' @param climatic_element A vector specifying the climatic elements to be displayed (e.g., temperature, rainfall).
#' @param date_col The name of the column containing date information. Default is `date_col`.
#' @param year_col The name of the column containing year information. Default is `year_col`.
#' @param station_col The name of the column containing station information. If missing, assigns the `Station` column from metadata.
#' @param Misscode A value representing missing data in the dataset.
#' @param Tracecode A value representing trace amounts of the climatic element.
#' @param Zerocode A value representing zero values for the climatic element.
#' @param monstats A vector of summary statistics to calculate for monthly data. Options include `"min"`, `"mean"`, `"median"`, `"max"`, `"IQR"`, and `"sum"`.
#'
#' @return A data frame displaying the daily summary table for the specified climatic element.
display_daily_table = function(data_name, climatic_element, date_col = date_col, year_col = year_col, station_col = station_col, Misscode, Tracecode, Zerocode, monstats = c("min", "mean", "median", "max", "IQR", "sum")) {
self$get_data_objects(data_name)$display_daily_table(data_name = data_name, climatic_element = climatic_element, date_col = date_col, year_col =year_col, station_col = station_col, Misscode = Misscode, Tracecode = Tracecode, Zerocode = Zerocode, monstats = monstats)
},

#' @title Import SST
#' @description Imports SST data and adds keys and links to the specified data tables.
#' @param dataset The SST dataset.
#' @param data_from The source of the data. Default is 5.
#' @param data_names A vector of data table names.
#' @return None
import_SST = function(dataset, data_from = 5, data_names = c()) {
import_SST = function(dataset, data_from = 5, data_names = c()) {
data_list <- convert_SST(dataset, data_from)
if(length(data_list) != length(data_names)) stop("data_names vector should be of length 2")
names(data_list) = data_names
Expand Down
28 changes: 27 additions & 1 deletion R/data_sheet.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
#' \item{\code{replace_values_with_NA(row_index, column_index)}}{Replaces values with NA in the specified rows and columns.}
#' \item{\code{set_options_by_context_types(obyc_types = NULL, key_columns = NULL)}}{Set options by context types for the current data sheet.}
#' \item{\code{has_labels(col_names)}}{Checks if the specified columns have labels.}
#' \item{\code{display_daily_table(data_name, climatic_element, date_col = date_col, year_col = year_col, station_col = station_col, Misscode, Tracecode, Zerocode, monstats = c("min", "mean", "median", "max", "IQR", "sum"))}}{Display a daily summary table for a specified climatic data element.}
#' }
#'
#' @section Active bindings:
Expand Down Expand Up @@ -5071,8 +5072,33 @@ DataSheet <- R6::R6Class(
has_labels = function(col_names) {
if(missing(col_names)) stop("Column name must be specified.")
return(!is.null(attr(col_names, "labels")))
}
},

#' @description
#' Display a daily summary table for a specified climatic data element.
#'
#' @param data_name A character string representing the name of the dataset.
#' @param climatic_element A vector specifying the climatic elements to be displayed (e.g., temperature, rainfall).
#' @param date_col The name of the column containing date information. Default is `date_col`.
#' @param year_col The name of the column containing year information. Default is `year_col`.
#' @param station_col The name of the column containing station information. If missing, assigns the `Station` column from metadata.
#' @param Misscode A value representing missing data in the dataset.
#' @param Tracecode A value representing trace amounts of the climatic element.
#' @param Zerocode A value representing zero values for the climatic element.
#' @param monstats A vector of summary statistics to calculate for monthly data. Options include `"min"`, `"mean"`, `"median"`, `"max"`, `"IQR"`, and `"sum"`.
#'
#' @return A data frame displaying the daily summary table for the specified climatic element.
#'
#' @details
#' This function retrieves the data frame associated with the specified dataset and renames columns to standardise `Date`, `Year`, and `Station` for ease of processing. It then displays a daily summary table using the specified climatic elements, handling missing codes, trace codes, and zero codes as defined. Monthly statistics are calculated based on the `monstats` argument.
display_daily_table = function(data_name, climatic_element, date_col = date_col, year_col = year_col, station_col = station_col, Misscode, Tracecode, Zerocode, monstats = c("min", "mean", "median", "max", "IQR", "sum")) {
curr_data <- self$get_data_frame()
if(missing(station_col)) curr_data[["Station"]] <- self$get_metadata(data_name_label)
else names(curr_data)[names(curr_data) == station_col] <- "Station"
names(curr_data)[names(curr_data) == date_col] <- "Date"
names(curr_data)[names(curr_data) == year_col] <- "Year"
return(DisplayDaily(Datain = curr_data, Variables = climatic_element, option = 1, Misscode = Misscode, Tracecode = Tracecode, Zerocode = Zerocode, monstats = monstats))
}

),

Expand Down
22 changes: 22 additions & 0 deletions man/DataBook.Rd

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

50 changes: 50 additions & 0 deletions man/DataSheet.Rd

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

59 changes: 59 additions & 0 deletions man/DisplayDaily.Rd

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

0 comments on commit 8f3ebcb

Please sign in to comment.