From 214ae6449ee0d1aace8e176456f0060543fb064a Mon Sep 17 00:00:00 2001 From: lilyclements Date: Fri, 1 Nov 2024 17:07:43 +0000 Subject: [PATCH 1/4] fix warnings --- NAMESPACE | 1 - R/DisplayDaily.R | 4 +- R/data_book.R | 4401 +--------------------------------- man/DataBook.Rd | 5971 +++------------------------------------------- 4 files changed, 350 insertions(+), 10027 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 3538b60..11a3cef 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,7 +1,6 @@ # Generated by roxygen2: do not edit by hand export("%>%") -export(DataBook) export(DataSheet) export(instat_comment) export(link) diff --git a/R/DisplayDaily.R b/R/DisplayDaily.R index 9b2de0a..3641283 100644 --- a/R/DisplayDaily.R +++ b/R/DisplayDaily.R @@ -310,13 +310,13 @@ DisplayDaily <- function(Datain,Stations,Variables,option=1,Years,Misscode,Trace cat(paste("VARIABLE : '",Variables[v],"'",sep=""),"\n",file=fileoutput,sep="") cat(paste("YEAR :",Years[y]),"\n",file=fileoutput,sep="") cat(paste(names(out)),"\n",file=fileoutput,sep="\t") - write.table(out,file=fileoutput,sep="\t",append=TRUE,quote=FALSE,col.names=FALSE,row.names=FALSE) + utils::write.table(out,file=fileoutput,sep="\t",append=TRUE,quote=FALSE,col.names=FALSE,row.names=FALSE) }else{ cat("\n",paste("STATION : '",Stations[s],"'",sep=""),"\n",file=fileoutput,sep="") cat(paste("VARIABLE : '",Variables[v],"'",sep=""),"\n",file=fileoutput,sep="") cat(paste("YEAR :",Years[y]),"\n",file=fileoutput,sep="") cat(paste(names(out)),"\n",file=fileoutput,sep="\t") - write.table(out,file=fileoutput,sep="\t",append=TRUE,quote=FALSE,col.names=FALSE,row.names=FALSE) + utils::write.table(out,file=fileoutput,sep="\t",append=TRUE,quote=FALSE,col.names=FALSE,row.names=FALSE) } } rm(tmp2) diff --git a/R/data_book.R b/R/data_book.R index 2fb121f..76aeab7 100644 --- a/R/data_book.R +++ b/R/data_book.R @@ -1,10 +1,11 @@ -#' DataBook Class +#' @title DataBook Class #' -#' An R6 class to manage a collection of data tables along with their metadata and other associated properties. +#' @description An R6 class to manage a collection of data tables along with their metadata and other associated properties. #' #' @name DataBook #' @docType class #' @format An R6 class object. +#' @aliases DataBook DataBook$new DataBook$ #' @usage DataBook$new(data_tables = list(), instat_obj_metadata = list(), #' data_tables_variables_metadata = rep(list(data.frame()), length(data_tables)), #' data_tables_metadata = rep(list(list()), length(data_tables)), @@ -233,6 +234,7 @@ #' @export DataBook <- R6::R6Class("DataBook", public = list( + #' Initialise for Public List #' @description #' Initialize a new DataBook object. #' @param data_tables A list of data frames to be included in the DataBook. @@ -1896,7 +1898,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$convert_column_to_type(col_names = col_names, to_type = to_type, factor_values = factor_values, set_digits = set_digits, set_decimals = set_decimals, keep_attr = keep_attr, ignore_labels = ignore_labels, keep.labels = keep.labels) }, - #' @title Append Property to Variables Metadata + #' Append Property to Variables Metadata #' @description Appends a new property and its value to the metadata of specified columns in a data table. #' @param data_name The name of the data table. #' @param col_names A vector of column names to which the property should be appended. @@ -1907,7 +1909,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$append_to_variables_metadata(col_names, property, new_val) }, - #' @title Append Property to Dataframe Metadata + #' Append Property to Dataframe Metadata #' @description Appends a new property and its value to the metadata of a data table. #' @param data_name The name of the data table. #' @param property The name of the property to append. @@ -1917,7 +1919,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$append_to_metadata(property, new_val) }, - #' @title Append Property to Metadata + #' Append Property to Metadata #' @description Appends a new property and its value to the metadata of the current object. #' @param property The name of the property to append. #' @param new_val The value of the property to append. Default is an empty string. @@ -1934,7 +1936,7 @@ DataBook <- R6::R6Class("DataBook", } }, - #' @title Add Metadata Field + #' Add Metadata Field #' @description Adds a new metadata field and its value to the specified data table or all data tables. #' @param data_name The name of the data table. Use overall_label to apply to all data tables. #' @param property The name of the property to append. @@ -1949,7 +1951,7 @@ DataBook <- R6::R6Class("DataBook", } }, - #' @title Reorder Dataframes + #' Reorder Dataframes #' @description Reorders the dataframes in the object according to the specified order. #' @param data_frames_order A vector specifying the new order of dataframes. #' @return None @@ -1960,7 +1962,7 @@ DataBook <- R6::R6Class("DataBook", self$data_objects_changed <- TRUE }, - #' @title Copy Columns + #' Copy Columns #' @description Copies specified columns from a data table to another location or clipboard. #' @param data_name The name of the data table. #' @param col_names A vector of column names to copy. @@ -1975,7 +1977,7 @@ DataBook <- R6::R6Class("DataBook", } }, - #' @title Drop Unused Factor Levels + #' Drop Unused Factor Levels #' @description Drops unused levels from a factor column in the specified data table. #' @param data_name The name of the data table. #' @param col_name The name of the column. @@ -1984,7 +1986,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$drop_unused_factor_levels(col_name = col_name) }, - #' @title Set Factor Levels + #' Set Factor Levels #' @description Sets new levels for a factor column in the specified data table. #' @param data_name The name of the data table. #' @param col_name The name of the column. @@ -1996,7 +1998,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$set_factor_levels(col_name = col_name, new_labels = new_labels, new_levels = new_levels, set_new_labels = set_new_labels) }, - #' @title Edit Factor Level + #' Edit Factor Level #' @description Edits a level in a factor column in the specified data table. #' @param data_name The name of the data table. #' @param col_name The name of the column. @@ -2007,7 +2009,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$edit_factor_level(col_name = col_name, old_level = old_level, new_level = new_level) }, - #' @title Set Factor Reference Level + #' Set Factor Reference Level #' @description Sets the reference level for a factor column in the specified data table. #' @param data_name The name of the data table. #' @param col_name The name of the column. @@ -2017,7 +2019,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$set_factor_reference_level(col_name = col_name, new_ref_level = new_ref_level) }, - #' @title Get Column Count + #' Get Column Count #' @description Returns the number of columns in the specified data table. #' @param data_name The name of the data table. #' @param use_column_selection Boolean flag to use column selection. Default is FALSE. @@ -2026,7 +2028,7 @@ DataBook <- R6::R6Class("DataBook", return(self$get_data_objects(data_name)$get_column_count(use_column_selection)) }, - #' @title Reorder Factor Levels + #' Reorder Factor Levels #' @description Reorders the levels of a factor column in the specified data table. #' @param data_name The name of the data table. #' @param col_name The name of the column. @@ -2036,7 +2038,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$reorder_factor_levels(col_name = col_name, new_level_names = new_level_names) }, - #' @title Get Data Type + #' Get Data Type #' @description Returns the data type of the specified column in the given data table. #' @param data_name The name of the data table. #' @param col_name The name of the column. @@ -2045,7 +2047,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$get_data_type(col_name = col_name) }, - #' @title Copy Data Frame + #' Copy Data Frame #' @description Copies a data frame to a new name or clipboard. #' @param data_name The name of the data table. #' @param new_name The new name for the copied data frame. @@ -2070,7 +2072,7 @@ DataBook <- R6::R6Class("DataBook", } }, - #' @title Copy Column Metadata to Clipboard + #' Copy Column Metadata to Clipboard #' @description Copies the metadata of specified columns to the clipboard. #' @param data_name The name of the data table. #' @param property_names A vector of property names to copy. Default is all properties. @@ -2083,7 +2085,7 @@ DataBook <- R6::R6Class("DataBook", } }, - #' @title Copy Data Frame Metadata to Clipboard + #' Copy Data Frame Metadata to Clipboard #' @description Copies the metadata of the specified data table to the clipboard. #' @param data_name The name of the data table. #' @param property_names A vector of property names to copy. Default is all properties. @@ -2096,7 +2098,7 @@ DataBook <- R6::R6Class("DataBook", } }, - #' @title Copy to Clipboard + #' Copy to Clipboard #' @description Copies the specified content to the clipboard. #' @param content The content to copy to the clipboard. #' @return None @@ -2104,7 +2106,7 @@ DataBook <- R6::R6Class("DataBook", clipr::write_clip(content = content) }, - #' @title Set Hidden Columns + #' Set Hidden Columns #' @description Sets the specified columns as hidden in the given data table. #' @param data_name The name of the data table. #' @param col_names A vector of column names to set as hidden. @@ -2113,7 +2115,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$set_hidden_columns(col_names = col_names) }, - #' @title Unhide All Columns + #' Unhide All Columns #' @description Unhides all columns in the specified data table or all data tables if data_name is missing. #' @param data_name The name of the data table. If missing, applies to all data tables. #' @return None @@ -2125,7 +2127,7 @@ DataBook <- R6::R6Class("DataBook", } }, - #' @title Set Hidden Data Frames + #' Set Hidden Data Frames #' @description Sets the specified data tables as hidden. #' @param data_names A vector of data table names to set as hidden. #' @return None @@ -2135,7 +2137,7 @@ DataBook <- R6::R6Class("DataBook", invisible(sapply(unhide_data_names, function(x) self$append_to_dataframe_metadata(data_name = x, property = is_hidden_label, new_val = FALSE))) }, - #' @title Get Hidden Data Frames + #' Get Hidden Data Frames #' @description Returns a list of hidden data tables. #' @return A vector of hidden data table names. get_hidden_data_frames = function() { @@ -2145,7 +2147,7 @@ DataBook <- R6::R6Class("DataBook", return(hidden_data_names) }, - #' @title Set Row Names + #' Set Row Names #' @description Sets the row names for the specified data table. #' @param data_name The name of the data table. #' @param row_names A vector of row names to set. @@ -2154,7 +2156,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$set_row_names(row_names = row_names) }, - #' @title Get Row Names + #' Get Row Names #' @description Returns the row names of the specified data table. #' @param data_name The name of the data table. #' @return A vector of row names. @@ -2162,7 +2164,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$get_row_names() }, - #' @title Set Protected Columns + #' Set Protected Columns #' @description Sets the specified columns as protected in the given data table. #' @param data_name The name of the data table. #' @param col_names A vector of column names to set as protected. @@ -2171,7 +2173,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$set_protected_columns(col_names = col_names) }, - #' @title Get Metadata Fields + #' Get Metadata Fields #' @description Returns the metadata fields of the specified data table. #' @param data_name The name of the data table. #' @param include_overall Boolean flag to include overall metadata fields. Default is TRUE. @@ -2208,7 +2210,7 @@ DataBook <- R6::R6Class("DataBook", } }, - #' @title Freeze Columns + #' Freeze Columns #' @description Freezes the specified columns in the given data table. #' @param data_name The name of the data table. #' @param column A vector of column names to freeze. @@ -2217,7 +2219,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$freeze_columns(column = column) }, - #' @title Unfreeze Columns + #' Unfreeze Columns #' @description Unfreezes all columns in the specified data table. #' @param data_name The name of the data table. #' @return None @@ -2225,7 +2227,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$unfreeze_columns() }, - #' @title Is Variables Metadata + #' Is Variables Metadata #' @description Checks if the specified property is metadata for the given columns in the data table. #' @param data_name The name of the data table. #' @param property The name of the property to check. @@ -2236,7 +2238,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$is_variables_metadata(property, column, return_vector) }, - #' @title Data Frame Exists + #' Data Frame Exists #' @description Checks if the specified data table exists. #' @param data_name The name of the data table. #' @return A boolean value indicating if the data table exists. @@ -2244,7 +2246,7 @@ DataBook <- R6::R6Class("DataBook", return(data_name %in% names(private$.data_sheets)) }, - #' @title Add Key + #' Add Key #' @description Adds a key to the specified columns in the given data table. #' @param data_name The name of the data table. #' @param col_names A vector of column names to add as keys. @@ -2257,7 +2259,7 @@ DataBook <- R6::R6Class("DataBook", invisible(sapply(self$get_data_objects(), function(x) if(!x$is_metadata(is_linkable)) x$append_to_metadata(is_linkable, FALSE))) }, - #' @title Is Key + #' Is Key #' @description Checks if the specified columns are keys in the given data table. #' @param data_name The name of the data table. #' @param col_names A vector of column names to check. @@ -2266,7 +2268,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$is_key(col_names) }, - #' @title Has Key + #' Has Key #' @description Checks if the specified data table has a key. #' @param data_name The name of the data table. #' @return A boolean value indicating if the data table has a key. @@ -2274,7 +2276,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$has_key() }, - #' @title Get Keys + #' Get Keys #' @description Returns the keys of the specified data table. #' @param data_name The name of the data table. #' @param key_name The name of the key. Default is all keys. @@ -2283,7 +2285,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$get_keys(key_name) }, - #' @title Add New Comment + #' Add New Comment #' @description Adds a new comment to the specified row and column in the given data table. #' @param data_name The name of the data table. #' @param row The name of the row. @@ -2324,7 +2326,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(".comment")$set_data(new_data = comment_df) }, - #' @title Get Comments + #' Get Comments #' @description Returns the comments for the specified data table and comment ID. #' @param data_name The name of the data table. #' @param comment_id The ID of the comment. @@ -2333,7 +2335,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$get_comments(comment_id) }, - #' @title Get Links + #' Get Links #' @description Returns the links for the specified link name or all links. #' @param link_name The name of the link. Default is all links. #' @return A list of links. @@ -2346,7 +2348,7 @@ DataBook <- R6::R6Class("DataBook", } }, - #' @title Set Structure Columns + #' Set Structure Columns #' @description Sets the structure columns for the specified data table. #' @param data_name The name of the data table. #' @param struc_type_1 A vector of column names for the first structure type. @@ -2357,7 +2359,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$set_structure_columns(struc_type_1, struc_type_2, struc_type_3) }, - #' @title Add Dependent Columns + #' Add Dependent Columns #' @description Adds dependent columns to the specified columns in the given data table. #' @param data_name The name of the data table. #' @param columns A vector of column names to add dependents to. @@ -2367,7 +2369,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$add_dependent_columns(columns, dependent_cols) }, - #' @title Set Column Colours + #' Set Column Colours #' @description Sets the colours for the specified columns in the given data table. #' @param data_name The name of the data table. #' @param columns A vector of column names to set colours for. @@ -2377,7 +2379,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$set_column_colours(columns, colours) }, - #' @title Has Colours + #' Has Colours #' @description Checks if the specified columns have colours in the given data table. #' @param data_name The name of the data table. #' @param columns A vector of column names to check. @@ -2386,7 +2388,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$has_colours(columns) }, - #' @title Remove Column Colours + #' Remove Column Colours #' @description Removes the colours from all columns in the specified data table. #' @param data_name The name of the data table. #' @return None @@ -2394,7 +2396,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$remove_column_colours() }, - #' @title Set Column Colours by Metadata + #' Set Column Colours by Metadata #' @description Sets the colours for the specified columns based on metadata in the given data table. #' @param data_name The name of the data table. #' @param columns A vector of column names to set colours for. @@ -2404,7 +2406,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$set_column_colours_by_metadata(data_name, columns, property) }, - #' @title Graph One Variable + #' Graph One Variable #' @description Creates a graph for a single variable in the specified data table. #' @param data_name The name of the data table. #' @param columns A vector of column names to graph. @@ -2421,7 +2423,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$graph_one_variable(columns = columns, numeric = numeric, categorical = categorical, output = output, free_scale_axis = free_scale_axis, ncol = ncol, coord_flip = coord_flip, ... = ...) }, - #' @title Make Date YearMonthDay + #' Make Date YearMonthDay #' @description Creates a date column from year, month, and day columns in the specified data table. #' @param data_name The name of the data table. #' @param year The name of the year column. @@ -2437,7 +2439,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$make_date_yearmonthday(year = year, month = month, day = day, f_year = f_year, f_month = f_month, f_day = f_day, year_format = year_format, month_format = month_format) }, - #' @title Make Date YearDoY + #' Make Date YearDoY #' @description Creates a date column from year and day of year columns in the specified data table. #' @param data_name The name of the data table. #' @param year The name of the year column. @@ -2449,7 +2451,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$make_date_yeardoy(year = year, doy = doy, base = base, doy_typical_length = doy_typical_length) }, - #' @title Set Contrasts of Factor + #' Set Contrasts of Factor #' @description Sets the contrasts for a factor column in the specified data table. #' @param data_name The name of the data table. #' @param col_name The name of the column. @@ -2460,7 +2462,7 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$set_contrasts_of_factor(col_name = col_name, new_contrasts = new_contrasts, defined_contr_matrix = defined_contr_matrix) }, - #' @title Create Factor Data Frame + #' Create Factor Data Frame #' @description Creates a new data frame for a factor column in the specified data table. #' @param data_name The name of the data table. #' @param factor The name of the factor column. @@ -2505,7 +2507,7 @@ DataBook <- R6::R6Class("DataBook", self$add_link(from_data_frame = data_name, to_data_frame = factor_data_frame_name, link_pairs = factor, type = keyed_link_label) }, - #' @title Split Date + #' Split Date #' @description Splits a date column into multiple date components in the specified data table. #' @param data_name The name of the data table. #' @param col_name The name of the date column. @@ -4322,4297 +4324,6 @@ DataBook <- R6::R6Class("DataBook", return(self$get_data_objects(data_name)$get_comments_as_data_frame()) }, - #' @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()) { - 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 - self$import_data(data_list) - self$add_key(data_names[1], c("Lon", "Lat", "Year", "Month", "Day"), "key1") - self$add_key(data_names[2], c("Lon", "Lat"), "key2") - link_pairs = c("Lon", "Lat") - names(link_pairs) = c("Lon", "Lat") - self$add_link(from_data_frame = data_names[1], to_data_frame = data_names[2], link_pairs = link_pairs, type = keyed_link_label) - } - - ), - private = list( - .data_sheets = list(), - .metadata = list(), - .objects = list(), - .links = list(), - .data_sheets_changed = FALSE, - .database_connection = NULL, - .last_graph = NULL - ), - active = list( - #' @field data_objects_changed Logical indicating whether the data objects have changed. - data_objects_changed = function(new_value) { - if (missing(new_value)) return(private$.data_sheets_changed) - else { - if (new_value != TRUE && new_value != FALSE) stop("new_value must be TRUE or FALSE") - private$.data_sheets_changed <- new_value - invisible(sapply(self$get_data_objects(), function(x) x$data_changed <- new_value)) - } - } - ) -) -#' DataBook Class -#' -#' An R6 class to manage a collection of data tables along with their metadata and other associated properties. -#' -#' @name DataBook -#' @docType class -#' @format An R6 class object. -#' @usage DataBook$new(data_tables = list(), instat_obj_metadata = list(), -#' data_tables_variables_metadata = rep(list(data.frame()), length(data_tables)), -#' data_tables_metadata = rep(list(list()), length(data_tables)), -#' data_tables_filters = rep(list(list()), length(data_tables)), -#' data_tables_column_selections = rep(list(list()), length(data_tables)), -#' imported_from = as.list(rep("", length(data_tables))), -#' messages = TRUE, convert = TRUE, create = TRUE) -#' -#' @section Methods: -#' \describe{ -#' \item{\code{set_data(new_data, messages, check_names)}}{Sets the data for the DataSheet object.} -#' \item{\code{standardise_country_names(data_name, country_columns = c())}}{Standardizes country names in the specified data table.} -#' \item{\code{define_as_climatic(data_name, types, key_col_names, key_name)}}{Defines a data table as climatic data.} -#' \item{\code{define_corruption_outputs(data_name, output_columns = c())}}{Defines corruption output columns in the specified data table.} -#' \item{\code{define_red_flags(data_name, red_flags = c())}}{Defines red flag columns in the specified data table.} -#' \item{\code{define_as_procurement(data_name, primary_types = c(), calculated_types = c(), country_data_name, country_types, auto_generate = TRUE)}}{Defines a data table as procurement data.} -#' \item{\code{define_as_procurement_country_level_data(data_name, contract_level_data_name, types = c(), auto_generate = TRUE)}}{Defines a data table as procurement country-level data.} -#' \item{\code{get_CRI_component_column_names(data_name)}}{Gets the names of CRI component columns in the specified data table.} -#' \item{\code{get_red_flag_column_names(data_name)}}{Gets the names of red flag columns in the specified data table.} -#' \item{\code{get_CRI_column_names(data_name)}}{Gets the names of CRI columns in the specified data table.} -#' \item{\code{get_corruption_column_name(data_name, type)}}{Gets the name of the corruption column in the specified data table.} -#' \item{\code{import_data(data_tables = list(), data_tables_variables_metadata = rep(list(data.frame()),length(data_tables)), data_tables_metadata = rep(list(list()),length(data_tables)), data_tables_filters = rep(list(list()),length(data_tables)), data_tables_column_selections = rep(list(list()),length(data_tables)), imported_from = as.list(rep("",length(data_tables))), data_names = NULL, messages=TRUE, convert=TRUE, create=TRUE, prefix=TRUE, add_to_graph_book = TRUE)}}{Imports data into the DataBook from a list of data tables and their metadata.} -#' \item{\code{replace_instat_object(new_instat_object)}}{Replaces the current instat object with a new one.} -#' \item{\code{set_data_objects(new_data_objects)}}{Sets the data objects for the DataBook.} -#' \item{\code{copy_data_object(data_name, new_name, filter_name = "", column_selection_name = "", reset_row_names = TRUE)}}{Copies a data object with optional filtering and column selection.} -#' \item{\code{import_RDS(data_RDS, keep_existing = TRUE, overwrite_existing = FALSE, include_objects = TRUE, include_metadata = TRUE, include_logs = TRUE, include_filters = TRUE, include_column_selections = TRUE, include_calculations = TRUE, include_comments = TRUE)}}{Imports data from an RDS file into the DataBook.} -#' \item{\code{clone_data_object(curr_data_object, include_objects = TRUE, include_metadata = TRUE, include_logs = TRUE, include_filters = TRUE, include_column_selections = TRUE, include_calculations = TRUE, include_comments = TRUE, ...)}}{Clones a data object with options to include various components.} -#' \item{\code{clone_instat_calculation(curr_instat_calculation, ...)}}{Clones an instat calculation.} -#' \item{\code{import_from_ODK(username, form_name, platform)}}{Imports data from ODK (Open Data Kit).} -#' \item{\code{set_meta(new_meta)}}{Sets the metadata for the DataBook.} -#' \item{\code{set_objects(new_objects)}}{Sets the objects for the DataBook.} -#' \item{\code{append_data_object(name, obj, add_to_graph_book = TRUE)}}{Appends a data object to the DataBook.} -#' \item{\code{get_data_objects(data_name, as_list = FALSE, ...)}}{Gets data objects from the DataBook.} -#' \item{\code{get_data_frame(data_name, convert_to_character = FALSE, stack_data = FALSE, include_hidden_columns = TRUE, use_current_filter = TRUE, filter_name = "", use_column_selection = TRUE, column_selection_name = "", remove_attr = FALSE, retain_attr = FALSE, max_cols, max_rows, drop_unused_filter_levels = FALSE, start_row, start_col, ...)}}{Gets a data frame from the DataBook with various options.} -#' \item{\code{get_variables_metadata(data_name, data_type = "all", convert_to_character = FALSE, property, column, error_if_no_property = TRUE, direct_from_attributes = FALSE, use_column_selection = TRUE)}}{Gets the variables metadata for the specified data table.} -#' \item{\code{get_column_data_types(data_name, columns)}}{Gets the data types of the specified columns in the data table.} -#' \item{\code{get_column_labels(data_name, columns)}}{Gets the labels of the specified columns in the data table.} -#' \item{\code{get_data_frame_label(data_name, use_current_filter = FALSE)}}{Gets the label of the data frame.} -#' \item{\code{get_data_frame_metadata(data_name, label, include_calculated = TRUE, excluded_not_for_display = TRUE)}}{Gets the metadata of the data frame.} -#' \item{\code{get_combined_metadata(convert_to_character = FALSE)}}{Gets combined metadata from all data tables.} -#' \item{\code{get_metadata(name, ...)}}{Gets metadata for the specified name.} -#' \item{\code{get_data_names(as_list = FALSE, include, exclude, excluded_items, include_hidden = TRUE, ...)}}{Gets the names of the data tables in the DataBook.} -#' \item{\code{get_data_changed(data_name)}}{Checks if the data has changed.} -#' \item{\code{get_variables_metadata_changed(data_name)}}{Checks if the variables metadata has changed.} -#' \item{\code{get_metadata_changed(data_name)}}{Checks if the metadata has changed.} -#' \item{\code{get_calculations(data_name)}}{Gets the calculations for the specified data table.} -#' \item{\code{get_calculation_names(data_name, as_list = FALSE, excluded_items = c())}}{Gets the names of the calculations for the specified data table.} -#' \item{\code{dataframe_count()}}{Gets the count of data frames in the DataBook.} -#' \item{\code{set_data_frames_changed(data_name = "", new_val)}}{Sets the changed status for data frames.} -#' \item{\code{set_variables_metadata_changed(data_name = "", new_val)}}{Sets the changed status for variables metadata.} -#' \item{\code{set_metadata_changed(data_name = "", new_val)}}{Sets the changed status for metadata.} -#' \item{\code{add_columns_to_data(data_name, col_name = "", col_data, use_col_name_as_prefix = FALSE, hidden = FALSE, before, adjacent_column = "", num_cols, require_correct_length = TRUE, keep_existing_position = TRUE)}}{Adds columns to the specified data table.} -#' \item{\code{get_columns_from_data(data_name, col_names, from_stacked_data = FALSE, force_as_data_frame = FALSE, use_current_filter = TRUE, remove_labels = FALSE, drop_unused_filter_levels = FALSE)}}{Gets columns from the specified data table.} -#' \item{\code{create_graph_data_book()}}{Creates a graph data book.} -#' \item{\code{add_object(data_name = NULL, object_name = NULL, object_type_label, object_format, object)}}{Adds an object to the DataBook.} -#' \item{\code{get_object_names(data_name = NULL, object_type_label = NULL, as_list = FALSE, ...)}}{Gets the names of the objects in the DataBook.} -#' \item{\code{get_objects(data_name = NULL, object_type_label = NULL)}}{Gets the objects from the DataBook.} -#' \item{\code{get_object(data_name = NULL, object_name)}}{Gets a specific object from the DataBook.} -#' \item{\code{get_object_data(data_name = NULL, object_name, as_file = FALSE)}}{Gets the data of a specific object from the DataBook.} -#' \item{\code{get_objects_data(data_name = NULL, object_names = NULL, as_files = FALSE)}}{Gets the data of multiple objects from the DataBook.} -#' \item{\code{get_last_object_data(object_type_label, as_file = TRUE)}}{Gets the data of the last object of a specified type from the DataBook.} -#' \item{\code{rename_object(data_name, object_name, new_name, object_type = "object")}}{Renames an object in the DataBook.} -#' \item{\code{delete_objects(data_name, object_names, object_type = "object")}}{Deletes objects from the DataBook.} -#' \item{\code{reorder_objects(data_name, new_order)}}{Reorders the objects in the DataBook.} -#' \item{\code{get_from_object(data_name, object_name, value1, value2, value3)}}{Gets values from a specified object in the DataBook.} -#' \item{\code{add_filter(data_name, filter, filter_name = "", replace = TRUE, set_as_current_filter = FALSE, na.rm = TRUE, is_no_filter = FALSE, and_or = "&", inner_not = FALSE, outer_not = FALSE)}}{Adds a filter to the specified data table.} -#' \item{\code{add_filter_as_levels(data_name, filter_levels, column)}}{Adds filter levels to the specified column.} -#' \item{\code{current_filter(data_name)}}{Gets the current filter for the specified data table.} -#' \item{\code{set_current_filter(data_name, filter_name = "")}}{Sets the current filter for the specified data table.} -#' \item{\code{get_filter(data_name, filter_name)}}{Gets a filter by name from the specified data table.} -#' \item{\code{get_filter_as_logical(data_name, filter_name)}}{Gets a filter as a logical vector from the specified data table.} -#' \item{\code{get_current_filter(data_name)}}{Gets the current filter for the specified data table.} -#' \item{\code{get_filter_row_names(data_name, filter_name)}}{Gets the row names that match a specified filter in the data table.} -#' \item{\code{get_current_filter_name(data_name)}}{Gets the name of the current filter for the specified data table.} -#' \item{\code{get_filter_names(data_name, as_list = FALSE, include = list(), exclude = list(), excluded_items = c())}}{Gets the names of the filters in the specified data table.} -#' \item{\code{remove_current_filter(data_name)}}{Removes the current filter from the specified data table.} -#' \item{\code{filter_applied(data_name)}}{Checks if a filter is applied to the specified data table.} -#' \item{\code{filter_string(data_name, filter_name)}}{Gets the filter string for a specified filter in the data table.} -#' \item{\code{get_filter_as_instat_calculation(data_name, filter_name)}}{Gets a filter as an instat calculation from the specified data table.} -#' \item{\code{add_column_selection(data_name, column_selection, name = "", replace = TRUE, set_as_current = FALSE, is_everything = FALSE, and_or = "|")}}{Adds a column selection to the specified data table.} -#' \item{\code{current_column_selection(data_name)}}{Gets the current column selection for the specified data table.} -#' \item{\code{set_current_column_selection(data_name, name = "")}}{Sets the current column selection for the specified data table.} -#' \item{\code{get_column_selection(data_name, name)}}{Gets a column selection by name from the specified data table.} -#' \item{\code{get_column_selection_column_names(data_name, filter_name)}}{Gets the column names for a specified filter in the data table.} -#' \item{\code{get_column_selected_column_names(data_name, column_selection_name = "")}}{Gets the names of the selected columns in the specified data table.} -#' \item{\code{get_current_column_selection(data_name)}}{Gets the current column selection for the specified data table.} -#' \item{\code{get_current_column_selection_name(data_name)}}{Gets the name of the current column selection for the specified data table.} -#' \item{\code{get_column_selection_names(data_name, as_list = FALSE, include = list(), exclude = list(), excluded_items = c())}}{Gets the names of the column selections in the specified data table.} -#' \item{\code{remove_current_column_selection(data_name)}}{Removes the current column selection from the specified data table.} -#' \item{\code{column_selection_applied(data_name)}}{Checks if a column selection is applied to the specified data table.} -#' \item{\code{replace_value_in_data(data_name, col_names, rows, old_value, old_is_missing = FALSE, start_value = NA, end_value = NA, new_value, new_is_missing = FALSE, closed_start_value = TRUE, closed_end_value = TRUE, locf = FALSE, from_last = FALSE)}}{Replaces values in the specified columns and rows of the data table.} -#' \item{\code{paste_from_clipboard(data_name, col_names, start_row_pos = 1, first_clip_row_is_header = TRUE, clip_board_text)}}{Pastes data from the clipboard into the specified columns of the data table.} -#' \item{\code{rename_column_in_data(data_name, column_name = NULL, new_val = NULL, label = "", type = "single", .fn, .cols = everything(), new_column_names_df, new_labels_df, ...)}}{Renames a column in the specified data table.} -#' \item{\code{frequency_tables(data_name, x_col_names, y_col_name, n_column_factors = 1, store_results = TRUE, drop = TRUE, na.rm = FALSE, summary_name = NA, include_margins = FALSE, return_output = TRUE, treat_columns_as_factor = FALSE, page_by = "default", as_html = TRUE, signif_fig = 2, na_display = "", na_level_display = "NA", weights = NULL, caption = NULL, result_names = NULL, percentage_type = "none", perc_total_columns = NULL, perc_total_factors = c(), perc_total_filter = NULL, perc_decimal = FALSE, margin_name = "(All)", additional_filter, ...)}}{Creates frequency tables for the specified data table.} -#' \item{\code{anova_tables(data_name, x_col_names, y_col_name, signif.stars = FALSE, sign_level = FALSE, means = FALSE)}}{Creates ANOVA tables for the specified data table.} -#' \item{\code{cor(data_name, x_col_names, y_col_name, use = "everything", method = c("pearson", "kendall", "spearman"))}}{Calculates correlations for the specified columns in the data table.} -#' \item{\code{remove_columns_in_data(data_name, cols, allow_delete_all = FALSE)}}{Removes columns from the specified data table.} -#' \item{\code{remove_rows_in_data(data_name, row_names)}}{Removes rows from the specified data table.} -#' \item{\code{get_next_default_column_name(data_name, prefix)}}{Gets the next default column name for the specified data table.} -#' \item{\code{get_column_names(data_name, as_list = FALSE, include = list(), exclude = list(), excluded_items = c(), max_no, use_current_column_selection = TRUE)}}{Gets the column names in the specified data table.} -#' \item{\code{reorder_columns_in_data(data_name, col_order)}}{Reorders the columns in the specified data table.} -#' \item{\code{insert_row_in_data(data_name, start_row, row_data = c(), number_rows = 1, before = FALSE)}}{Inserts rows into the specified data table.} -#' \item{\code{get_data_frame_length(data_name, use_current_filter = FALSE)}}{Gets the length of the data frame in the specified data table.} -#' \item{\code{get_next_default_dataframe_name(prefix, include_index = TRUE, start_index = 1)}}{Gets the next default name for a data frame in the DataBook.} -#' \item{\code{delete_dataframes(data_names, delete_graph_book = TRUE)}}{Deletes data frames from the DataBook.} -#' \item{\code{remove_link(link_name)}}{Removes a link from the DataBook.} -#' \item{\code{get_column_factor_levels(data_name, col_name = "")}}{Gets the factor levels of a column in the specified data table.} -#' \item{\code{get_factor_data_frame(data_name, col_name = "", include_levels = TRUE, include_NA_level = FALSE)}}{Gets a factor data frame for the specified column in the data table.} -#' \item{\code{sort_dataframe(data_name, col_names = c(), decreasing = FALSE, na.last = TRUE, by_row_names = FALSE, row_names_as_numeric = TRUE)}}{Sorts the specified data table.} -#' \item{\code{rename_dataframe(data_name, new_value = "", label = "")}}{Renames the specified data table.} -#' \item{\code{convert_column_to_type(data_name, col_names = c(), to_type, factor_values = NULL, set_digits, set_decimals = FALSE, keep_attr = TRUE, ignore_labels = FALSE, keep.labels = TRUE)}}{Converts the specified columns to a different type in the data table.} -#' \item{\code{append_to_variables_metadata(data_name, col_names, property, new_val = "")}}{Appends a new value to the specified property in the variables metadata for the given columns in the specified data table.} -#' \item{\code{append_to_dataframe_metadata(data_name, property, new_val = "")}}{Appends a new value to the specified property in the dataframe metadata for the specified data table.} -#' \item{\code{append_to_metadata(property, new_val = "", allow_override_special = FALSE)}}{Appends a new value to the specified property in the overall metadata, with an option to override special properties.} -#' \item{\code{add_metadata_field(data_name, property, new_val = "")}}{Adds a new metadata field to the specified data table or to the overall metadata.} -#' \item{\code{reorder_dataframes(data_frames_order)}}{Reorders the data frames in the object based on the provided order.} -#' \item{\code{copy_columns(data_name, col_names = "", copy_to_clipboard = FALSE)}}{Copies the specified columns from the given data table, with an option to copy to the clipboard.} -#' \item{\code{drop_unused_factor_levels(data_name, col_name)}}{Drops unused factor levels from the specified column in the given data table.} -#' \item{\code{set_factor_levels(data_name, col_name, new_labels, new_levels, set_new_labels = TRUE)}}{Sets new factor levels and labels for the specified column in the given data table.} -#' \item{\code{edit_factor_level(data_name, col_name, old_level, new_level)}}{Edits an existing factor level in the specified column of the given data table.} -#' \item{\code{set_factor_reference_level(data_name, col_name, new_ref_level)}}{Sets a new reference level for the specified factor column in the given data table.} -#' \item{\code{get_column_count(data_name, use_column_selection = FALSE)}}{Returns the count of columns in the specified data table, with an option to use the current column selection.} -#' \item{\code{reorder_factor_levels(data_name, col_name, new_level_names)}}{Reorders the factor levels in the specified column of the given data table.} -#' \item{\code{get_data_type(data_name, col_name)}}{Returns the data type of the specified column in the given data table.} -#' \item{\code{copy_data_frame(data_name, new_name, label = "", copy_to_clipboard = FALSE)}}{Copies the specified data table to a new data table with an optional new name, label, and option to copy to the clipboard.} -#' \item{\code{copy_col_metadata_to_clipboard(data_name, property_names)}}{Copies the specified column metadata properties from the given data table to the clipboard.} -#' \item{\code{copy_data_frame_metadata_to_clipboard(data_name, property_names)}}{Copies the specified data frame metadata properties from the given data table to the clipboard.} -#' \item{\code{copy_to_clipboard(content)}}{Copies the given content to the clipboard.} -#' \item{\code{set_hidden_columns(data_name, col_names = c())}}{Sets the specified columns in the given data table to be hidden.} -#' \item{\code{unhide_all_columns(data_name)}}{Unhides all columns in the specified data table.} -#' \item{\code{set_hidden_data_frames(data_names = c())}}{Sets the specified data frames to be hidden.} -#' \item{\code{get_hidden_data_frames()}}{Returns the names of all hidden data frames.} -#' \item{\code{set_row_names(data_name, row_names)}}{Sets new row names for the specified data table.} -#' \item{\code{get_row_names(data_name)}}{Returns the row names of the specified data table.} -#' \item{\code{set_protected_columns(data_name, col_names)}}{Sets the specified columns in the given data table to be protected.} -#' \item{\code{get_metadata_fields(data_name, include_overall, as_list = FALSE, include, exclude, excluded_items = c())}}{Returns the metadata fields for the specified data table and overall metadata, with options to include or exclude specific fields.} -#' \item{\code{freeze_columns(data_name, column)}}{Freezes the specified columns in the given data table.} -#' \item{\code{unfreeze_columns(data_name)}}{Unfreezes all columns in the specified data table.} -#' \item{\code{is_variables_metadata(data_name, property, column, return_vector = FALSE)}}{Checks if the specified property is part of the variables metadata for the given column in the specified data table.} -#' \item{\code{data_frame_exists(data_name)}}{Checks if the specified data table exists in the object.} -#' \item{\code{add_key(data_name, col_names, key_name)}}{Adds a key to the specified data table using the given columns and key name.} -#' \item{\code{is_key(data_name, col_names)}}{Checks if the specified columns form a key in the given data table.} -#' \item{\code{has_key(data_name)}}{Checks if the specified data table has a key.} -#' \item{\code{get_keys(data_name, key_name)}}{Returns the keys for the specified data table and key name.} -#' \item{\code{add_new_comment(data_name, row = "", column = "", comment)}}{Adds a new comment to the specified data table, optionally specifying the row and column.} -#' \item{\code{get_comments(data_name, comment_id)}}{Returns the comments for the specified data table and comment ID.} -#' \item{\code{get_links(link_name, ...)}}{Returns the links for the specified link name or all links if no name is provided.} -#' \item{\code{set_structure_columns(data_name, struc_type_1 = c(), struc_type_2 = c(), struc_type_3 = c())}}{Sets the structure columns for the specified data table.} -#' \item{\code{add_dependent_columns(data_name, columns, dependent_cols)}}{Adds dependent columns to the specified columns in the given data table.} -#' \item{\code{set_column_colours(data_name, columns, colours)}}{Sets the colors for the specified columns in the given data table.} -#' \item{\code{has_colours(data_name, columns)}}{Checks if the specified columns in the given data table have colors.} -#' \item{\code{remove_column_colours(data_name)}}{Removes colors from all columns in the specified data table.} -#' \item{\code{set_column_colours_by_metadata(data_name, columns, property)}}{Sets the colors for the specified columns in the given data table based on the specified metadata property.} -#' \item{\code{graph_one_variable(data_name, columns, numeric = "geom_boxplot", categorical = "geom_bar", character = "geom_bar", output = "facets", free_scale_axis = FALSE, ncol = NULL, coord_flip = FALSE, ... = ...)}}{Creates a graph for one variable in the specified data table with options for the type of graph, axis scaling, and other parameters.} -#' \item{\code{make_date_yearmonthday(data_name, year, month, day, f_year, f_month, f_day, year_format = "%Y", month_format = "%m")}}{Creates a date column from the specified year, month, and day columns in the given data table, with options for formatting.} -#' \item{\code{make_date_yeardoy(data_name, year, doy, base, doy_typical_length = "366")}}{Creates a date column from the specified year and day of year columns in the given data table.} -#' \item{\code{set_contrasts_of_factor(data_name, col_name, new_contrasts, defined_contr_matrix)}}{Sets the contrasts for the specified factor column in the given data table.} -#' \item{\code{create_factor_data_frame(data_name, factor, factor_data_frame_name, include_contrasts = FALSE, replace = FALSE, summary_count = TRUE)}}{Creates a new data frame for the specified factor column in the given data table, with options to include contrasts and summary counts.} -#' \item{\code{split_date(data_name, col_name = "", year_val = FALSE, year_name = FALSE, leap_year = FALSE, month_val = FALSE, month_abbr = FALSE, month_name = FALSE, week_val = FALSE, week_abbr = FALSE, week_name = FALSE, weekday_val = FALSE, weekday_abbr = FALSE, weekday_name = FALSE, day = FALSE, day_in_month = FALSE, day_in_year = FALSE, day_in_year_366 = FALSE, pentad_val = FALSE, pentad_abbr = FALSE, dekad_val = FALSE, dekad_abbr = FALSE, quarter_val = FALSE, quarter_abbr = FALSE, with_year = FALSE, s_start_month = 1, s_start_day_in_month = 1, days_in_month = FALSE)}}{Splits the specified date column into multiple components such as year, month, day, etc. in the given data table.} -#' \item{\code{import_SST(dataset, data_from = 5, data_names = c())}}{Imports SST data from the specified dataset and data source, creating data tables with the specified names.} -#' \item{\code{make_inventory_plot(data_name, date_col, station_col = NULL, year_col = NULL, doy_col = NULL, element_cols = NULL, add_to_data = FALSE, year_doy_plot = FALSE, coord_flip = FALSE, facet_by = NULL, graph_title = "Inventory Plot", graph_subtitle = NULL, graph_caption = NULL, title_size = NULL, subtitle_size = NULL, caption_size = NULL, labelXAxis, labelYAxis, xSize = NULL, ySize = NULL, Xangle = NULL, Yangle = NULL, scale_xdate, fromXAxis = NULL, toXAxis = NULL, byXaxis = NULL, date_ylabels, legend_position = NULL, xlabelsize = NULL, ylabelsize = NULL, scale = NULL, dir = "", row_col_number, nrow = NULL, ncol = NULL, key_colours = c("red", "grey"), display_rain_days = FALSE, facet_xsize = 9, facet_ysize = 9, facet_xangle = 90, facet_yangle = 90, scale_ydate = FALSE, date_ybreaks, step = 1, rain_cats = list(breaks = c(0, 0.85, Inf), labels = c("Dry", "Rain"), key_colours = c("tan3", "blue")))}}{Creates an inventory plot for the specified data table with various customisation options.} -#' \item{\code{import_NetCDF(nc, path, name, only_data_vars = TRUE, keep_raw_time = TRUE, include_metadata = TRUE, boundary, lon_points = NULL, lat_points = NULL, id_points = NULL, show_requested_points = TRUE, great_circle_dist = FALSE)}}{Imports data from a NetCDF file, with options to specify the data variables, time format, metadata inclusion, and boundaries.} -#' \item{\code{infill_missing_dates(data_name, date_name, factors, start_month, start_date, end_date, resort = TRUE)}}{Infills missing dates in the specified data table using the provided date column and factors.} -#' \item{\code{get_key_names(data_name, include_overall = TRUE, include, exclude, include_empty = FALSE, as_list = FALSE, excluded_items = c())}}{Returns the key names for the specified data table, with options to include overall keys, exclude specific keys, and return as a list.} -#' \item{\code{remove_key(data_name, key_name)}}{Removes the specified key from the given data table.} -#' \item{\code{add_climdex_indices(data_name, climdex_output, freq = "annual", station, year, month)}}{Adds climdex indices to the specified data table, with options for frequency, station, year, and month.} -#' \item{\code{is_metadata(data_name, str)}}{Checks if the specified string is part of the metadata for the given data table.} -#' \item{\code{get_climatic_column_name(data_name, col_name)}}{Returns the climatic column name for the specified column in the given data table.} -#' \item{\code{merge_data(data_name, new_data, by = NULL, type = "left", match = "all")}}{Merges new data into the specified data table using the provided columns and merge type.} -#' \item{\code{get_corruption_data_names()}}{Returns the names of all data tables with corruption data.} -#' \item{\code{get_corruption_contract_data_names()}}{Returns the names of all data tables with corruption contract data.} -#' \item{\code{get_database_variable_names(query, data_name, include_overall = TRUE, include, exclude, include_empty = FALSE, as_list = FALSE, excluded_items = c())}}{Returns the database variable names for the specified query and data table, with options to include overall variables, exclude specific variables, and return as a list.} -#' \item{\code{get_nc_variable_names(file = "", as_list = FALSE, ...)}}{Returns the variable names from the specified NetCDF file, with an option to return as a list.} -#' \item{\code{has_database_connection()}}{Checks if there is a database connection.} -#' \item{\code{database_connect(dbname, user, host, port, drv = RMySQL::MySQL())}}{Connects to a database using the provided credentials and driver.} -#' \item{\code{get_database_connection()}}{Returns the current database connection.} -#' \item{\code{set_database_connection(dbi_connection)}}{Sets the database connection to the specified DBI connection object.} -#' \item{\code{database_disconnect()}}{Disconnects from the current database.} -#' \item{\code{import_from_climsoft(stationfiltercolumn = "stationId", stations = c(), elementfiltercolumn = "elementId", elements = c(), include_observation_data = FALSE, include_observation_flags = FALSE, unstack_data = FALSE, include_elements_info = FALSE, start_date = NULL, end_date = NULL)}}{Imports data from CLIMSOFT using the specified filters and options for observation data, flags, and unstacking.} -#' \item{\code{import_from_iri(download_from, data_file, data_frame_name, location_data_name, path, X1, X2 = NA, Y1, Y2 = NA, get_area_point = "area")}}{Imports data from IRI using the specified parameters for download, file path, coordinates, and area type.} -#' \item{\code{export_workspace(data_names, file, include_graphs = TRUE, include_models = TRUE, include_metadata = TRUE)}}{Exports the workspace to a file, including the specified data tables, graphs, models, and metadata.} -#' \item{\code{set_links(new_links)}}{Sets the links in the object to the specified new links.} -#' \item{\code{display_daily_graph(data_name, date_col = NULL, station_col = NULL, year_col = NULL, doy_col = NULL, climatic_element = NULL, upper_limit = 100, bar_colour = "blue", rug_colour = "red")}}{Displays a daily graph for the specified data table with options for columns, element, colors, and limits.} -#' \item{\code{create_variable_set(data_name, set_name, columns)}}{Creates a variable set with the specified name and columns in the given data table.} -#' \item{\code{update_variable_set(data_name, set_name, columns, new_set_name)}}{Updates the specified variable set with new columns and optionally a new name in the given data table.} -#' \item{\code{delete_variable_sets(data_name, set_names)}}{Deletes the specified variable sets from the given data table.} -#' \item{\code{get_variable_sets_names(data_name, include_overall = TRUE, include, exclude, include_empty = FALSE, as_list = FALSE, excluded_items = c())}}{Returns the names of variable sets for the specified data table, with options to include overall sets, exclude specific sets, and return as a list.} -#' \item{\code{get_variable_sets(data_name, set_names, force_as_list = FALSE)}}{Returns the specified variable sets from the given data table, with an option to force the result as a list.} -#' \item{\code{crops_definitions(data_name, year, station, rain, day, rain_totals, plant_days, plant_lengths, start_check = TRUE, season_data_name, start_day, end_day, definition_props = TRUE, print_table = TRUE)}}{Defines crop parameters for the specified data table using the provided columns and options for seasons, days, and properties.} -#' \item{\code{tidy_climatic_data(x, format, stack_cols, day, month, year, stack_years, station, element, element_name="value", ignore_invalid = FALSE, silent = FALSE, unstack_elements = TRUE, new_name)}}{Converts wide-format daily climatic data to long format using the specified columns and options for format, elements, and validation.} -#' \item{\code{get_geometry(data)}}{Returns the geometry column for the specified data table.} -#' \item{\code{package_check(package)}}{Checks if the specified package is installed and returns information about its version and availability.} -#' \item{\code{download_from_IRI(source, data, path = tempdir(), min_lon, max_lon, min_lat, max_lat, min_date, max_date, name, download_type = "Point", import = TRUE)}}{Downloads data from IRI using the specified source, data, coordinates, date range, and options for download type and import.} -#' \item{\code{patch_climate_element(data_name, date_col_name = "", var = "", vars = c(), max_mean_bias = NA, max_stdev_bias = NA, time_interval = "month", column_name, station_col_name = station_col_name)}}{Patches the specified climate element in the given data table using the provided columns and options for bias, time interval, and station.} -#' \item{\code{visualize_element_na(data_name, element_col_name, element_col_name_imputed, station_col_name, x_axis_labels_col_name, ncol = 2, type = "distribution", xlab = NULL, ylab = NULL, legend = TRUE, orientation = "horizontal", interval_size = interval_size, x_with_truth = NULL, measure = "percent")}}{Visualizes missing data for the specified element in the given data table using the provided columns and options for labels, legend, orientation, and measure.} -#' \item{\code{get_data_entry_data(data_name, station, date, elements, view_variables, station_name, type, start_date, end_date)}}{Returns data entry data for the specified data table using the provided columns and options for date range, variables, and type.} -#' \item{\code{save_data_entry_data(data_name, new_data, rows_changed, comments_list = list(), add_flags = FALSE, ...)}}{Saves data entry data to the specified data table with options for adding comments, flags, and rows changed.} -#' \item{\code{import_from_cds(user, dataset, elements, start_date, end_date, lon, lat, path, import = FALSE, new_name)}}{Imports data from CDS using the specified user, dataset, elements, date range, coordinates, and options for file path and import.} -#' \item{\code{add_flag_fields(data_name, col_names, key_column_names)}}{Adds flag fields to the specified columns in the given data table, using the provided key columns.} -#' \item{\code{remove_empty(data_name, which = c("rows","cols"))}}{Removes empty rows or columns from the specified data table.} -#' \item{\code{replace_values_with_NA(data_name, row_index, column_index)}}{Replaces values with NA in the specified rows and columns of the given data table.} -#' \item{\code{has_labels(data_name, col_names)}}{Checks if the specified columns in the given data table have labels.} -#' \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.} -#' -#' @export -DataBook <- R6::R6Class("DataBook", - public = list( - #' @description - #' Initialize a new DataBook object. - #' @param data_tables A list of data frames to be included in the DataBook. - #' @param instat_obj_metadata Metadata for the instat object. - #' @param data_tables_variables_metadata A list of data frames, each containing metadata for the corresponding data table. - #' @param data_tables_metadata A list of lists, each containing metadata for the corresponding data table. - #' @param data_tables_filters A list of lists, each containing filter information for the corresponding data table. - #' @param data_tables_column_selections A list of lists, each containing column selection information for the corresponding data table. - #' @param imported_from A list of strings indicating the source from which each data table was imported. - #' @param messages A boolean indicating whether to display messages. - #' @param convert A boolean indicating whether to perform data conversion. - #' @param create A boolean indicating whether to create new data objects. - initialize = function(data_tables = list(), instat_obj_metadata = list(), - data_tables_variables_metadata = rep(list(data.frame()), length(data_tables)), - data_tables_metadata = rep(list(list()), length(data_tables)), - data_tables_filters = rep(list(list()), length(data_tables)), - data_tables_column_selections = rep(list(list()), length(data_tables)), - imported_from = as.list(rep("", length(data_tables))), - messages = TRUE, convert = TRUE, create = TRUE) { - self$set_meta(instat_obj_metadata) - self$set_objects(list()) - - if (missing(data_tables) || length(data_tables) == 0) { - self$set_data_objects(list()) - } else { - self$import_data(data_tables = data_tables, data_tables_variables_metadata = data_tables_variables_metadata, - data_tables_metadata = data_tables_metadata, - imported_from = imported_from, messages = messages, convert = convert, create = create, - data_tables_filters = data_tables_filters, - data_tables_column_selections = data_tables_column_selections) - } - - private$.data_sheets_changed <- FALSE - }, - - #' @description - #' Standardize country names in the specified data table. - #' @param data_name The name of the data table. - #' @param country_columns A vector of column names containing country data. - standardise_country_names = function(data_name, country_columns = c()) { - self$get_data_objects(data_name)$standardise_country_names(country_columns) - }, - - #' @description - #' Define a data table as climatic data. - #' @param data_name The name of the data table. - #' @param types A vector specifying the types of climatic data. - #' @param key_col_names A vector of column names to be used as keys. - #' @param key_name The name of the key. - define_as_climatic = function(data_name, types, key_col_names, key_name) { - self$add_key(data_name = data_name, col_names = key_col_names, key_name = key_name) - self$append_to_dataframe_metadata(data_name, is_climatic_label, TRUE) - - for (curr_data_name in self$get_data_names()) { - if (!self$get_data_objects(data_name)$is_metadata(is_climatic_label)) { - self$append_to_dataframe_metadata(curr_data_name, is_climatic_label, FALSE) - } - } - self$get_data_objects(data_name)$set_climatic_types(types) - }, - - #' @description - #' Define corruption output columns in the specified data table. - #' @param data_name The name of the data table. - #' @param output_columns A vector of column names to be defined as corruption outputs. - define_corruption_outputs = function(data_name, output_columns = c()) { - self$get_data_objects(data_name)$define_corruption_outputs(output_columns) - }, - - #' @description - #' Define red flag columns in the specified data table. - #' @param data_name The name of the data table. - #' @param red_flags A vector of column names to be defined as red flags. - define_red_flags = function(data_name, red_flags = c()) { - self$get_data_objects(data_name)$define_red_flags(red_flags) - }, - - #' @description - #' Define a data table as procurement data. - #' @param data_name The name of the data table. - #' @param primary_types A vector of primary types of procurement data. - #' @param calculated_types A vector of calculated types of procurement data. - #' @param country_data_name The name of the country-level data table. - #' @param country_types A vector of types for the country-level data. - #' @param auto_generate A boolean indicating whether to auto-generate procurement types. - define_as_procurement = function(data_name, primary_types = c(), calculated_types = c(), - country_data_name, country_types, auto_generate = TRUE) { - self$append_to_dataframe_metadata(data_name, corruption_data_label, corruption_contract_level_label) - self$get_data_objects(data_name)$set_procurement_types(primary_types, calculated_types, auto_generate) - if (!missing(country_data_name)) { - self$define_as_procurement_country_level_data(data_name = country_data_name, - contract_level_data_name = data_name, - types = country_types, - auto_generate = auto_generate) - } - }, - - #' @description - #' Define a data table as procurement country-level data. - #' @param data_name The name of the data table. - #' @param contract_level_data_name The name of the contract-level data table. - #' @param types A vector of types for the procurement country-level data. - #' @param auto_generate A boolean indicating whether to auto-generate procurement types. - define_as_procurement_country_level_data = function(data_name, contract_level_data_name, types = c(), auto_generate = TRUE) { - self$append_to_dataframe_metadata(data_name, corruption_data_label, corruption_country_level_label) - self$get_data_objects(data_name)$define_as_procurement_country_level_data(types, auto_generate) - contract_level_country_name <- self$get_corruption_column_name(contract_level_data_name, corruption_country_label) - country_level_country_name <- self$get_corruption_column_name(data_name, corruption_country_label) - if (contract_level_country_name == "" || country_level_country_name == "") stop("country column must be defined in the contract level data and country level data.") - link_pairs <- country_level_country_name - names(link_pairs) <- contract_level_country_name - self$add_link(from_data_frame = contract_level_data_name, to_data_frame = data_name, link_pairs = link_pairs, type = keyed_link_label) - }, - - #' @description - #' Get the names of CRI component columns in the specified data table. - #' @param data_name The name of the data table. - #' @return A vector of CRI component column names. - get_CRI_component_column_names = function(data_name) { - self$get_data_objects(data_name)$get_CRI_component_column_names() - }, - - #' @description - #' Get the names of red flag columns in the specified data table. - #' @param data_name The name of the data table. - #' @return A vector of red flag column names. - get_red_flag_column_names = function(data_name) { - self$get_data_objects(data_name)$get_red_flag_column_names() - }, - - #' @description - #' Get the names of CRI columns in the specified data table. - #' @param data_name The name of the data table. - #' @return A vector of CRI column names. - get_CRI_column_names = function(data_name) { - self$get_data_objects(data_name)$get_CRI_column_names() - }, - - #' @description - #' Get the name of the corruption column in the specified data table. - #' @param data_name The name of the data table. - #' @param type The type of the corruption column. - #' @return The name of the corruption column. - get_corruption_column_name = function(data_name, type) { - self$get_data_objects(data_name)$get_corruption_column_name(type) - }, - - #' @description - #' Imports data tables and their associated metadata into the DataBook object. - #' @param data_tables A list of data tables to be imported. - #' @param data_tables_variables_metadata Metadata for the variables of each data table. - #' @param data_tables_metadata General metadata for each data table. - #' @param data_tables_filters Filters applied to each data table. - #' @param data_tables_column_selections Column selections for each data table. - #' @param imported_from The origin/source of the imported data. - #' @param data_names Optional names for the data tables. - #' @param messages A boolean indicating if messages should be displayed. - #' @param convert A boolean indicating if data conversion should occur. - #' @param create A boolean to create new data objects. - #' @param prefix A boolean indicating whether to prefix data names. - #' @param add_to_graph_book A boolean to add the data to a graph book. - import_data = function(data_tables = list(), data_tables_variables_metadata = rep(list(data.frame()),length(data_tables)), - data_tables_metadata = rep(list(list()),length(data_tables)), - data_tables_filters = rep(list(list()),length(data_tables)), - data_tables_column_selections = rep(list(list()),length(data_tables)), - imported_from = as.list(rep("",length(data_tables))), - data_names = NULL, - messages=TRUE, convert=TRUE, create=TRUE, prefix=TRUE, - add_to_graph_book = TRUE) { - if (missing(data_tables) || length(data_tables) == 0) { - stop("No data found. No data objects can be created.") - } - - else { - - if(!(is.list(data_tables))) { - stop("data_tables must be a list of data frames") - } - - if(anyDuplicated(names(data_tables))) { - stop("There are duplicate names in the data tables list.") - } - - if(length(data_tables_variables_metadata) != length(data_tables)) { - stop("If data_tables_variables_metadata is specified, it must be a list of metadata lists with the same length as data_tables.") - } - - if(length(data_tables_metadata) != length(data_tables)) { - stop("If data_tables_metadata is specified, it must be a list of metadata lists with the same length as data_tables.") - } - - if (length(imported_from) != length(data_tables)) { - stop("imported_from must be a list of the same length as data_tables") - } - - if(!is.null(data_names) && length(data_names) != length(data_names)) { - stop("If data_names is specified it must be a list of the same length as data_tables") - } - - # loop through the data_tables list and create a data object for each - # data.frame given - new_data_objects = list() - for ( i in (1:length(data_tables)) ) { - curr_name <- names(data_tables)[[i]] - if(is.null(curr_name) && !is.null(data_names)) curr_name <- data_names[i] - if (prefix){ - if(tolower(curr_name) %in% tolower(names(private$.data_sheets))) { - warning("Cannot have data frames with the same name only differing by case. Data frame will be renamed.") - curr_name <- next_default_item(tolower(curr_name), tolower(names(private$.data_sheets))) - } - } - - new_data = DataSheet$new(data=data_tables[[i]], data_name = curr_name, - variables_metadata = data_tables_variables_metadata[[i]], - metadata = data_tables_metadata[[i]], - imported_from = imported_from[[i]], - start_point = i, - messages = messages, convert = convert, create = create, - filters = data_tables_filters[[i]], - column_selections = data_tables_column_selections[[i]]) - # Add this new data object to our list of data objects - self$append_data_object(new_data$get_metadata(data_name_label), new_data, add_to_graph_book = add_to_graph_book) - } - } - }, - - #' @description - #' Replaces the instat object in the DataBook. - #' @param new_instat_object The new instat object to replace the existing one. - replace_instat_object = function(new_instat_object) { - self$set_data_objects(list()) - for(curr_obj in new_instat_object$get_data_objects()) { - self$append_data_object(curr_obj$get_metadata(data_name_label), curr_obj$data_clone()) - } - self$set_meta(new_instat_object$get_metadata()) - self$set_objects(new_instat_object$get_objects(data_name = overall_label)) - self$data_objects_changed <- TRUE - }, - - #' @description - #' Sets the data objects within the DataBook. - #' @param new_data_objects A list of data objects to be set. - set_data_objects = function(new_data_objects) { - # new_data_objects could be of old class type 'data_object' - if(!is.list(new_data_objects) || (length(new_data_objects) > 0 && !any(c("DataSheet", "data_object") %in% sapply(new_data_objects, class)))) { - stop("new_data_objects must be a list of data_objects") - } - else private$.data_sheets <- new_data_objects - }, - - #' @description - #' Copies a data object with an optional filter and column selection. - #' @param data_name The name of the data object to copy. - #' @param new_name The new name for the copied data object. - #' @param filter_name Optional filter to apply during the copy. - #' @param column_selection_name Optional column selection to apply during the copy. - #' @param reset_row_names A boolean indicating whether to reset row names. - copy_data_object = function(data_name, new_name, filter_name = "", column_selection_name = "", reset_row_names = TRUE) { - new_obj <- self$get_data_objects(data_name)$data_clone() - if(filter_name != "") { - subset_data <- self$get_data_objects(data_name)$get_data_frame(use_current_filter = FALSE, filter_name = filter_name, retain_attr = TRUE) - if(reset_row_names) rownames(subset_data) <- 1:nrow(subset_data) - new_obj$remove_current_filter() - new_obj$set_data(subset_data) - } - if(column_selection_name != "") { - subset_data <- self$get_data_objects(data_name)$get_data_frame(use_current_filter = FALSE, filter_name = filter_name, column_selection_name = column_selection_name, use_column_selection = FALSE, retain_attr = TRUE) - new_obj$remove_current_column_selection() - new_obj$set_data(subset_data) - } - self$append_data_object(new_name, new_obj) - }, - - #' @description - #' Imports data from an RDS file into the DataBook. - #' @param data_RDS The RDS file containing data. - #' @param keep_existing A boolean to keep existing data. - #' @param overwrite_existing A boolean to overwrite existing data if necessary. - #' @param include_objects A boolean to include objects in the import. - #' @param include_metadata A boolean to include metadata in the import. - #' @param include_logs A boolean to include logs in the import. - #' @param include_filters A boolean to include filters in the import. - #' @param include_column_selections A boolean to include column selections in the import. - #' @param include_calculations A boolean to include calculations in the import. - #' @param include_comments A boolean to include comments in the import. - import_RDS = function(data_RDS, - keep_existing = TRUE, - overwrite_existing = FALSE, - include_objects = TRUE, - include_metadata = TRUE, - include_logs = TRUE, - include_filters = TRUE, - include_column_selections = TRUE, - include_calculations = TRUE, - include_comments = TRUE) { - # TODO add include_calculations options - - # 'instat_object' is previously used class name, some files may have this name. - if(any(c("instat_object", "DataBook") %in% class(data_RDS))) { - if(!keep_existing && include_objects && include_metadata && include_logs && include_filters && include_column_selections && include_calculations && include_comments) { - self$replace_instat_object(new_instat_object = data_RDS) - }else { - if(!keep_existing) { - self$set_data_objects(list()) - self$set_meta(list()) - self$set_objects(list()) - self$set_links(list()) - self$set_database_connection(NULL) - } - new_links_list <- data_RDS$get_links() - for(data_obj_name in data_RDS$get_data_names()) { - data_obj_clone <- self$clone_data_object(data_RDS$get_data_objects(data_obj_name), include_objects = include_objects, include_metadata = include_metadata, include_logs = include_logs, include_filters = include_filters, include_column_selections = include_column_selections, include_calculations = include_calculations, include_comments = include_comments) - if(tolower(data_obj_name) %in% tolower(self$get_data_names()) && !overwrite_existing) { - warning("Cannot have data frames with the same name only differing by case. Data frame will be renamed.") - new_name <- next_default_item(tolower(data_obj_name), tolower(self$get_data_names())) - data_obj_clone$append_to_metadata(data_name_label, new_name) - if(new_name != data_obj_name) { - for(i in seq_along(new_links_list)) { - new_links_list[[i]]$rename_data_frame_in_link(data_obj_name, new_name) - } - } - } - #if(!data_obj_clone$is_metadata(data_name_label)) data_obj_clone$append_to_metadata(data_name_label, new_name) - curr_data_name = data_obj_clone$get_metadata(data_name_label) - self$append_data_object(curr_data_name, data_obj_clone) - } - for(i in seq_along(new_links_list)) { - curr_link <- new_links_list[[i]] - for(j in seq_along(curr_link$link_columns)) { - self$add_link(from_data_frame = curr_link$from_data_frame, to_data_frame = curr_link$to_data_frame, link_pairs = curr_link$link_columns[[j]], type = curr_link$type, link_name = names(new_links_list)[i]) - } - } - new_objects_list <- data_RDS$get_objects(data_name = overall_label) - new_objects_count <- length(new_objects_list) - if(include_objects && new_objects_count > 0) { - for(i in (1:new_objects_count)) { - if(!(names(new_objects_list)[i] %in% names(private$.objects)) || overwrite_existing) { - self$add_object(object_name = names(new_objects_list)[i], - object_type_label = new_objects_list[[i]]$object_type_label, - object_format = new_objects_list[[i]]$object_format, - object = new_objects_list[[i]]$object) - } - } - } - new_metadata <- data_RDS$get_metadata() - new_metadata_count <- length(new_metadata) - if(include_metadata && new_metadata_count > 0) { - for(i in (1:new_metadata_count)) { - if(!(names(new_metadata)[i] %in% names(private$metadata)) || overwrite_existing) { - self$append_to_metadata(names(new_metadata)[i], new_metadata[[i]]) - } - } - } - } - self$data_objects_changed <- TRUE - }else if(is.data.frame(data_RDS) || is.matrix(data_RDS)) { - self$import_data(data_tables = list(data_RDS = data_RDS)) - }else stop("Cannot import an objects of class", paste(class(data_RDS), collapse = ",")) - }, - - #' @description - #' Clones a data object with options to include metadata, logs, filters, etc. - #' @param curr_data_object The current data object to be cloned. - #' @param include_objects A boolean to include objects in the clone. - #' @param include_metadata A boolean to include metadata in the clone. - #' @param include_logs A boolean to include logs in the clone. - #' @param include_filters A boolean to include filters in the clone. - #' @param include_column_selections A boolean to include column selections in the clone. - #' @param include_calculations A boolean to include calculations in the clone. - #' @param include_comments A boolean to include comments in the clone. - clone_data_object = function(curr_data_object, include_objects = TRUE, include_metadata = TRUE, include_logs = TRUE, include_filters = TRUE, include_column_selections = TRUE, include_calculations = TRUE, include_comments = TRUE, include_scalars = TRUE, ...) { - curr_names <- names(curr_data_object) - if("get_data_frame" %in% curr_names) new_data <- curr_data_object$get_data_frame(use_current_filter = FALSE) - else stop("Cannot import data. No 'get_data_frame' method.") - if("get_metadata" %in% curr_names) new_data_name <- curr_data_object$get_metadata(data_name_label) - if(include_objects && "get_objects" %in% curr_names) new_objects <- curr_data_object$get_objects() - else new_objects <- list() - if(include_scalars && "get_scalars" %in% curr_names) new_scalars <- curr_data_object$get_scalars() - else new_scalars <- list() - if(include_filters && "get_filter" %in% curr_names) { - new_filters <- lapply(curr_data_object$get_filter(), function(x) x$data_clone()) - new_filters <- lapply(new_filters, function(x) check_filter(x)) - } else new_filters <- list() - if(include_column_selections && "get_column_selection" %in% curr_names) new_column_selections <- curr_data_object$get_column_selection() - else new_column_selections <- list() - if(include_calculations && "get_calculations" %in% curr_names) new_calculations <- lapply(curr_data_object$get_calculations(), function(x) self$clone_instat_calculation(x)) - else new_calculations <- list() - if(include_comments && "get_comments" %in% curr_names) new_comments <- lapply(curr_data_object$get_comments(), function(x) x$data_clone()) - else new_comments <- list() - if("get_keys" %in% curr_names) new_keys <- curr_data_object$get_keys() - else new_keys <- list() - - new_data_object <- DataSheet$new(data = new_data, data_name = new_data_name, filters = new_filters, column_selections = new_column_selections, objects = new_objects, calculations = new_calculations, scalars = new_scalars, keys = new_keys, comments = new_comments, keep_attributes = include_metadata) - if(include_logs && "get_changes" %in% curr_names) { - new_changes <- curr_data_object$get_changes() - } - else new_changes <- list() - new_data_object$set_changes(new_changes) - if(include_filters && "current_filter" %in% curr_names) new_data_object$current_filter <- curr_data_object$get_current_filter() - else new_data_object$remove_current_filter() - if(include_column_selections && "current_column_selection" %in% curr_names) new_data_object$current_column_selection <- curr_data_object$get_current_column_selection() - else new_data_object$remove_current_column_selection() - if(!include_metadata) { - new_data_object$clear_metadata() - new_data_object$clear_variables_metadata() - } - new_data_object$data_changed <- TRUE - new_data_object$metadata_changed <- TRUE - new_data_object$variables_metadata_changed <- TRUE - return(new_data_object) - }, - - #' @description - #' Clones an instat calculation with manipulations and sub-calculations. - #' @param curr_instat_calculation The current instat calculation to be cloned. - clone_instat_calculation = function(curr_instat_calculation, ...) { - new_manips <- lapply(curr_instat_calculation$manipulations, function(x) self$clone_instat_calculation(x)) - new_subs <- lapply(curr_instat_calculation$sub_calculations, function(x) self$clone_instat_calculation(x)) - new_instat_calculation <- instat_calculation$new(function_exp = curr_instat_calculation$function_exp, - type = curr_instat_calculation$type, - name = curr_instat_calculation$name, - result_name = curr_instat_calculation$result_name, - manipulations = new_manips, - sub_calculations = new_subs, - calculated_from = curr_instat_calculation$calculated_from, - save = curr_instat_calculation$save) - return(new_instat_calculation) - }, - - #' @description - #' Imports data from an ODK platform. - #' @param username The username for ODK. - #' @param form_name The name of the ODK form. - #' @param platform The platform used for ODK. - import_from_ODK = function(username, form_name, platform) { - out <- import_from_ODK(username, form_name, platform) - data_list <- list(out) - names(data_list) <- form_name - self$import_data(data_tables = data_list) - }, - - #' @description - #' Sets metadata for the DataBook. - #' @param new_meta A list of metadata to be set. - set_meta = function(new_meta) { - if(!is.list(new_meta)) stop("new_meta must be of type: list") - for(name in names(attributes(self))) { - if(!name %in% c("class")) attr(self, name) <- NULL - } - for(name in names(new_meta)) { - self$append_to_metadata(name, new_meta[[name]]) - } - }, - - #' @description - #' Sets objects in the DataBook. - #' @param new_objects A list of objects to be set. - set_objects = function(new_objects) { - if(!is.list(new_objects)) stop("new_objects must be of type: list") - private$.objects <- new_objects - }, - - #' @description - #' Sets scalar values in the DataBook. - #' @param new_scalars A list of scalar values to be set. - set_scalars = function(new_scalars) { - if(!is.list(new_scalars)) stop("new_scalars must be of type: list") - private$.scalars <- new_scalars - }, - - #' @description - #' Appends a data object to the DataBook. - #' @param name The name of the data object. - #' @param obj The data object to append. - #' @param add_to_graph_book A boolean to add the data to the graph book. - append_data_object = function(name, obj, add_to_graph_book = TRUE) { - if(!is.character(name)) stop("name must be a character") - # obj could be of old class type 'data_object' - if(!any(c("data_object", "DataSheet") %in% class(obj))) { - stop("obj must be a data object") - } - obj$append_to_metadata(data_name_label, name) - private$.data_sheets[[name]] <- obj - if (add_to_graph_book && exists(".graph_data_book")) { - dfs <- list(data.frame()) - names(dfs) <- name - .graph_data_book$import_data(data_tables = dfs, add_to_graph_book = FALSE) - } - }, - - #' @description - #' Retrieve data objects from the DataBook by name. - #' @param data_name The name or index of the data object(s) to retrieve. - #' @param as_list A boolean to return the data objects as a list (default: FALSE). - #' @param ... Additional arguments. - get_data_objects = function(data_name, as_list = FALSE, ...) { - if (missing(data_name)) { - return(private$.data_sheets) - } else { - if (all(is.character(data_name))) type = "character" - else if (all(is.numeric(data_name)) && all((data_name %% 1) == 0)) type = "integer" - else stop("data_name must be of type character or integer") - - if (type == "character" && !all(data_name %in% names(private$.data_sheets))) stop(paste(data_name, "not found")) - if (type == "integer" && (!all(1 <= data_name) || !all(data_name <= length(private$.data_sheets)))) stop(paste(data_name, "not found")) - if (length(data_name) > 1 || as_list) return(private$.data_sheets[data_name]) - else return(private$.data_sheets[[data_name]]) - } - }, - - #' @description - #' Retrieve data frames from the DataBook. - #' @param data_name The name of the data frame to retrieve. - #' @param convert_to_character A boolean indicating whether to convert data to character type (default: FALSE). - #' @param stack_data A boolean to stack data (default: FALSE). - #' @param include_hidden_columns A boolean to include hidden columns (default: TRUE). - #' @param use_current_filter A boolean to apply the current filter (default: TRUE). - #' @param ... Additional arguments. - get_data_frame = function(data_name, convert_to_character = FALSE, stack_data = FALSE, - include_hidden_columns = TRUE, use_current_filter = TRUE, ...) { - if (!stack_data) { - if (missing(data_name)) data_name <- self$get_data_names() - if (length(data_name) > 1) { - retlist <- list() - for (curr_name in data_name) { - retlist[[curr_name]] = self$get_data_objects(curr_name)$get_data_frame( - convert_to_character = convert_to_character, - include_hidden_columns = include_hidden_columns, - use_current_filter = use_current_filter, ...) - } - return(retlist) - } else { - return(self$get_data_objects(data_name)$get_data_frame( - convert_to_character = convert_to_character, - include_hidden_columns = include_hidden_columns, - use_current_filter = use_current_filter, ...)) - } - } else { - if (missing(data_name)) stop("data to be stacked is missing") - if (!data_name %in% names(private$.data_sheets)) stop(paste(data_name, "not found.")) - return(self$get_data_objects(data_name)$get_data_frame( - include_hidden_columns = include_hidden_columns, - use_current_filter = use_current_filter, - stack_data = TRUE, ...)) - } - }, - - #' @description - #' Retrieve metadata for variables in a data frame. - #' @param data_name The name of the data frame. - #' @param data_type The type of data to retrieve (default: "all"). - #' @param convert_to_character A boolean indicating whether to convert data to character type (default: FALSE). - #' @param property The specific property to retrieve. - #' @param column The column for which metadata is to be retrieved. - #' @param ... Additional arguments. - get_variables_metadata = function(data_name, data_type = "all", convert_to_character = FALSE, - property, column, ...) { - if (missing(data_name)) { - retlist <- list() - for (curr_obj in private$.data_sheets) { - retlist[[curr_obj$get_metadata(data_name_label)]] = curr_obj$get_variables_metadata( - data_type = data_type, convert_to_character = convert_to_character, property = property, column = column, ...) - } - return(retlist) - } else { - return(self$get_data_objects(data_name)$get_variables_metadata( - data_type = data_type, convert_to_character = convert_to_character, property = property, column = column, ...)) - } - }, - - #' @description - #' Retrieve data types for specific columns in a data frame. - #' @param data_name The name of the data frame. - #' @param columns A vector of columns to retrieve the data types for. - get_column_data_types = function(data_name, columns) { - return(self$get_data_objects(data_name)$get_column_data_types(columns = columns)) - }, - - #' @description - #' Retrieve labels for specific columns in a data frame. - #' @param data_name The name of the data frame. - #' @param columns A vector of columns to retrieve the labels for. - get_column_labels = function(data_name, columns) { - return(self$get_data_objects(data_name)$get_column_labels(columns = columns)) - }, - - #' @description - #' Retrieve the label of a data frame. - #' @param data_name The name of the data frame. - #' @param use_current_filter A boolean indicating whether to use the current filter (default: FALSE). - get_data_frame_label = function(data_name, use_current_filter = FALSE) { - self$get_data_objects(data_name)$get_data_frame_label(use_current_filter) - }, - - #' @description - #' Retrieve metadata for a data frame. - #' @param data_name The name of the data frame. - #' @param label The label for the metadata to retrieve. - #' @param include_calculated A boolean indicating whether to include calculated columns (default: TRUE). - #' @param excluded_not_for_display A boolean to exclude columns not for display (default: TRUE). - get_data_frame_metadata = function(data_name, label, include_calculated = TRUE, excluded_not_for_display = TRUE) { - return(self$get_data_objects(data_name)$get_metadata( - label = label, include_calculated = include_calculated, excluded_not_for_display = excluded_not_for_display)) - }, - - #' @description - #' Retrieve combined metadata across all data objects in the DataBook. - #' @param convert_to_character A boolean to convert the metadata to a character matrix (default: FALSE). - get_combined_metadata = function(convert_to_character = FALSE) { - retlist <- data.frame() - i = 1 - for (curr_obj in private$.data_sheets) { - templist = curr_obj$get_metadata() - for (j in seq_along(templist)) { - if (is.list(templist[[j]]) || length(templist[[j]]) > 1) { - if (length(templist[[j]]) > 0) { - templist[[j]] <- paste(names(templist[[j]]), " = ", templist[[j]], collapse = ", ") - } else { - next - } - } - retlist[i, names(templist[j])] = templist[[j]] - } - i = i + 1 - } - if (convert_to_character) return(convert_to_character_matrix(retlist, FALSE)) - else return(retlist) - }, - - #' @description - #' Retrieve metadata for a specific property. - #' @param name The name of the metadata to retrieve. - get_metadata = function(name, ...) { - if (missing(name)) return(private$.metadata) - if (!is.character(name)) stop("name must be a character") - if (!name %in% names(private$.metadata)) stop(paste(name, "not found in metadata")) - return(private$.metadata[[name]]) - }, - - #' @description - #' Retrieve data names from the data book. - #' @param as_list A boolean indicating whether to return results as a list. - #' @param include A vector of names to include. - #' @param exclude A vector of names to exclude. - #' @param excluded_items A vector of excluded items. - #' @param include_hidden A boolean indicating whether to include hidden items. - get_data_names = function(as_list = FALSE, include, exclude, excluded_items, include_hidden = TRUE, ...) { - ret <- names(private$.data_sheets) - if(!include_hidden) { - ret <- ret[sapply(ret, function(x) !isTRUE(self$get_data_objects(x)$get_metadata(label = is_hidden_label)))] - } - if(as_list) return(list(data_names = ret)) - else return(ret) - }, - - #' @description - #' Check if data has changed. - #' @param data_name The name of the data table to check. - get_data_changed = function(data_name) { - if(missing(data_name)) { - if(self$data_objects_changed) return(TRUE) - for(curr_obj in private$.data_sheets) { - if(curr_obj$data_changed) return(TRUE) - } - return(FALSE) - } - else { - return(self$get_data_objects(data_name)$data_changed) - } - }, - - #' @description - #' Check if variables metadata has changed. - #' @param data_name The name of the data table to check. - get_variables_metadata_changed = function(data_name) { - if(missing(data_name)) { - if(private$.data_sheets_changed) return(TRUE) - return(any(sapply(private$.data_sheets, function(x) x$variables_metadata_changed))) - } - else { - return(self$get_data_objects(data_name)$variables_metadata_changed) - } - }, - - #' @description - #' Check if metadata has changed. - #' @param data_name The name of the data table to check. - get_metadata_changed = function(data_name) { - if(missing(data_name)) { - if(private$.data_sheets_changed) return(TRUE) - for(curr_obj in private$.data_sheets) { - if(curr_obj$metadata_changed) return(TRUE) - } - return(FALSE) - } - else { - return(self$get_data_objects(data_name)$metadata_changed) - } - }, - - #' @description - #' Retrieve calculations for a specific data table. - #' @param data_name The name of the data table. - get_calculations = function(data_name) { - return(self$get_data_objects(data_name)$get_calculations()) - }, - - #' @description - #' Retrieve calculation names for a specific data table. - #' @param data_name The name of the data table. - #' @param as_list A boolean indicating whether to return results as a list. - #' @param excluded_items A vector of excluded items. - get_calculation_names = function(data_name, as_list = FALSE, excluded_items = c()) { - return(self$get_data_objects(data_name)$get_calculation_names(as_list = as_list, excluded_items = excluded_items)) - }, - - #' @description - #' Retrieve scalars for a specific data table. - #' @param data_name The name of the data table. - get_scalars = function(data_name) { - if(is.null(data_name) || identical(data_name, overall_label)) { - out <- private$.scalars[self$get_scalar_names(data_name = data_name)] - } else { - out <- self$get_data_objects(data_name)$get_scalars() - } - return(out) - }, - - #' @description - #' Retrieve scalar names for a specific data table. - #' @param data_name The name of the data table. - #' @param as_list A boolean indicating whether to return results as a list. - #' @param excluded_items A vector of excluded items. - get_scalar_names = function(data_name, as_list = FALSE, excluded_items = c(), ...) { - if (is.null(data_name) || identical(data_name, overall_label)) { - out <- - get_data_book_scalar_names( - scalar_list = private$.scalars, - as_list = as_list, - list_label = overall_label - ) - } else { - out <- - self$get_data_objects(data_name)$get_scalar_names(as_list = as_list, excluded_items = excluded_items) - } - return(out) - }, - - #' @description - #' Retrieve the value of a specific scalar for a data table. - #' @param data_name The name of the data table. - #' @param scalar_name The name of the scalar. - get_scalar_value = function(data_name, scalar_name) { - self$get_data_objects(data_name)$get_scalar_value(scalar_name) - }, - - #' @description - #' Add a scalar to a data table. - #' @param data_name The name of the data table. - #' @param scalar_name The name of the scalar (optional). - #' @param scalar_value The value of the scalar. - add_scalar = function(data_name, scalar_name = "", scalar_value) { - if (is.null(data_name) || identical(data_name, overall_label)) { - if (missing(scalar_name)) - scalar_name <- next_default_item("scalar", names(private$.scalars)) - if (scalar_name %in% names(private$.scalars)) - warning("A scalar called ", - scalar_name, - " already exists. It will be replaced.") - - # Add the scalar - private$.scalars[[scalar_name]] <- scalar_value - } else { - self$get_data_objects(data_name)$add_scalar(scalar_name, scalar_value) - } - }, - - #' @description - #' Get the count of data frames in the DataBook. - #' @return An integer representing the number of data frames. - dataframe_count = function() { - return(length(private$.data_sheets)) - }, - - #' @description - #' Set the data changed status for the specified data frame. - #' @param data_name The name of the data frame. Defaults to an empty string. - #' @param new_val A boolean indicating the new changed status. - set_data_frames_changed = function(data_name = "", new_val) { - if(data_name == "") { - for(curr_obj in private$.data_sheets) { - curr_obj$data_changed <- new_val - } - } else { - self$get_data_objects(data_name)$set_data_changed(new_val) - } - }, - - #' @description - #' Set the variables metadata changed status for the specified data frame. - #' @param data_name The name of the data frame. Defaults to an empty string. - #' @param new_val A boolean indicating the new changed status. - set_variables_metadata_changed = function(data_name = "", new_val) { - if(data_name == "") { - for(curr_obj in private$.data_sheets) { - curr_obj$variables_metadata_changed <- new_val - } - } else { - self$get_data_objects(data_name)$set_variables_metadata_changed(new_val) - } - }, - - #' @description - #' Set the metadata changed status for the specified data frame. - #' @param data_name The name of the data frame. Defaults to an empty string. - #' @param new_val A boolean indicating the new changed status. - set_metadata_changed = function(data_name = "", new_val) { - if(data_name == "") { - for(curr_obj in private$.data_sheets) { - curr_obj$set_metadata_changed(new_val) - } - } else { - self$get_data_objects(data_name)$set_metadata_changed(new_val) - } - }, - - #' @description - #' Add columns to the specified data frame. - #' @param data_name The name of the data frame. - #' @param col_name The name of the new column. - #' @param col_data The data for the new column. - #' @param use_col_name_as_prefix A boolean indicating if the column name should be prefixed. - #' @param hidden A boolean indicating if the column should be hidden. - #' @param before The name of the column before which to insert the new column. - #' @param adjacent_column The name of an adjacent column. - #' @param num_cols The number of columns to add. - #' @param require_correct_length A boolean indicating if the lengths of the data should match. - #' @param keep_existing_position A boolean indicating if the existing column position should be maintained. - add_columns_to_data = function(data_name, col_name = "", col_data, use_col_name_as_prefix = FALSE, hidden = FALSE, before, adjacent_column = "", num_cols, require_correct_length = TRUE, keep_existing_position = TRUE) { - self$get_data_objects(data_name)$add_columns_to_data(col_name, col_data, use_col_name_as_prefix = use_col_name_as_prefix, hidden = hidden, before = before, adjacent_column = adjacent_column, num_cols = num_cols, require_correct_length = require_correct_length, keep_existing_position = keep_existing_position) - }, - - #' @description - #' Get specified columns from the data frame. - #' @param data_name The name of the data frame. - #' @param col_names A vector of column names to retrieve. - #' @param from_stacked_data A boolean indicating if the data is stacked. - #' @param force_as_data_frame A boolean indicating if the output should be a data frame. - #' @param use_current_filter A boolean indicating if the current filter should be used. - #' @param remove_labels A boolean indicating if labels should be removed. - #' @param drop_unused_filter_levels A boolean indicating if unused filter levels should be dropped. - get_columns_from_data = function(data_name, col_names, from_stacked_data = FALSE, force_as_data_frame = FALSE, use_current_filter = TRUE, remove_labels = FALSE, drop_unused_filter_levels = FALSE) { - if(missing(data_name)) stop("data_name is required") - if(!from_stacked_data) { - if(!data_name %in% names(private$.data_sheets)) stop(data_name, "not found") - self$get_data_objects(data_name)$get_columns_from_data(col_names, force_as_data_frame, use_current_filter = use_current_filter, remove_labels = remove_labels, drop_unused_filter_levels = drop_unused_filter_levels) - } else { - if(!exists(data_name)) stop(paste(data_name, "not found.")) - if(!all(sapply(col_names, function(x) x %in% names(data_name)))) stop("Not all column names were found in data") - if(length(col_names) == 1 && !force_as_data_frame) return(data_name[[col_names]]) - else return(data_name[col_names]) - } - }, - - #' @description - #' Create a new graph data book and assign it to the global environment. - create_graph_data_book = function() { - .graph_data_book <- DataBook$new() - df_names <- self$get_data_names() - dfs <- vector("list", length(df_names)) - names(dfs) <- df_names - for (i in seq_along(dfs)) { - dfs[[i]] <- data.frame() - } - .graph_data_book$import_data(data_tables = dfs) - assign(".graph_data_book", .graph_data_book, envir = .GlobalEnv) - }, - - #' @description - #' Add an object to the DataBook. - #' @param data_name The name of the data frame. - #' @param object_name The name of the object. If NULL, a default name is generated. - #' @param object_type_label The label for the object type. - #' @param object_format The format of the object. - #' @param object The object to add. - add_object = function(data_name = NULL, - object_name = NULL, - object_type_label, - object_format, - object) { - if(is.null(data_name) || identical(data_name, overall_label)) { - if(is.null(object_name)){ - object_name <- next_default_item("object", names(private$.objects)) - } - - if(object_name %in% names(private$.objects)){ - message(paste("An object called", object_name, "already exists. It will be replaced.")) - } - - private$.objects[[object_name]] <- list(object_type_label = object_type_label, object_format = object_format, object = object) - } else { - self$get_data_objects(data_name)$add_object(object_name = object_name, object_type_label = object_type_label, object_format = object_format, object = object) - } - - if(identical(object_type_label, graph_label)){ - private$.last_graph <- c(data_name, object_name) - } - }, - - #' @description - #' Get the names of objects in the DataBook. - #' @param data_name The name of the data frame. - #' @param object_type_label The label for the object type. - #' @param as_list A boolean indicating if the output should be a list. - #' @return A vector of object names. - get_object_names = function(data_name = NULL, - object_type_label = NULL, - as_list = FALSE, ...) { - if(is.null(data_name) || identical(data_name, overall_label)){ - out <- get_data_book_output_object_names( - output_object_list = private$.objects, - object_type_label = object_type_label, - as_list = as_list, - list_label = overall_label) - } else { - out <- self$get_data_objects(data_name)$get_object_names( - object_type_label = object_type_label, - as_list = as_list) - } - return(out) - }, - - #' @description - #' Get objects from the DataBook. - #' @param data_name The name of the data frame. - #' @param object_type_label The label for the object type. - #' @return A list of objects. - get_objects = function(data_name = NULL, - object_type_label = NULL) { - if(is.null(data_name) || identical(data_name, overall_label)) { - out <- private$.objects[self$get_object_names(data_name = data_name, object_type_label = object_type_label)] - } else { - out <- self$get_data_objects(data_name)$get_objects(object_type_label = object_type_label) - } - return(out) - }, - - #' @description - #' Get a specific object from the DataBook. - #' @param data_name The name of the data frame. - #' @param object_name The name of the object to retrieve. - #' @return The requested object, or NULL if not found. - get_object = function(data_name = NULL, object_name) { - out <- NULL - if(is.null(data_name) || identical(data_name, overall_label)) { - out <- private$.objects[[object_name]] - } else { - out <- self$get_data_objects(data_name)$get_object(object_name = object_name) - } - return(out) - }, - - #' @description - #' Get the data of a specific object. - #' @param data_name The name of the data frame. - #' @param object_name The name of the object. - #' @param as_file A boolean indicating if the output should be formatted as a file. - #' @return The object data or NULL if not found. - get_object_data = function(data_name = NULL, object_name, as_file = FALSE) { - out <- self$get_object(data_name = data_name, object_name = object_name) - if(is.null(out)){ - return(NULL) - } else if(as_file){ - out <- view_object_data(object = out$object, object_format = out$object_format) - } else { - out <- out$object - } - return(out) - }, - - #' @description - #' Retrieve data objects from a specified data table. - #' @param data_name The name of the data table. - #' @param object_names A character vector of object names to retrieve. - #' @param as_files A boolean indicating whether to return data as files. - get_objects_data = function(data_name = NULL, object_names = NULL, as_files = FALSE) { - out <- list() - if(is.null(object_names)){ - objects_list <- self$get_objects(data_name = data_name) - out <- self$get_objects_data(data_name = data_name, object_names = names(objects_list)) - } else { - for(object_name in object_names){ - object_data <- self$get_object_data(data_name = data_name, object_name = object_name, as_file = as_files) - if(!is.null(object_data)){ - out[[object_name]] <- object_data - } - } - } - return(out) - }, - - #' @description - #' Retrieve the last object data based on the specified type label. - #' @param object_type_label The label of the object type to retrieve. - #' @param as_file A boolean indicating whether to return the data as a file. - get_last_object_data = function(object_type_label, as_file = TRUE) { - out <- NULL - if(identical(object_type_label, graph_label)){ - if(!is.null(private$.last_graph) && length(private$.last_graph) == 2) { - out <- self$get_object_data(data_name = private$.last_graph[1], object_name = private$.last_graph[2], as_file = as_file) - } - } - return(out) - }, - - #' @description - #' Rename an object within a specified data table. - #' @param data_name The name of the data table. - #' @param object_name The current name of the object to rename. - #' @param new_name The new name for the object. - #' @param object_type The type of the object being renamed. - rename_object = function(data_name, object_name, new_name, object_type = "object") { - if(missing(data_name) || data_name == overall_label) { - if(!object_name %in% names(private$.objects)) stop(object_name, " not found in overall objects list") - if(new_name %in% names(private$.objects)) stop(new_name, " is already an object name. Cannot rename ", object_name, " to ", new_name) - names(private$.objects)[names(private$.objects) == object_name] <- new_name - } else { - self$get_data_objects(data_name)$rename_object(object_name = object_name, new_name = new_name, object_type = object_type) - } - }, - - #' @description - #' Delete specified objects from a data table. - #' @param data_name The name of the data table. - #' @param object_names A character vector of object names to delete. - #' @param object_type The type of the objects being deleted. - delete_objects = function(data_name, object_names, object_type = "object") { - if(missing(data_name) || data_name == overall_label) { - if(!all(object_names %in% names(private$.objects))) stop("Not all object_names found in overall objects list") - } else { - self$get_data_objects(data_name)$delete_objects(object_names = object_names, object_type = object_type) - } - }, - - #' @description - #' Reorder objects in a specified data table. - #' @param data_name The name of the data table. - #' @param new_order A character vector specifying the new order of object names. - reorder_objects = function(data_name, new_order) { - if(missing(data_name) || data_name == overall_label) { - if(length(new_order) != length(private$.objects) || !setequal(new_order, names(private$.objects))) stop("new_order must be a permutation of the current object names.") - self$set_objects(private$.objects[new_order]) - } else { - self$get_data_objects(data_name)$reorder_objects(new_order = new_order) - } - }, - - #' @description - #' Retrieve a value from a specified object. - #' @param data_name The name of the data table. - #' @param object_name The name of the object to retrieve data from. - #' @param value1 The first value/key to retrieve. - #' @param value2 The second value/key to retrieve. - #' @param value3 The third value/key to retrieve. - get_from_object = function(data_name, object_name, value1, value2, value3) { - if(missing(data_name) || missing(object_name)) stop("data_name and object_name must both be specified.") - curr_object = self$get_objects(data_name = data_name, object_name = object_name) - if(missing(value1)) { - if(!missing(value2) || !missing(value3)) warning("value1 is missing so value2 and value3 will be ignored.") - return(curr_object[]) - } - if(!value1 %in% names(curr_object)) stop(value1, " not found in ", object_name) - if(missing(value2)) { - if(!missing(value3)) warning("value2 is missing so value3 will be ignored.") - return(curr_object[[value1]]) - } else { - if(!value2 %in% names(curr_object[[value1]])) stop(paste0(value2, " not found in ", object_name,"[[\"",value1,"\"]]")) - if(missing(value3)) return(curr_object[[value1]][[value2]]) - else { - if(!value3 %in% names(curr_object[[value1]][[value2]])) stop(value3, " not found in ", object_name,"[[\"",value1,"\"]]","[[\"",value2,"\"]]") - return(curr_object[[value1]][[value2]][[value3]]) - } - } - }, - - #' @description - #' Add a filter to the specified data table. - #' @param data_name The name of the data table. - #' @param filter The filter to apply. - #' @param filter_name The name of the filter. - #' @param replace A boolean indicating whether to replace existing filters. - #' @param set_as_current_filter A boolean indicating whether to set this filter as the current filter. - #' @param na.rm A boolean indicating whether to remove NA values. - #' @param is_no_filter A boolean indicating whether this is a "no filter". - #' @param and_or A string indicating whether to apply AND or OR logic. - #' @param inner_not A boolean for inner negation. - #' @param outer_not A boolean for outer negation. - add_filter = function(data_name, filter, filter_name = "", replace = TRUE, set_as_current_filter = FALSE, na.rm = TRUE, is_no_filter = FALSE, and_or = "&", inner_not = FALSE, outer_not = FALSE) { - if(missing(filter)) stop("filter is required") - self$get_data_objects(data_name)$add_filter(filter, filter_name, replace, set_as_current_filter, na.rm = na.rm, is_no_filter = is_no_filter, and_or = and_or, inner_not = inner_not, outer_not = outer_not) - }, - - #' @description - #' Add a filter as levels for a specified column in the data table. - #' @param data_name The name of the data table. - #' @param filter_levels The levels of the filter to add. - #' @param column The column to apply the filter to. - add_filter_as_levels = function(data_name, filter_levels, column) { - self$get_data_objects(data_name)$add_filter_as_levels(filter_levels, column) - }, - - #' @description - #' Retrieve the current filter applied to a specified data table. - #' @param data_name The name of the data table. - #' @return The current filter. - current_filter = function(data_name) { - return(self$get_data_objects(data_name)$current_filter) - }, - - #' @description - #' Set the current filter for a specified data table. - #' @param data_name The name of the data table. - #' @param filter_name The name of the filter to set as current. - set_current_filter = function(data_name, filter_name = "") { - self$get_data_objects(data_name)$set_current_filter(filter_name) - }, - - #' @description - #' Retrieve a specific filter by name. - #' @param data_name The name of the data table. - #' @param filter_name The name of the filter to retrieve. - #' @return The requested filter. - get_filter = function(data_name, filter_name) { - return(self$get_data_objects(data_name)$get_filter(filter_name)) - }, - - #' @description - #' Retrieve a filter as a logical vector. - #' @param data_name The name of the data table. - #' @param filter_name The name of the filter to retrieve. - #' @return A logical vector representing the filter. - get_filter_as_logical = function(data_name, filter_name) { - return(self$get_data_objects(data_name)$get_filter_as_logical(filter_name)) - }, - - #' @description - #' Retrieve the currently applied filter for a specified data table. - #' @param data_name The name of the data table. - #' @return The currently applied filter. - get_current_filter = function(data_name) { - self$get_data_objects(data_name)$get_current_filter() - }, - - #' @description - #' Retrieve row names based on a specific filter for a data table. - #' @param data_name The name of the data table. - #' @param filter_name The name of the filter to use for retrieval. - #' @return A vector of row names. - get_filter_row_names = function(data_name, filter_name) { - row_names <- row.names(self$get_data_frame(data_name, convert_to_character = FALSE, stack_data = FALSE, - include_hidden_columns = TRUE, use_current_filter = TRUE, filter_name = filter_name, - remove_attr = FALSE, retain_attr = FALSE, drop_unused_filter_levels = FALSE)) - return(row_names) - }, - - #' @description - #' Retrieve the name of the current filter for a specified data table. - #' @param data_name The name of the data table. - #' @return The name of the current filter. - get_current_filter_name = function(data_name) { - self$get_data_objects(data_name)$get_current_filter()$name - }, - - #' @description - #' Retrieve the names of all filters for a specified data table. - #' @param data_name The name of the data table. - #' @param as_list A boolean indicating whether to return as a list. - #' @param include A list of items to include. - #' @param exclude A list of items to exclude. - #' @param excluded_items A vector of excluded items. - #' @return A vector or list of filter names. - get_filter_names = function(data_name, as_list = FALSE, include = list(), exclude = list(), excluded_items = c()) { - if(missing(data_name)) { - return(lapply(self$get_data_objects(), function(x) x$get_filter_names(include = include, exclude = exclude))) - } else { - return(self$get_data_objects(data_name)$get_filter_names(as_list = as_list, include = include, exclude = exclude, excluded_items = excluded_items)) - } - }, - - #' @description - #' Remove the current filter from a specified data table. - #' @param data_name The name of the data table. - remove_current_filter = function(data_name) { - self$get_data_objects(data_name)$remove_current_filter() - }, - - #' @description - #' Check if a filter is applied to a specified data table. - #' @param data_name The name of the data table. - #' @return A boolean indicating if a filter is applied. - filter_applied = function(data_name) { - self$get_data_objects(data_name)$filter_applied() - }, - - #' @description - #' Retrieve the string representation of a specific filter. - #' @param data_name The name of the data table. - #' @param filter_name The name of the filter to retrieve the string for. - #' @return A string representation of the filter. - filter_string = function(data_name, filter_name) { - self$get_data_objects(data_name)$filter_string(filter_name) - }, - - #' @description - #' Retrieve a filter as an Instat calculation. - #' @param data_name The name of the data table. - #' @param filter_name The name of the filter to retrieve. - #' @return The filter as an Instat calculation. - get_filter_as_instat_calculation = function(data_name, filter_name) { - self$get_data_objects(data_name)$get_filter_as_instat_calculation(filter_name) - }, - - - # Column Selections ------------------------------------------------------- - - #' @description - #' Add a column selection to a data table. - #' @param data_name The name of the data table. - #' @param column_selection The selection of columns. - #' @param name Optional name for the selection. - #' @param replace Logical indicating if the selection should replace an existing one. - #' @param set_as_current Logical indicating if the selection should be set as current. - #' @param is_everything Logical indicating if all columns should be selected. - #' @param and_or String indicating the logical operator to use. - add_column_selection = function(data_name, column_selection, name = "", replace = TRUE, - set_as_current = FALSE, is_everything = FALSE, and_or = "|") { - self$get_data_objects(data_name)$add_column_selection(column_selection, name, replace, set_as_current, is_everything, and_or) - }, - - #' @description - #' Get the current column selection for a data table. - #' @param data_name The name of the data table. - #' @return The current column selection. - current_column_selection = function(data_name) { - return(self$get_data_objects(data_name)$current_column_selection) - }, - - #' @description - #' Set the current column selection for a data table. - #' @param data_name The name of the data table. - #' @param name The name of the column selection to set as current. - set_current_column_selection = function(data_name, name = "") { - self$get_data_objects(data_name)$set_current_column_selection(name) - }, - - #' @description - #' Get a specific column selection from a data table. - #' @param data_name The name of the data table. - #' @param name The name of the column selection to retrieve. - #' @return The specified column selection. - get_column_selection = function(data_name, name) { - return(self$get_data_objects(data_name)$get_column_selection(name)) - }, - - #' @description - #' Get column names from a specified filter in a data table. - #' @param data_name The name of the data table. - #' @param filter_name The name of the filter. - #' @return Logical representation of the filter applied to column names. - get_column_selection_column_names = function(data_name, filter_name) { - return(self$get_data_objects(data_name)$get_filter_as_logical(filter_name)) - }, - - #' @description - #' Get column names selected in a specific column selection. - #' @param data_name The name of the data table. - #' @param column_selection_name Optional name of the column selection. - #' @return A vector of selected column names. - get_column_selected_column_names = function(data_name, column_selection_name = "") { - return(self$get_data_objects(data_name)$get_column_selected_column_names(column_selection_name)) - }, - - #' @description - #' Get the current column selection for a data table. - #' @param data_name The name of the data table. - #' @return The current column selection object. - get_current_column_selection = function(data_name) { - self$get_data_objects(data_name)$get_current_column_selection() - }, - - #' @description - #' Get the name of the current column selection for a data table. - #' @param data_name The name of the data table. - #' @return The name of the current column selection. - get_current_column_selection_name = function(data_name) { - self$get_data_objects(data_name)$get_current_column_selection()$name - }, - - #' @description - #' Get names of all column selections for a data table. - #' @param data_name The name of the data table. - #' @param as_list Logical indicating if results should be returned as a list. - #' @param include List of items to include. - #' @param exclude List of items to exclude. - #' @param excluded_items Optional vector of excluded items. - #' @return A list or vector of column selection names. - get_column_selection_names = function(data_name, as_list = FALSE, include = list(), - exclude = list(), excluded_items = c()) { - if(missing(data_name)) { - return(lapply(self$get_data_objects(), function(x) x$get_column_selection_names(include = include, exclude = exclude))) - } - else { - return(self$get_data_objects(data_name)$get_column_selection_names(as_list = as_list, include = include, exclude = exclude, excluded_items = excluded_items)) - } - }, - - #' @description - #' Remove the current column selection for a data table. - #' @param data_name The name of the data table. - remove_current_column_selection = function(data_name) { - self$get_data_objects(data_name)$remove_current_column_selection() - }, - - #' @description - #' Check if a column selection has been applied to a data table. - #' @param data_name The name of the data table. - #' @return Logical indicating if a selection has been applied. - column_selection_applied = function(data_name) { - self$get_data_objects(data_name)$column_selection_applied() - }, - - #' @description - #' Replace values in the data of a specified table. - #' @param data_name The name of the data table. - #' @param col_names Names of the columns to modify. - #' @param rows The rows to be modified. - #' @param old_value The value to replace. - #' @param old_is_missing Logical indicating if old_value is missing. - #' @param start_value Optional starting value for replacement. - #' @param end_value Optional ending value for replacement. - #' @param new_value The new value to replace with. - #' @param new_is_missing Logical indicating if new_value is missing. - #' @param closed_start_value Logical for start value closure. - #' @param closed_end_value Logical for end value closure. - #' @param locf Logical indicating if last observation carried forward should be used. - #' @param from_last Logical indicating if the replacement should start from the last. - replace_value_in_data = function(data_name, col_names, rows, old_value, old_is_missing = FALSE, - start_value = NA, end_value = NA, new_value, new_is_missing = FALSE, - closed_start_value = TRUE, closed_end_value = TRUE, locf = FALSE, - from_last = FALSE) { - self$get_data_objects(data_name)$replace_value_in_data(col_names, rows, old_value, old_is_missing, start_value, end_value, new_value, new_is_missing, closed_start_value, closed_end_value, locf, from_last) - }, - - #' @description - #' Paste data from the clipboard into a specified data table. - #' @param data_name The name of the data table. - #' @param col_names Names of the columns to paste into. - #' @param start_row_pos Position to start pasting in the data. - #' @param first_clip_row_is_header Logical indicating if the first row of the clipboard is a header. - #' @param clip_board_text The text to paste from the clipboard. - paste_from_clipboard = function(data_name, col_names, start_row_pos = 1, first_clip_row_is_header = TRUE, clip_board_text) { - self$get_data_objects(data_name)$paste_from_clipboard(col_names, start_row_pos, first_clip_row_is_header, clip_board_text) - }, - - #' @description - #' Rename a column in the data of a specified table. - #' @param data_name The name of the data table. - #' @param column_name Optional name of the column to rename. - #' @param new_val The new name for the column. - #' @param label Optional label for the column. - #' @param type Type of renaming operation. - #' @param .fn Optional function for renaming. - #' @param .cols Optional columns to rename. - #' @param new_column_names_df Data frame with new column names. - #' @param new_labels_df Data frame with new labels. - #' @param ... Additional parameters. - rename_column_in_data = function(data_name, column_name = NULL, new_val = NULL, label = "", type = "single", .fn, .cols = everything(), new_column_names_df, new_labels_df, ...) { - self$get_data_objects(data_name)$rename_column_in_data(column_name, new_val, label, type, .fn, .cols, new_column_names_df, new_labels_df, ...) - self$update_links_rename_column(data_name = data_name, old_column_name = column_name, new_column_name = new_val) - }, - - #' @description - #' Generate frequency tables for specified columns in a data table. - #' @param data_name The name of the data table. - #' @param x_col_names Names of columns for x-axis. - #' @param y_col_name Name of column for y-axis. - #' @param n_column_factors Number of column factors. - #' @param store_results Logical indicating if results should be stored. - #' @param drop Logical indicating if to drop unused levels. - #' @param na.rm Logical indicating if NA values should be removed. - #' @param summary_name Optional name for the summary. - #' @param include_margins Logical indicating if margins should be included. - #' @param return_output Logical indicating if output should be returned. - #' @param treat_columns_as_factor Logical indicating if columns should be treated as factors. - #' @param page_by Pagination option. - #' @param as_html Logical indicating if output should be in HTML format. - #' @param signif_fig Number of significant figures. - #' @param na_display Optional display for NA values. - #' @param na_level_display Optional display for NA levels. - #' @param weights Optional weights for frequency calculations. - #' @param caption Optional caption for the output. - #' @param result_names Optional names for results. - #' @param percentage_type Type of percentage calculation. - #' @param perc_total_columns Optional columns for total percentages. - #' @param perc_total_factors Optional factors for total percentages. - #' @param perc_total_filter Optional filter for total percentages. - #' @param perc_decimal Logical indicating if percentages should be decimal. - #' @param margin_name Name for the margin. - #' @param additional_filter Optional additional filter. - #' @param ... Additional parameters. - frequency_tables = function(data_name, x_col_names, y_col_name, n_column_factors = 1, - store_results = TRUE, drop = TRUE, na.rm = FALSE, - summary_name = NA, include_margins = FALSE, return_output = TRUE, - treat_columns_as_factor = FALSE, page_by = "default", as_html = TRUE, - signif_fig = 2, na_display = "", na_level_display = "NA", - weights = NULL, caption = NULL, result_names = NULL, - percentage_type = "none", perc_total_columns = NULL, - perc_total_factors = c(), perc_total_filter = NULL, - perc_decimal = FALSE, margin_name = "(All)", - additional_filter, ...) { - for(i in seq_along(x_col_names)) { - cat(x_col_names[i], "by", y_col_name, "\n") - print(data_book$summary_table(data_name = data_name, summaries = count_label, - factors = c(x_col_names[i], y_col_name), - n_column_factors = n_column_factors, - store_results = store_results, drop = drop, - na.rm = na.rm, summary_name = summary_name, - include_margins = include_margins, - return_output = return_output, - treat_columns_as_factor = treat_columns_as_factor, - page_by = page_by, as_html = as_html, - signif_fig = signif_fig, na_display = na_display, - na_level_display = na_level_display, weights = weights, - caption = caption, result_names = result_names, - percentage_type = percentage_type, - perc_total_columns = perc_total_columns, - perc_total_factors = perc_total_factors, - perc_total_filter = perc_total_filter, - perc_decimal = perc_decimal, margin_name = margin_name, - additional_filter = additional_filter, ... = ...)) - cat("\n") - } - }, - - #' @description - #' Generate ANOVA tables for specified columns in a data table. - #' @param data_name The name of the data table. - #' @param x_col_names Names of columns for x-axis. - #' @param y_col_name Name of column for y-axis. - #' @param signif.stars Logical indicating if significance stars should be shown. - #' @param sign_level Logical indicating if significance level should be displayed. - #' @param means Logical indicating if means should be displayed. - anova_tables = function(data_name, x_col_names, y_col_name, signif.stars = FALSE, - sign_level = FALSE, means = FALSE) { - self$get_data_objects(data_name)$anova_tables(x_col_names = x_col_names, - y_col_name = y_col_name, - signif.stars = signif.stars, - sign_level = sign_level, means = means) - }, - - #' @description - #' Calculate correlation between specified columns in a data table. - #' @param data_name The name of the data table. - #' @param x_col_names Names of columns for x-axis. - #' @param y_col_name Name of column for y-axis. - #' @param use How to handle missing values. - #' @param method The method to use for correlation. - cor = function(data_name, x_col_names, y_col_name, use = "everything", - method = c("pearson", "kendall", "spearman")) { - self$get_data_objects(data_name)$cor(x_col_names = x_col_names, y_col_name = y_col_name, - use = use, method = method) - }, - - #' @description - #' Remove specified columns from a data table. - #' @param data_name The name of the data table. - #' @param cols The columns to remove. - #' @param allow_delete_all Logical indicating if all columns can be deleted. - remove_columns_in_data = function(data_name, cols, allow_delete_all = FALSE) { - self$get_data_objects(data_name)$remove_columns_in_data(cols = cols, allow_delete_all = allow_delete_all) - }, - - #' @description - #' Remove specified rows from a data table. - #' @param data_name The name of the data table. - #' @param row_names The names of the rows to remove. - remove_rows_in_data = function(data_name, row_names) { - self$get_data_objects(data_name)$remove_rows_in_data(row_names = row_names) - }, - - #' @description - #' Get the next available default column name for a data table. - #' @param data_name The name of the data table. - #' @param prefix The prefix for the new column name. - #' @return The next available default column name. - get_next_default_column_name = function(data_name, prefix) { - if(missing(data_name)) { - out = list() - for(curr_obj in private$.data_sheets) { - out[[curr_obj$get_metadata(data_name_label)]] = curr_obj$get_next_default_column_name(prefix) - } - return(out) - } - if(!is.character(data_name)) stop("data_name must be of type character") - if(!data_name %in% names(private$.data_sheets)) stop("dataframe: ", data_name, " not found") - return(self$get_data_objects(data_name)$get_next_default_column_name(prefix)) - }, - - #' @description - #' Retrieve the column names of a data table. - #' @param data_name The name of the data table. - #' @param as_list A boolean indicating whether to return the names as a list. - #' @param include A list of column names to include. - #' @param exclude A list of column names to exclude. - #' @param excluded_items A vector of items to be excluded. - #' @param max_no The maximum number of column names to return. - #' @param use_current_column_selection A boolean indicating whether to use the current column selection. - get_column_names = function(data_name, as_list = FALSE, include = list(), exclude = list(), - excluded_items = c(), max_no, use_current_column_selection = TRUE) { - if (missing(data_name)) { - # TODO: what to do with excluded items in this case? - return(lapply(self$get_data_objects(), function(x) x$get_column_names(include = include, exclude = exclude, max_no = max_no, use_current_column_selection = use_current_column_selection))) - } else { - return(self$get_data_objects(data_name)$get_column_names(as_list, include, exclude, excluded_items = excluded_items, max_no = max_no, use_current_column_selection = use_current_column_selection)) - } - }, - - #' @description - #' Reorder the columns in a data table. - #' @param data_name The name of the data table. - #' @param col_order A vector specifying the new order of columns. - reorder_columns_in_data = function(data_name, col_order) { - self$get_data_objects(data_name)$reorder_columns_in_data(col_order = col_order) - }, - - #' @description - #' Insert rows into a data table. - #' @param data_name The name of the data table. - #' @param start_row The row number to start inserting at. - #' @param row_data A vector of data for the new row(s). - #' @param number_rows The number of rows to insert. - #' @param before A boolean indicating whether to insert before the start_row. - insert_row_in_data = function(data_name, start_row, row_data = c(), number_rows = 1, before = FALSE) { - self$get_data_objects(data_name)$insert_row_in_data(start_row = start_row, row_data = row_data, number_rows = number_rows, before = before) - }, - - #' @description - #' Get the length of a data frame. - #' @param data_name The name of the data frame. - #' @param use_current_filter A boolean indicating whether to use the current filter. - get_data_frame_length = function(data_name, use_current_filter = FALSE) { - self$get_data_objects(data_name)$get_data_frame_length(use_current_filter) - }, - - #' @description - #' Get the next default name for a data frame. - #' @param prefix The prefix for the new data frame name. - #' @param include_index A boolean indicating whether to include an index. - #' @param start_index The starting index for naming. - get_next_default_dataframe_name = function(prefix, include_index = TRUE, start_index = 1) { - next_default_item(prefix = prefix, existing_names = names(private$.data_sheets), include_index = include_index, start_index = start_index) - }, - - #' @description - #' Delete specified data frames. - #' @param data_names A vector of data frame names to delete. - #' @param delete_graph_book A boolean indicating whether to delete the associated graph book. - delete_dataframes = function(data_names, delete_graph_book = TRUE) { - # TODO: need a set or append - for (name in data_names) { - private$.data_sheets[[name]] <- NULL - self$data_objects_changed <- TRUE - link_names <- c() - for (i in seq_along(private$.links)) { - if (private$.links[[i]]$from_data_frame == name || private$.links[[i]]$to_data_frame == name) { - link_names <- c(link_names, names(private$.links)[i]) - } - } - for (link_name in link_names) { - # TODO: Should we be able to disable links instead of deleting? - self$remove_link(link_name) - } - if (!is.null(private$.last_graph) && private$.last_graph[1] %in% data_names) private$.last_graph <- NULL - } - if (delete_graph_book && exists(".graph_data_book")) .graph_data_book$delete_dataframes(data_names = data_names, delete_graph_book = FALSE) - }, - - #' @description - #' Remove a link by its name. - #' @param link_name The name of the link to remove. - remove_link = function(link_name) { - if (!link_name %in% names(private$.links)) stop(link_name, " not found.") - private$.links[[link_name]] <- NULL - cat("Link removed:", link_name) - }, - - #' @description - #' Get the factor levels of a specified column in a data table. - #' @param data_name The name of the data table. - #' @param col_name The name of the column to check. - get_column_factor_levels = function(data_name, col_name = "") { - self$get_data_objects(data_name)$get_column_factor_levels(col_name) - }, - - #' @description - #' Get the data frame for a specified factor column. - #' @param data_name The name of the data table. - #' @param col_name The name of the column to retrieve. - #' @param include_levels A boolean indicating whether to include levels. - #' @param include_NA_level A boolean indicating whether to include NA as a level. - get_factor_data_frame = function(data_name, col_name = "", include_levels = TRUE, include_NA_level = FALSE) { - self$get_data_objects(data_name)$get_factor_data_frame(col_name = col_name, include_levels = include_levels, include_NA_level = include_NA_level) - }, - - #' @description - #' Sort a data frame by specified column(s). - #' @param data_name The name of the data table. - #' @param col_names A vector of column names to sort by. - #' @param decreasing A boolean indicating whether to sort in decreasing order. - #' @param na.last A boolean indicating how to handle NA values. - #' @param by_row_names A boolean indicating whether to sort by row names. - #' @param row_names_as_numeric A boolean indicating whether row names should be treated as numeric. - sort_dataframe = function(data_name, col_names = c(), decreasing = FALSE, na.last = TRUE, by_row_names = FALSE, row_names_as_numeric = TRUE) { - self$get_data_objects(data_name)$sort_dataframe(col_names = col_names, decreasing = decreasing, na.last = na.last, by_row_names = by_row_names, row_names_as_numeric = row_names_as_numeric) - }, - - #' @description - #' Rename a data frame and optionally update its label. - #' @param data_name The current name of the data frame. - #' @param new_value The new name for the data frame. - #' @param label An optional label for the data frame. - rename_dataframe = function(data_name, new_value = "", label = "") { - data_obj <- self$get_data_objects(data_name) - if (data_name != new_value) { - if (tolower(new_value) %in% tolower(names(private$.data_sheets)[-which(names(private$.data_sheets) == data_name)])) stop("Cannot rename data frame since ", new_value, " is an existing data frame.") - names(private$.data_sheets)[names(private$.data_sheets) == data_name] <- new_value - data_obj$append_to_metadata(data_name_label, new_value) - self$update_links_rename_data_frame(data_name, new_value) - } - if (label != "") { - data_obj$append_to_metadata(property = "label", new_val = label) - } - data_obj$set_data_changed(TRUE) - data_obj$set_metadata_changed(TRUE) - data_obj$set_variables_metadata_changed(TRUE) - if (exists(".graph_data_book")) .graph_data_book$rename_dataframe(data_name = data_name, new_value = new_value, label = label) - }, - - #' @description - #' Convert specified columns to a different type. - #' @param data_name The name of the data table. - #' @param col_names A vector of column names to convert. - #' @param to_type The target data type. - #' @param factor_values Optional values for factors. - #' @param set_digits Number of digits to set. - #' @param set_decimals A boolean indicating whether to set decimals. - #' @param keep_attr A boolean indicating whether to keep attributes. - #' @param ignore_labels A boolean indicating whether to ignore labels. - #' @param keep.labels A boolean indicating whether to keep labels. - convert_column_to_type = function(data_name, col_names = c(), to_type, factor_values = NULL, set_digits, set_decimals = FALSE, keep_attr = TRUE, ignore_labels = FALSE, keep.labels = TRUE) { - self$get_data_objects(data_name)$convert_column_to_type(col_names = col_names, to_type = to_type, factor_values = factor_values, set_digits = set_digits, set_decimals = set_decimals, keep_attr = keep_attr, ignore_labels = ignore_labels, keep.labels = keep.labels) - }, - - #' @title Append Property to Variables Metadata - #' @description Appends a new property and its value to the metadata of specified columns in a data table. - #' @param data_name The name of the data table. - #' @param col_names A vector of column names to which the property should be appended. - #' @param property The name of the property to append. - #' @param new_val The value of the property to append. Default is an empty string. - #' @return None - append_to_variables_metadata = function(data_name, col_names, property, new_val = "") { - self$get_data_objects(data_name)$append_to_variables_metadata(col_names, property, new_val) - }, - - #' @title Append Property to Dataframe Metadata - #' @description Appends a new property and its value to the metadata of a data table. - #' @param data_name The name of the data table. - #' @param property The name of the property to append. - #' @param new_val The value of the property to append. Default is an empty string. - #' @return None - append_to_dataframe_metadata = function(data_name, property, new_val = "") { - self$get_data_objects(data_name)$append_to_metadata(property, new_val) - }, - - #' @title Append Property to Metadata - #' @description Appends a new property and its value to the metadata of the current object. - #' @param property The name of the property to append. - #' @param new_val The value of the property to append. Default is an empty string. - #' @param allow_override_special Boolean flag to allow overriding special properties. Default is FALSE. - #' @return None - append_to_metadata = function(property, new_val = "", allow_override_special = FALSE) { - if(missing(property)) stop("property and new_val arguments must be specified.") - if(!is.character(property)) stop("property must be of type character") - if(!allow_override_special && property %in% c("class")) message("Cannot override property: ", property, ". Specify allow_override_special = TRUE to replace this property.") - else { - attr(self, property) <- new_val - self$metadata_changed <- TRUE - self$append_to_changes(list(Added_metadata, property)) - } - }, - - #' @title Add Metadata Field - #' @description Adds a new metadata field and its value to the specified data table or all data tables. - #' @param data_name The name of the data table. Use overall_label to apply to all data tables. - #' @param property The name of the property to append. - #' @param new_val The value of the property to append. Default is an empty string. - #' @return None - add_metadata_field = function(data_name, property, new_val = "") { - if(missing(property)) stop("property and new_val arguments must be specified.") - if(data_name == overall_label) { - invisible(sapply(self$get_data_objects(), function(x) x$append_to_metadata(property, new_val))) - } else { - invisible(sapply(self$get_data_objects(data_name, as_list = TRUE), function(x) x$append_to_variables_metadata(property = property, new_val = new_val))) - } - }, - - #' @title Reorder Dataframes - #' @description Reorders the dataframes in the object according to the specified order. - #' @param data_frames_order A vector specifying the new order of dataframes. - #' @return None - reorder_dataframes = function(data_frames_order) { - if(length(data_frames_order) != length(names(private$.data_sheets))) stop("number data frames to order should be equal to number of dataframes in the object") - if(!setequal(data_frames_order, names(private$.data_sheets))) stop("data_frames_order must be a permutation of the dataframe names.") - self$set_data_objects(private$.data_sheets[data_frames_order]) - self$data_objects_changed <- TRUE - }, - - #' @title Copy Columns - #' @description Copies specified columns from a data table to another location or clipboard. - #' @param data_name The name of the data table. - #' @param col_names A vector of column names to copy. - #' @param copy_to_clipboard Boolean flag to copy to clipboard. Default is FALSE. - #' @return None - copy_columns = function(data_name, col_names = "", copy_to_clipboard = FALSE) { - if(copy_to_clipboard){ - col_data_obj <- self$get_columns_from_data(data_name = data_name, col_names = col_names, force_as_data_frame = TRUE) - self$copy_to_clipboard(content = col_data_obj) - }else{ - self$get_data_objects(data_name)$copy_columns(col_names = col_names) - } - }, - - #' @title Drop Unused Factor Levels - #' @description Drops unused levels from a factor column in the specified data table. - #' @param data_name The name of the data table. - #' @param col_name The name of the column. - #' @return None - drop_unused_factor_levels = function(data_name, col_name) { - self$get_data_objects(data_name)$drop_unused_factor_levels(col_name = col_name) - }, - - #' @title Set Factor Levels - #' @description Sets new levels for a factor column in the specified data table. - #' @param data_name The name of the data table. - #' @param col_name The name of the column. - #' @param new_labels A vector of new labels for the factor levels. - #' @param new_levels A vector of new levels. - #' @param set_new_labels Boolean flag to set new labels. Default is TRUE. - #' @return None - set_factor_levels = function(data_name, col_name, new_labels, new_levels, set_new_labels = TRUE) { - self$get_data_objects(data_name)$set_factor_levels(col_name = col_name, new_labels = new_labels, new_levels = new_levels, set_new_labels = set_new_labels) - }, - - #' @title Edit Factor Level - #' @description Edits a level in a factor column in the specified data table. - #' @param data_name The name of the data table. - #' @param col_name The name of the column. - #' @param old_level The old level to replace. - #' @param new_level The new level to set. - #' @return None - edit_factor_level = function(data_name, col_name, old_level, new_level) { - self$get_data_objects(data_name)$edit_factor_level(col_name = col_name, old_level = old_level, new_level = new_level) - }, - - #' @title Set Factor Reference Level - #' @description Sets the reference level for a factor column in the specified data table. - #' @param data_name The name of the data table. - #' @param col_name The name of the column. - #' @param new_ref_level The new reference level. - #' @return None - set_factor_reference_level = function(data_name, col_name, new_ref_level) { - self$get_data_objects(data_name)$set_factor_reference_level(col_name = col_name, new_ref_level = new_ref_level) - }, - - #' @title Get Column Count - #' @description Returns the number of columns in the specified data table. - #' @param data_name The name of the data table. - #' @param use_column_selection Boolean flag to use column selection. Default is FALSE. - #' @return The number of columns. - get_column_count = function(data_name, use_column_selection = FALSE) { - return(self$get_data_objects(data_name)$get_column_count(use_column_selection)) - }, - - #' @title Reorder Factor Levels - #' @description Reorders the levels of a factor column in the specified data table. - #' @param data_name The name of the data table. - #' @param col_name The name of the column. - #' @param new_level_names A vector specifying the new order of factor levels. - #' @return None - reorder_factor_levels = function(data_name, col_name, new_level_names) { - self$get_data_objects(data_name)$reorder_factor_levels(col_name = col_name, new_level_names = new_level_names) - }, - - #' @title Get Data Type - #' @description Returns the data type of the specified column in the given data table. - #' @param data_name The name of the data table. - #' @param col_name The name of the column. - #' @return The data type of the column. - get_data_type = function(data_name, col_name) { - self$get_data_objects(data_name)$get_data_type(col_name = col_name) - }, - - #' @title Copy Data Frame - #' @description Copies a data frame to a new name or clipboard. - #' @param data_name The name of the data table. - #' @param new_name The new name for the copied data frame. - #' @param label A label for the new data frame. Default is an empty string. - #' @param copy_to_clipboard Boolean flag to copy to clipboard. Default is FALSE. - #' @return None - copy_data_frame = function(data_name, new_name, label = "", copy_to_clipboard = FALSE) { - if(copy_to_clipboard){ - self$copy_to_clipboard(content = self$get_data_frame(data_name)) - }else{ - if(new_name %in% names(private$.data_sheets)) stop("Cannot copy data frame since ", new_name, " is an existing data frame.") - curr_obj <- self$get_data_objects(data_name)$clone(deep = TRUE) - if(missing(new_name)) new_name <- next_default_item(data_name, self$get_data_names()) - self$append_data_object(new_name, curr_obj) - new_data_obj <- self$get_data_objects(new_name) - new_data_obj$data_changed <- TRUE - new_data_obj$set_data_changed(TRUE) - if(label != "") { - new_data_obj$append_to_metadata(property = "label" , new_val = label) - new_data_obj$set_metadata_changed(TRUE) - } - } - }, - - #' @title Copy Column Metadata to Clipboard - #' @description Copies the metadata of specified columns to the clipboard. - #' @param data_name The name of the data table. - #' @param property_names A vector of property names to copy. Default is all properties. - #' @return None - copy_col_metadata_to_clipboard = function(data_name, property_names) { - if(missing(property_names)){ - self$copy_to_clipboard(content = self$get_variables_metadata(data_name = data_name)) - }else{ - self$copy_to_clipboard(content = self$get_variables_metadata(data_name = data_name, property = property_names)) - } - }, - - #' @title Copy Data Frame Metadata to Clipboard - #' @description Copies the metadata of the specified data table to the clipboard. - #' @param data_name The name of the data table. - #' @param property_names A vector of property names to copy. Default is all properties. - #' @return None - copy_data_frame_metadata_to_clipboard = function(data_name, property_names) { - if(missing(property_names)){ - self$copy_to_clipboard(content = self$get_data_frame_metadata(data_name = data_name)) - }else{ - self$copy_to_clipboard(content = self$get_data_frame_metadata(data_name = data_name, label = property_names)) - } - }, - - #' @title Copy to Clipboard - #' @description Copies the specified content to the clipboard. - #' @param content The content to copy to the clipboard. - #' @return None - copy_to_clipboard = function(content) { - clipr::write_clip(content = content) - }, - - #' @title Set Hidden Columns - #' @description Sets the specified columns as hidden in the given data table. - #' @param data_name The name of the data table. - #' @param col_names A vector of column names to set as hidden. - #' @return None - set_hidden_columns = function(data_name, col_names = c()) { - self$get_data_objects(data_name)$set_hidden_columns(col_names = col_names) - }, - - #' @title Unhide All Columns - #' @description Unhides all columns in the specified data table or all data tables if data_name is missing. - #' @param data_name The name of the data table. If missing, applies to all data tables. - #' @return None - unhide_all_columns = function(data_name) { - if(missing(data_name)) { - invisible(sapply(self$get_data_objects(), function(obj) obj$unhide_all_columns())) - } else { - self$get_data_objects(data_name)$unhide_all_columns() - } - }, - - #' @title Set Hidden Data Frames - #' @description Sets the specified data tables as hidden. - #' @param data_names A vector of data table names to set as hidden. - #' @return None - set_hidden_data_frames = function(data_names = c()) { - invisible(sapply(data_names, function(x) self$append_to_dataframe_metadata(data_name = x, property = is_hidden_label, new_val = TRUE))) - unhide_data_names <- setdiff(self$get_data_names(), data_names) - invisible(sapply(unhide_data_names, function(x) self$append_to_dataframe_metadata(data_name = x, property = is_hidden_label, new_val = FALSE))) - }, - - #' @title Get Hidden Data Frames - #' @description Returns a list of hidden data tables. - #' @return A vector of hidden data table names. - get_hidden_data_frames = function() { - all_data_names <- names(private$.data_sheets) - visible_data_names <- all_data_names[sapply(all_data_names, function(x) !isTRUE(self$get_data_objects(x)$get_metadata(label = is_hidden_label)))] - hidden_data_names <- setdiff(all_data_names, visible_data_names) - return(hidden_data_names) - }, - - #' @title Set Row Names - #' @description Sets the row names for the specified data table. - #' @param data_name The name of the data table. - #' @param row_names A vector of row names to set. - #' @return None - set_row_names = function(data_name, row_names) { - self$get_data_objects(data_name)$set_row_names(row_names = row_names) - }, - - #' @title Get Row Names - #' @description Returns the row names of the specified data table. - #' @param data_name The name of the data table. - #' @return A vector of row names. - get_row_names = function(data_name) { - self$get_data_objects(data_name)$get_row_names() - }, - - #' @title Set Protected Columns - #' @description Sets the specified columns as protected in the given data table. - #' @param data_name The name of the data table. - #' @param col_names A vector of column names to set as protected. - #' @return None - set_protected_columns = function(data_name, col_names) { - self$get_data_objects(data_name)$set_protected_columns(col_names = col_names) - }, - - #' @title Get Metadata Fields - #' @description Returns the metadata fields of the specified data table. - #' @param data_name The name of the data table. - #' @param include_overall Boolean flag to include overall metadata fields. Default is TRUE. - #' @param as_list Boolean flag to return the result as a list. Default is FALSE. - #' @param include A vector of metadata fields to include. Default is all fields. - #' @param exclude A vector of metadata fields to exclude. Default is none. - #' @param excluded_items A vector of metadata fields to exclude. Default is an empty vector. - #' @return A vector or list of metadata fields. - get_metadata_fields = function(data_name, include_overall, as_list = FALSE, include, exclude, excluded_items = c()) { - if(!missing(data_name)) { - if(data_name == overall_label) { - out = names(self$get_combined_metadata()) - if(length(excluded_items) > 0){ - ex_ind = which(out %in% excluded_items) - if(length(ex_ind) != length(excluded_items)) warning("Some of the excluded_items were not found in the list of objects") - if(length(ex_ind) > 0) out = out[-ex_ind] - } - if(as_list) { - lst = list() - lst[[data_name]] <- out - return(lst) - } - else return(out) - } else { - return(self$get_data_objects(data_name)$get_variables_metadata_fields(as_list = as_list, include = include, exclude = exclude, excluded_items = excluded_items)) - } - } else { - out = list() - if(include_overall) out[[overall_label]] <- names(self$get_combined_metadata()) - for(data_obj_name in self$get_data_names()) { - out[[data_obj_name]] <- self$get_data_objects(data_obj_name)$get_variables_metadata_fields(as_list = FALSE, include = include, exclude = exclude) - } - return(out) - } - }, - - #' @title Freeze Columns - #' @description Freezes the specified columns in the given data table. - #' @param data_name The name of the data table. - #' @param column A vector of column names to freeze. - #' @return None - freeze_columns = function(data_name, column) { - self$get_data_objects(data_name)$freeze_columns(column = column) - }, - - #' @title Unfreeze Columns - #' @description Unfreezes all columns in the specified data table. - #' @param data_name The name of the data table. - #' @return None - unfreeze_columns = function(data_name) { - self$get_data_objects(data_name)$unfreeze_columns() - }, - - #' @title Is Variables Metadata - #' @description Checks if the specified property is metadata for the given columns in the data table. - #' @param data_name The name of the data table. - #' @param property The name of the property to check. - #' @param column The name of the column. - #' @param return_vector Boolean flag to return the result as a vector. Default is FALSE. - #' @return A boolean value indicating if the property is metadata for the columns. - is_variables_metadata = function(data_name, property, column, return_vector = FALSE) { - self$get_data_objects(data_name)$is_variables_metadata(property, column, return_vector) - }, - - #' @title Data Frame Exists - #' @description Checks if the specified data table exists. - #' @param data_name The name of the data table. - #' @return A boolean value indicating if the data table exists. - data_frame_exists = function(data_name) { - return(data_name %in% names(private$.data_sheets)) - }, - - #' @title Add Key - #' @description Adds a key to the specified columns in the given data table. - #' @param data_name The name of the data table. - #' @param col_names A vector of column names to add as keys. - #' @param key_name The name of the key. - #' @return None - add_key = function(data_name, col_names, key_name) { - self$get_data_objects(data_name)$add_key(col_names, key_name) - names(col_names) <- col_names - self$add_link(data_name, data_name, col_names, keyed_link_label) - invisible(sapply(self$get_data_objects(), function(x) if(!x$is_metadata(is_linkable)) x$append_to_metadata(is_linkable, FALSE))) - }, - - #' @title Is Key - #' @description Checks if the specified columns are keys in the given data table. - #' @param data_name The name of the data table. - #' @param col_names A vector of column names to check. - #' @return A boolean value indicating if the columns are keys. - is_key = function(data_name, col_names) { - self$get_data_objects(data_name)$is_key(col_names) - }, - - #' @title Has Key - #' @description Checks if the specified data table has a key. - #' @param data_name The name of the data table. - #' @return A boolean value indicating if the data table has a key. - has_key = function(data_name) { - self$get_data_objects(data_name)$has_key() - }, - - #' @title Get Keys - #' @description Returns the keys of the specified data table. - #' @param data_name The name of the data table. - #' @param key_name The name of the key. Default is all keys. - #' @return A list of keys. - get_keys = function(data_name, key_name) { - self$get_data_objects(data_name)$get_keys(key_name) - }, - - #' @title Add New Comment - #' @description Adds a new comment to the specified row and column in the given data table. - #' @param data_name The name of the data table. - #' @param row The name of the row. - #' @param column The name of the column. - #' @param comment The comment text. - #' @return None - add_new_comment = function(data_name, row = "", column = "", comment) { - if (!self$has_key(data_name)) stop("A key must be defined in the data frame to add a comment. Use the Add Key dialog to define a key.") - if (!".comment" %in% self$get_data_names()) { - comment_df <- data.frame(sheet = character(0), - row = character(0), - column = character(0), - id = numeric(0), - comment = character(0), - time_stamp = as.POSIXct(c())) - self$import_data(data_tables = list(.comment = comment_df)) - self$add_key(".comment", c("sheet", "row", "id"), "key1") - } - comment_df <- self$get_data_frame(".comment", use_current_filter = FALSE) - curr_df <- self$get_data_frame(data_name, use_current_filter = FALSE) - if(row != ""){ - curr_row <- curr_df[row.names(curr_df) == row, ] - key <- self$get_keys(data_name)[[1]] - key_cols <- as.character(key) - key_vals <- paste(sapply(curr_row[, key_cols], as.character), collapse = "__") - } else { - key_vals <- "" - } - curr_comments <- comment_df[comment_df$sheet == data_name & comment_df$row == key_vals, ] - new_id <- 1 - if (nrow(curr_comments) > 0) new_id <- max(curr_comments$id) + 1 - comment_df[nrow(comment_df) + 1, ] <- list(sheet = data_name, - row = key_vals, - column = column, - id = new_id, - comment = comment, - time_stamp = Sys.time()) - self$get_data_objects(".comment")$set_data(new_data = comment_df) - }, - - #' @title Get Comments - #' @description Returns the comments for the specified data table and comment ID. - #' @param data_name The name of the data table. - #' @param comment_id The ID of the comment. - #' @return A data frame of comments. - get_comments = function(data_name, comment_id) { - self$get_data_objects(data_name)$get_comments(comment_id) - }, - - #' @title Get Links - #' @description Returns the links for the specified link name or all links. - #' @param link_name The name of the link. Default is all links. - #' @return A list of links. - get_links = function(link_name, ...) { - if(!missing(link_name)) { - if(!link_name %in% names(private$.links)) stop(link_name, " not found.") - return(private$.links[[link_name]]) - } else { - return(private$.links) - } - }, - - #' @title Set Structure Columns - #' @description Sets the structure columns for the specified data table. - #' @param data_name The name of the data table. - #' @param struc_type_1 A vector of column names for the first structure type. - #' @param struc_type_2 A vector of column names for the second structure type. - #' @param struc_type_3 A vector of column names for the third structure type. - #' @return None - set_structure_columns = function(data_name, struc_type_1 = c(), struc_type_2 = c(), struc_type_3 = c()) { - self$get_data_objects(data_name)$set_structure_columns(struc_type_1, struc_type_2, struc_type_3) - }, - - #' @title Add Dependent Columns - #' @description Adds dependent columns to the specified columns in the given data table. - #' @param data_name The name of the data table. - #' @param columns A vector of column names to add dependents to. - #' @param dependent_cols A vector of dependent column names. - #' @return None - add_dependent_columns = function(data_name, columns, dependent_cols) { - self$get_data_objects(data_name)$add_dependent_columns(columns, dependent_cols) - }, - - #' @title Set Column Colours - #' @description Sets the colours for the specified columns in the given data table. - #' @param data_name The name of the data table. - #' @param columns A vector of column names to set colours for. - #' @param colours A vector of colours. - #' @return None - set_column_colours = function(data_name, columns, colours) { - self$get_data_objects(data_name)$set_column_colours(columns, colours) - }, - - #' @title Has Colours - #' @description Checks if the specified columns have colours in the given data table. - #' @param data_name The name of the data table. - #' @param columns A vector of column names to check. - #' @return A boolean value indicating if the columns have colours. - has_colours = function(data_name, columns) { - self$get_data_objects(data_name)$has_colours(columns) - }, - - #' @title Remove Column Colours - #' @description Removes the colours from all columns in the specified data table. - #' @param data_name The name of the data table. - #' @return None - remove_column_colours = function(data_name) { - self$get_data_objects(data_name)$remove_column_colours() - }, - - #' @title Set Column Colours by Metadata - #' @description Sets the colours for the specified columns based on metadata in the given data table. - #' @param data_name The name of the data table. - #' @param columns A vector of column names to set colours for. - #' @param property The metadata property to use for setting colours. - #' @return None - set_column_colours_by_metadata = function(data_name, columns, property) { - self$get_data_objects(data_name)$set_column_colours_by_metadata(data_name, columns, property) - }, - - #' @title Graph One Variable - #' @description Creates a graph for a single variable in the specified data table. - #' @param data_name The name of the data table. - #' @param columns A vector of column names to graph. - #' @param numeric The type of graph for numeric columns. Default is "geom_boxplot". - #' @param categorical The type of graph for categorical columns. Default is "geom_bar". - #' @param character The type of graph for character columns. Default is "geom_bar". - #' @param output The output type for the graph. Default is "facets". - #' @param free_scale_axis Boolean flag to allow free scaling of axes. Default is FALSE. - #' @param ncol The number of columns in the output. Default is NULL. - #' @param coord_flip Boolean flag to flip coordinates. Default is FALSE. - #' @param ... Additional arguments passed to the graph function. - #' @return None - graph_one_variable = function(data_name, columns, numeric = "geom_boxplot", categorical = "geom_bar", character = "geom_bar", output = "facets", free_scale_axis = FALSE, ncol = NULL, coord_flip = FALSE, ...) { - self$get_data_objects(data_name)$graph_one_variable(columns = columns, numeric = numeric, categorical = categorical, output = output, free_scale_axis = free_scale_axis, ncol = ncol, coord_flip = coord_flip, ... = ...) - }, - - #' @title Make Date YearMonthDay - #' @description Creates a date column from year, month, and day columns in the specified data table. - #' @param data_name The name of the data table. - #' @param year The name of the year column. - #' @param month The name of the month column. - #' @param day The name of the day column. - #' @param f_year The format for the year column. - #' @param f_month The format for the month column. - #' @param f_day The format for the day column. - #' @param year_format The format for the year. Default is "%Y". - #' @param month_format The format for the month. Default is "%m". - #' @return None - make_date_yearmonthday = function(data_name, year, month, day, f_year, f_month, f_day, year_format = "%Y", month_format = "%m") { - self$get_data_objects(data_name)$make_date_yearmonthday(year = year, month = month, day = day, f_year = f_year, f_month = f_month, f_day = f_day, year_format = year_format, month_format = month_format) - }, - - #' @title Make Date YearDoY - #' @description Creates a date column from year and day of year columns in the specified data table. - #' @param data_name The name of the data table. - #' @param year The name of the year column. - #' @param doy The name of the day of year column. - #' @param base The base date for the day of year. - #' @param doy_typical_length The typical length of the day of year. Default is "366". - #' @return None - make_date_yeardoy = function(data_name, year, doy, base, doy_typical_length = "366") { - self$get_data_objects(data_name)$make_date_yeardoy(year = year, doy = doy, base = base, doy_typical_length = doy_typical_length) - }, - - #' @title Set Contrasts of Factor - #' @description Sets the contrasts for a factor column in the specified data table. - #' @param data_name The name of the data table. - #' @param col_name The name of the column. - #' @param new_contrasts A vector of new contrasts. - #' @param defined_contr_matrix A defined contrast matrix. - #' @return None - set_contrasts_of_factor = function(data_name, col_name, new_contrasts, defined_contr_matrix) { - self$get_data_objects(data_name)$set_contrasts_of_factor(col_name = col_name, new_contrasts = new_contrasts, defined_contr_matrix = defined_contr_matrix) - }, - - #' @title Create Factor Data Frame - #' @description Creates a new data frame for a factor column in the specified data table. - #' @param data_name The name of the data table. - #' @param factor The name of the factor column. - #' @param factor_data_frame_name The name of the new data frame. - #' @param include_contrasts Boolean flag to include contrasts. Default is FALSE. - #' @param replace Boolean flag to replace the existing factor data frame. Default is FALSE. - #' @param summary_count Boolean flag to include summary count. Default is TRUE. - #' @return None - create_factor_data_frame = function(data_name, factor, factor_data_frame_name, include_contrasts = FALSE, replace = FALSE, summary_count = TRUE) { - curr_data_obj <- self$get_data_objects(data_name) - if(!factor %in% names(curr_data_obj$get_data_frame())) stop(factor, " not found in the data") - if(!is.factor(curr_data_obj$get_columns_from_data(factor))) stop(factor, " is not a factor column.") - if(self$link_exists_from(data_name, factor)) { - message("Factor data frame already exists.") - if(replace) { - message("Current factor data frame will be replaced.") - factor_named <- factor - names(factor_named) <- factor - curr_factor_df_name <- self$get_linked_to_data_name(data_name, factor_named) - if(length(curr_factor_df_name) > 0) self$delete_dataframes(curr_factor_df_name[1]) - } else { - warning("replace = FALSE so no action will be taken.") - } - } - data_frame_list <- list() - if(missing(factor_data_frame_name)) factor_data_frame_name <- paste0(data_name, "_", factor) - factor_data_frame_name <- make.names(factor_data_frame_name) - factor_data_frame_name <- next_default_item(factor_data_frame_name, self$get_data_names(), include_index = FALSE) - factor_column <- curr_data_obj$get_columns_from_data(factor) - factor_data_frame <- data.frame(levels(factor_column)) - names(factor_data_frame) <- factor - if(include_contrasts) factor_data_frame <- cbind(factor_data_frame, contrasts(factor_column)) - if(summary_count) factor_data_frame <- cbind(factor_data_frame, summary(factor_column)) - row.names(factor_data_frame) <- 1:nrow(factor_data_frame) - names(factor_data_frame)[2:ncol(factor_data_frame)] <- paste0("C", 1:(ncol(factor_data_frame)-1)) - if(summary_count) colnames(factor_data_frame)[ncol(factor_data_frame)] <- "Frequencies" - data_frame_list[[factor_data_frame_name]] <- factor_data_frame - self$import_data(data_frame_list) - factor_data_obj <- self$get_data_objects(factor_data_frame_name) - factor_data_obj$add_key(factor) - names(factor) <- factor - self$add_link(from_data_frame = data_name, to_data_frame = factor_data_frame_name, link_pairs = factor, type = keyed_link_label) - }, - - #' @title Split Date - #' @description Splits a date column into multiple date components in the specified data table. - #' @param data_name The name of the data table. - #' @param col_name The name of the date column. - #' @param year_val Boolean flag to include year value. Default is FALSE. - #' @param year_name Boolean flag to include year name. Default is FALSE. - #' @param leap_year Boolean flag to include leap year. Default is FALSE. - #' @param month_val Boolean flag to include month value. Default is FALSE. - #' @param month_abbr Boolean flag to include month abbreviation. Default is FALSE. - #' @param month_name Boolean flag to include month name. Default is FALSE. - #' @param week_val Boolean flag to include week value. Default is FALSE. - #' @param week_abbr Boolean flag to include week abbreviation. Default is FALSE. - #' @param week_name Boolean flag to include week name. Default is FALSE. - #' @param weekday_val Boolean flag to include weekday value. Default is FALSE. - #' @param weekday_abbr Boolean flag to include weekday abbreviation. Default is FALSE. - #' @param weekday_name Boolean flag to include weekday name. Default is FALSE. - #' @param day Boolean flag to include day value. Default is FALSE. - #' @param day_in_month Boolean flag to include day in month. Default is FALSE. - #' @param day_in_year Boolean flag to include day in year. Default is FALSE. - #' @param day_in_year_366 Boolean flag to include day in year (366). Default is FALSE. - #' @param pentad_val Boolean flag to include pentad value. Default is FALSE. - #' @param pentad_abbr Boolean flag to include pentad abbreviation. Default is FALSE. - #' @param dekad_val Boolean flag to include dekad value. Default is FALSE. - #' @param dekad_abbr Boolean flag to include dekad abbreviation. Default is FALSE. - #' @param quarter_val Boolean flag to include quarter value. Default is FALSE. - #' @param quarter_abbr Boolean flag to include quarter abbreviation. Default is FALSE. - #' @param with_year Boolean flag to include with year. Default is FALSE. - #' @param s_start_month The start month. Default is 1. - #' @param s_start_day_in_month The start day in month. Default is 1. - #' @param days_in_month Boolean flag to include days in month. Default is FALSE. - #' @return None - split_date = function(data_name, col_name = "", year_val = FALSE, year_name = FALSE, leap_year = FALSE, month_val = FALSE, month_abbr = FALSE, month_name = FALSE, week_val = FALSE, week_abbr = FALSE, week_name = FALSE, weekday_val = FALSE, weekday_abbr = FALSE, weekday_name = FALSE, day = FALSE, day_in_month = FALSE, day_in_year = FALSE, day_in_year_366 = FALSE, pentad_val = FALSE, pentad_abbr = FALSE, dekad_val = FALSE, dekad_abbr = FALSE, quarter_val = FALSE, quarter_abbr = FALSE, with_year = FALSE, s_start_month = 1, s_start_day_in_month = 1, days_in_month = FALSE) { - self$get_data_objects(data_name)$split_date(col_name = col_name , year_val = year_val, year_name = year_name, leap_year = leap_year, month_val = month_val, month_abbr = month_abbr, month_name = month_name, week_val = week_val, week_abbr = week_abbr, week_name = week_name, weekday_val = weekday_val, weekday_abbr = weekday_abbr, weekday_name = weekday_name, day = day, day_in_month = day_in_month, day_in_year = day_in_year, day_in_year_366 = day_in_year_366, pentad_val = pentad_val, pentad_abbr = pentad_abbr, dekad_val = dekad_val, dekad_abbr = dekad_abbr, quarter_val = quarter_val, quarter_abbr = quarter_abbr, with_year = with_year, s_start_month = s_start_month, s_start_day_in_month = s_start_day_in_month, days_in_month = days_in_month) - }, - - #' @description - #' Create an inventory plot based on the provided data. - #' @param data_name The name of the data table containing inventory data. - #' @param date_col The name of the column representing dates. - #' @param station_col Optional; the name of the column representing station identifiers. - #' @param year_col Optional; the name of the column representing years. - #' @param doy_col Optional; the name of the column representing day of the year. - #' @param element_cols Optional; a vector of column names representing different elements. - #' @param add_to_data Optional; a boolean indicating whether to add the plot to the existing data. - #' @param year_doy_plot Optional; a boolean indicating whether to plot by year and day of year. - #' @param coord_flip Optional; a boolean indicating whether to flip coordinates. - #' @param facet_by Optional; the variable to facet the plot by. - #' @param graph_title The title of the plot. - #' @param graph_subtitle Optional; the subtitle of the plot. - #' @param graph_caption Optional; the caption of the plot. - #' @param title_size Optional; the size of the title text. - #' @param subtitle_size Optional; the size of the subtitle text. - #' @param caption_size Optional; the size of the caption text. - #' @param labelXAxis Optional; the label for the x-axis. - #' @param labelYAxis Optional; the label for the y-axis. - #' @param xSize Optional; the size of the x-axis text. - #' @param ySize Optional; the size of the y-axis text. - #' @param Xangle Optional; the angle of the x-axis labels. - #' @param Yangle Optional; the angle of the y-axis labels. - #' @param scale_xdate Optional; a boolean indicating whether to scale x-axis by date. - #' @param fromXAxis Optional; the starting point for the x-axis. - #' @param toXAxis Optional; the ending point for the x-axis. - #' @param byXaxis Optional; the interval for the x-axis. - #' @param date_ylabels Optional; the labels for the y-axis dates. - #' @param legend_position Optional; the position of the legend. - #' @param xlabelsize Optional; the size of the x-axis label text. - #' @param ylabelsize Optional; the size of the y-axis label text. - #' @param scale Optional; scaling factor for the plot. - #' @param dir Optional; the directory to save the plot. - #' @param row_col_number The number of rows and columns for the plot layout. - #' @param nrow Optional; the number of rows for the plot layout. - #' @param ncol Optional; the number of columns for the plot layout. - #' @param key_colours A vector of colors for the keys in the plot. - #' @param display_rain_days Optional; a boolean indicating whether to display rain days. - #' @param facet_xsize Optional; the size of the x-axis facets. - #' @param facet_ysize Optional; the size of the y-axis facets. - #' @param facet_xangle Optional; the angle of the x-axis facet labels. - #' @param facet_yangle Optional; the angle of the y-axis facet labels. - #' @param scale_ydate Optional; a boolean indicating whether to scale y-axis by date. - #' @param date_ybreaks Optional; the breaks for y-axis dates. - #' @param step Optional; the step for the y-axis. - #' @param rain_cats A list defining categories for rainfall. - make_inventory_plot = function(data_name, date_col, station_col = NULL, year_col = NULL, doy_col = NULL, - element_cols = NULL, add_to_data = FALSE, year_doy_plot = FALSE, - coord_flip = FALSE, facet_by = NULL, graph_title = "Inventory Plot", - graph_subtitle = NULL, graph_caption = NULL, title_size = NULL, - subtitle_size = NULL, caption_size = NULL, labelXAxis, labelYAxis, - xSize = NULL, ySize = NULL, Xangle = NULL, Yangle = NULL, - scale_xdate, fromXAxis = NULL, toXAxis = NULL, byXaxis = NULL, - date_ylabels, legend_position = NULL, xlabelsize = NULL, - ylabelsize = NULL, scale = NULL, dir = "", row_col_number, - nrow = NULL, ncol = NULL, key_colours = c("red", "grey"), - display_rain_days = FALSE, facet_xsize = 9, facet_ysize = 9, - facet_xangle = 90, facet_yangle = 90, scale_ydate = FALSE, - date_ybreaks, step = 1, - rain_cats = list(breaks = c(0, 0.85, Inf), - labels = c("Dry", "Rain"), - key_colours = c("tan3", "blue"))) { - self$get_data_objects(data_name)$make_inventory_plot(date_col = date_col, station_col = station_col, - year_col = year_col, doy_col = doy_col, - element_cols = element_cols, add_to_data = add_to_data, - year_doy_plot = year_doy_plot, coord_flip = coord_flip, - facet_by = facet_by, graph_title = graph_title, - key_colours = key_colours, display_rain_days = display_rain_days, - rain_cats = rain_cats, graph_subtitle = graph_subtitle, - graph_caption = graph_caption, title_size = title_size, - subtitle_size = subtitle_size, caption_size = caption_size, - labelXAxis = labelXAxis, labelYAxis = labelYAxis, - xSize = xSize, ySize = ySize, Xangle = Xangle, - Yangle = Yangle, scale_xdate = scale_xdate, - fromXAxis = fromXAxis, toXAxis = toXAxis, - byXaxis = byXaxis, xlabelsize = xlabelsize, - scale_ydate = scale_ydate, date_ybreaks = date_ybreaks, - step = step, ylabelsize = ylabelsize, - date_ylabels = date_ylabels, legend_position = legend_position, - dir = dir, row_col_number = row_col_number, - nrow = nrow, ncol = ncol, scale = scale, - facet_xsize = facet_xsize, facet_ysize = facet_ysize, - facet_xangle = facet_xangle, facet_yangle = facet_yangle) - }, - - #' @description - #' Import NetCDF data and convert it into a data frame. - #' @param nc The NetCDF file object. - #' @param path Optional; the path to the NetCDF file. - #' @param name The name for the imported data table. - #' @param only_data_vars A boolean indicating whether to only include data variables. - #' @param keep_raw_time A boolean indicating whether to keep raw time data. - #' @param include_metadata A boolean indicating whether to include metadata. - #' @param boundary Optional; the boundary for the data. - #' @param lon_points Optional; specific longitude points to include. - #' @param lat_points Optional; specific latitude points to include. - #' @param id_points Optional; identifiers for the points to include. - #' @param show_requested_points A boolean indicating whether to show requested points. - #' @param great_circle_dist A boolean indicating whether to calculate great circle distances. - import_NetCDF = function(nc, path, name, only_data_vars = TRUE, keep_raw_time = TRUE, - include_metadata = TRUE, boundary, lon_points = NULL, - lat_points = NULL, id_points = NULL, show_requested_points = TRUE, - great_circle_dist = FALSE) { - if (only_data_vars) { - all_var_names <- ncdf4.helpers::nc.get.variable.list(nc) - } else { - all_var_names <- names(nc$var) - } - remaining_var_names <- all_var_names - var_groups <- list() - dim_groups <- list() - - while (length(remaining_var_names) > 0) { - grp <- remaining_var_names[1] - dim_names <- ncdf4.helpers::nc.get.dim.names(nc, remaining_var_names[1]) - dim_groups[[length(dim_groups) + 1]] <- dim_names - for (curr_var_name in remaining_var_names[-1]) { - if (setequal(ncdf4.helpers::nc.get.dim.names(nc, curr_var_name), dim_names)) { - grp <- c(grp, curr_var_name) - } - } - remaining_var_names <- remaining_var_names[-which(remaining_var_names %in% grp)] - var_groups[[length(var_groups) + 1]] <- grp - } - - data_list <- list() - use_prefix <- (length(seq_along(var_groups)) > 1) - data_names <- c() - - for (i in seq_along(var_groups)) { - if (use_prefix) curr_name <- paste0(name, "_", i) - else curr_name <- name - - if (!missing(boundary)) curr_boundary <- boundary[names(boundary) %in% dim_groups[[i]]] - else curr_boundary <- NULL - - curr_name <- make.names(curr_name) - curr_name <- next_default_item(curr_name, self$get_data_names(), include_index = FALSE) - - if (!missing(path)) { - data_list[[curr_name]] <- multiple_nc_as_data_frame(path = path, vars = var_groups[[i]], - keep_raw_time = keep_raw_time, - include_metadata = include_metadata, - boundary = curr_boundary, lon_points = lon_points, - lat_points = lat_points, id_points = id_points, - show_requested_points = show_requested_points, - great_circle_dist = great_circle_dist) - } else { - data_list[[curr_name]] <- nc_as_data_frame(nc = nc, vars = var_groups[[i]], - keep_raw_time = keep_raw_time, - include_metadata = include_metadata, - boundary = curr_boundary, lon_points = lon_points, - lat_points = lat_points, id_points = id_points, - show_requested_points = show_requested_points, - great_circle_dist = great_circle_dist) - } - - tmp_list <- list() - tmp_list[[curr_name]] <- data_list[[curr_name]] - data_names <- c(data_names, curr_name) - self$import_data(data_tables = tmp_list) - } - - for (i in seq_along(data_names)) { - for (j in seq_along(data_names)) { - if (i != j && !self$link_exists_between(data_names[i], data_names[j]) && - all(dim_groups[[i]] %in% dim_groups[[j]])) { - pairs <- dim_groups[[i]] - names(pairs) <- pairs - self$add_link(data_names[j], data_names[i], pairs, keyed_link_label) - } - } - } - }, - - #' @description - #' Infill missing dates in the specified data. - #' @param data_name The name of the data table to process. - #' @param date_name The name of the column representing dates. - #' @param factors A vector of factors to use for infilling dates. - #' @param start_month The starting month for date infilling. - #' @param start_date The starting date for date infilling. - #' @param end_date The ending date for date infilling. - #' @param resort A boolean indicating whether to resort the data after infilling. - infill_missing_dates = function(data_name, date_name, factors, start_month, start_date, end_date, resort = TRUE) { - self$get_data_objects(data_name)$infill_missing_dates(date_name = date_name, factor = factors, - start_month = start_month, start_date = start_date, - end_date = end_date, resort = resort) - }, - - #' @description - #' Retrieve key names from a specified data table. - #' @param data_name The name of the data table. - #' @param include_overall A boolean indicating whether to include overall keys. - #' @param include A vector of specific keys to include. - #' @param exclude A vector of specific keys to exclude. - #' @param include_empty A boolean indicating whether to include empty keys. - #' @param as_list A boolean indicating whether to return the keys as a list. - #' @param excluded_items A vector of items to exclude from the results. - get_key_names = function(data_name, include_overall = TRUE, include, exclude, - include_empty = FALSE, as_list = FALSE, - excluded_items = c()) { - self$get_data_objects(data_name)$get_key_names(include_overall = include_overall, - include, exclude, include_empty = include_empty, - as_list = as_list, excluded_items = excluded_items) - }, - - #' @description - #' Remove a specified key from a data table. - #' @param data_name The name of the data table. - #' @param key_name The name of the key to remove. - remove_key = function(data_name, key_name) { - self$get_data_objects(data_name)$remove_key(key_name = key_name) - }, - - #' @description - #' Add climdex indices to a specified data table. - #' @param data_name The name of the data table. - #' @param climdex_output The output from climdex calculations. - #' @param freq A string indicating the frequency of the data ('annual' or 'monthly'). - #' @param station The name of the station column (optional). - #' @param year The name of the year column. - #' @param month The name of the month column (optional for monthly frequency). - add_climdex_indices = function(data_name, climdex_output, freq = "annual", - station, year, month) { - stopifnot(freq %in% c("annual", "monthly")) - if (missing(climdex_output)) stop("climdex_output is required.") - if (missing(year)) stop("year is required.") - if (freq == "monthly" && missing(month)) stop("month is required for freq = 'monthly'.") - - col_year <- self$get_columns_from_data(data_name = data_name, col_names = year) - if (!missing(station)) col_station <- self$get_columns_from_data(data_name = data_name, col_names = station) - if (freq == "monthly") col_month <- self$get_columns_from_data(data_name = data_name, col_names = month) - links_cols <- year - if (!missing(station)) links_cols <- c(station, links_cols) - if (freq == "monthly") links_cols <- c(links_cols, month) - linked_data_name <- self$get_linked_to_data_name(data_name, links_cols) - if (length(linked_data_name) == 0) { - # Class matching and data linking logic goes here... - } else { - # Handling existing linked data logic goes here... - } - }, - - #' @description - #' Check if a specified string is part of the metadata for a data table. - #' @param data_name The name of the data table. - #' @param str The string to check in the metadata. - is_metadata = function(data_name, str) { - self$get_data_objects(data_name)$is_metadata(str = str) - }, - - #' @description - #' Get the climatic column name from the specified data table. - #' @param data_name The name of the data table. - #' @param col_name The name of the climatic column to retrieve. - get_climatic_column_name = function(data_name, col_name) { - self$get_data_objects(data_name)$get_climatic_column_name(col_name = col_name) - }, - - #' @description - #' Merge new data into the specified data table. - #' @param data_name The name of the existing data table. - #' @param new_data The new data to be merged. - #' @param by The column(s) to merge by. - #' @param type The type of merge (e.g., "left", "right", "inner"). - #' @param match How to handle matches (e.g., "all" or "first"). - merge_data = function(data_name, new_data, by = NULL, type = "left", match = "all") { - self$get_data_objects(data_name)$merge_data(new_data = new_data, by = by, type = type, match = match) - }, - - #' @description - #' Retrieve names of data tables containing corruption data. - #' @return A vector of names of corruption data tables. - get_corruption_data_names = function() { - corruption_names <- c() - for(curr_name in self$get_data_names()) { - if(self$get_data_objects(curr_name)$is_metadata(corruption_data_label) && - self$get_data_objects(curr_name)$get_metadata(corruption_data_label)) { - corruption_names <- c(corruption_names, curr_name) - } - } - return(corruption_names) - }, - - #' @description - #' Retrieve names of data tables containing corruption contract level data. - #' @return A vector of names of corruption contract data tables. - get_corruption_contract_data_names = function() { - corruption_names <- c() - for(curr_name in self$get_data_names()) { - if(self$get_data_objects(curr_name)$is_metadata(corruption_data_label) && - self$get_data_objects(curr_name)$get_metadata(corruption_data_label) == corruption_contract_level_label) { - corruption_names <- c(corruption_names, curr_name) - } - } - return(corruption_names) - }, - - #' @description - #' Get variable names from a database based on a query. - #' @param query The SQL query to execute. - #' @param data_name The name of the data table. - #' @param include_overall A boolean indicating whether to include overall data. - #' @param include Additional items to include. - #' @param exclude Additional items to exclude. - #' @param include_empty A boolean indicating whether to include empty values. - #' @param as_list A boolean indicating whether to return results as a list. - #' @param excluded_items A vector of items to exclude from results. - #' @return A list or vector of variable names from the database. - get_database_variable_names = function(query, data_name, include_overall = TRUE, include, exclude, include_empty = FALSE, as_list = FALSE, excluded_items = c()) { - if(self$has_database_connection()) { - temp_data <- DBI::dbGetQuery(self$get_database_connection(), query) - if(as_list) { - out <- list() - out[["database"]] <- temp_data[[1]] - return(out) - } else { - return(temp_data[[1]]) - } - } else { - return(list()) - } - }, - - #' @description - #' Get variable names from a NetCDF file. - #' @param file The path to the NetCDF file. - #' @param as_list A boolean indicating whether to return results as a list. - #' @return A list or vector of variable names from the NetCDF file. - get_nc_variable_names = function(file = "", as_list = FALSE, ...) { - if(file == "") { - vars <- "" - } else { - nc_file <- nc_open(file) - vars <- names(nc_file$dim) - } - if(as_list) { - out <- list() - out[["dim variables"]] <- vars - return(out) - } else { - return(vars) - } - }, - - #' @description - #' Check if there is an active database connection. - #' @return A boolean indicating whether a database connection exists. - has_database_connection = function() { - return(!is.null(self$get_database_connection())) - }, - - #' @description - #' Establish a connection to a database. - #' @param dbname The name of the database. - #' @param user The username for database access. - #' @param host The host address of the database. - #' @param port The port number for database connection. - #' @param drv The database driver to use (default is MySQL). - database_connect = function(dbname, user, host, port, drv = RMySQL::MySQL()) { - password <- getPass::getPass(paste0(user, " password:")) - if(length(password) > 0) { - out <- DBI::dbConnect(drv = drv, dbname = dbname, user = user, password = password, host = host, port = port) - if(!is.null(out)) { - self$set_database_connection(out) - } - } - }, - - #' @description - #' Retrieve the current database connection. - #' @return The active database connection object. - get_database_connection = function() { - return(private$.database_connection) - }, - - #' @description - #' Set the database connection. - #' @param dbi_connection The database connection object to set. - set_database_connection = function(dbi_connection) { - private$.database_connection <- dbi_connection - }, - - #' @description - #' Disconnect from the database if a connection exists. - database_disconnect = function() { - if(!is.null(self$get_database_connection())) { - DBI::dbDisconnect(private$.database_connection) - self$set_database_connection(NULL) - } - }, - - #' @description - #' Get the row count of a specified table in the database. - #' @param tableName The name of the table to count rows in. - #' @param query_condition An optional SQL condition to filter the rows. - #' @return The count of rows in the table. - get_db_table_row_count = function(tableName, query_condition = NULL) { - con <- self$get_database_connection() - if(is.null(con)){ - stop("No database connection") - } - - if(is.null(query_condition)){ - query_condition <- "" - } - - out <- DBI::dbGetQuery(con, paste0("SELECT COUNT(*) as result FROM ", tableName, " ", query_condition, ";" )) - return(out$result) - }, - - #' @description - #' Import Climsoft metadata, including stations, elements, and flags. - #' @param import_stations A boolean indicating whether to import station metadata. - #' @param import_elements A boolean indicating whether to import element metadata. - #' @param import_flags A boolean indicating whether to import flag metadata. - import_climsoft_metadata = function(import_stations = FALSE, import_elements = FALSE, import_flags = FALSE) { - if(!import_stations && !import_elements){ - stop("No metadata selected for import") - } - - con <- self$get_database_connection() - if(is.null(con)){ - stop("No database connection") - } - - # Imports metadata - #-------------------------------- - data_list <- list() - - if(import_stations){ - stations_df <- DBI::dbGetQuery(con, "SELECT stationId AS station_id, stationName AS station_name, wmoid, icaoid, latitude, longitude, elevation, qualifier, geoLocationMethod AS geo_location_method, geoLocationAccuracy AS geo_location_accuracy, openingDatetime AS opening_date_time, closingDatetime AS closing_date_time, wacaSelection AS waca_selection, cptSelection AS cpt_selection, stationOperational AS station_operational, drainageBasin AS drainage_basin, country AS country, authority, adminRegion AS admin_region_1, adminRegion2 AS admin_region_2, adminRegion3 AS admin_region_3, adminRegion4 AS admin_region_4 FROM station;") - - columns_to_convert <- c("station_id","station_name","qualifier", "station_operational", "drainage_basin", "country", "authority", "admin_region_1", "admin_region_2", "admin_region_3", "admin_region_4") - stations_df[columns_to_convert] <- lapply(stations_df[columns_to_convert], as.factor) - - stations_df_name <- next_default_item("stations_metadata", self$get_data_names(), include_index = FALSE) - data_list[[stations_df_name]] <- stations_df - } - - if(import_elements){ - elements_df <- DBI::dbGetQuery(con, "SELECT elementId AS element_id, elementName AS element_name, abbreviation, description, elementtype AS element_type, upperLimit AS upper_limit , lowerLimit AS lower_limit, units FROM obselement;") - - columns_to_convert <- c("element_id","element_name","abbreviation","element_type") - elements_df[columns_to_convert] <- lapply(elements_df[columns_to_convert], as.factor) - - elements_df_name <- next_default_item("elements_metadata", self$get_data_names(), include_index = FALSE) - data_list[[elements_df_name]] <- elements_df - } - - if(import_flags){ - flags_df <- DBI::dbGetQuery(con, "SELECT characterSymbol AS flag_name, description FROM flags;") - - flags_df$flag_name <- as.factor(flags_df$flag_name) - - flags_df_name <- next_default_item("flags_metadata", self$get_data_names(), include_index = FALSE) - data_list[[flags_df_name]] <- flags_df - } - - # Import the data frames into the data book - self$import_data(data_tables = data_list) - }, - - #' @description - #' Imports data from Climsoft observation tables, either initial or final. - #' This function also imports selected stations and elements metadata. - #' @param tableName The name of the Climsoft observation table. - #' @param station_filter_column The column name used to filter stations. - #' @param stations A vector of station identifiers to filter the data. - #' @param element_filter_column The column name used to filter elements. - #' @param elements A vector of element identifiers to filter the data. - #' @param qc_status A numeric status for quality control filtering; default is -1 (no filter). - #' @param start_date Optional; start date for filtering observations. - #' @param end_date Optional; end date for filtering observations. - #' @param unstack_data A boolean indicating whether to unstack the data. - #' @param include_element_id A boolean indicating whether to include element IDs in the output. - #' @param include_element_name A boolean indicating whether to include element names in the output. - #' @param include_acquisition_type A boolean indicating whether to include acquisition type in the output. - #' @param include_level A boolean indicating whether to include observation level in the output. - #' @param include_entry_form A boolean indicating whether to include entry form in the output. - #' @param include_captured_by A boolean indicating whether to include the name of the person who captured the data. - #' @param include_qc_status A boolean indicating whether to include quality control status in the output. - #' @param include_qc_log A boolean indicating whether to include the quality control log in the output. - #' @param include_flag A boolean indicating whether to include flags in the output. - #' @param import_selected_stations_metadata A boolean indicating whether to import metadata for selected stations. - #' @param import_selected_elements_metadata A boolean indicating whether to import metadata for selected elements. - import_climsoft_data = function(tableName, - station_filter_column, stations = c(), - element_filter_column, elements = c(), - qc_status = -1, start_date = NULL, end_date = NULL, - unstack_data = FALSE, - include_element_id = FALSE, include_element_name = FALSE, - include_acquisition_type = FALSE, include_level = FALSE, - include_entry_form = FALSE, include_captured_by = FALSE, - include_qc_status = FALSE, include_qc_log = FALSE, - include_flag = FALSE, - import_selected_stations_metadata = FALSE, - import_selected_elements_metadata = FALSE) { - #connection and parameter checks - #-------------------------------- - con <- self$get_database_connection() - if(is.null(con)){ - stop("No database connection") - } - - if(missing(tableName) || missing(station_filter_column) || missing(element_filter_column) || length(stations) == 0 || length(elements) == 0){ - stop("Missing parameters. tableName, station_filter_column, element_filter_column, stations and elements must be supplied") - } - - if (!is.null(start_date) && !lubridate::is.Date(start_date) ) { - stop("start_date must be of type Date.") - } - - if (!is.null(end_date) && !lubridate::is.Date(end_date) ) { - stop("start_date must be of type Date.") - } - #-------------------------------- - - #selects - #-------------------------------- - - sql_select<- paste0(tableName,".recordedFrom AS station_id",", station.stationName AS station_name") - - if(include_element_id){ - sql_select <-paste0(sql_select, ", ", tableName,".describedBy AS element_id") - } - - sql_select <-paste0(sql_select,", obselement.abbreviation AS element_abbrv") - - if(include_element_name){ - sql_select <-paste0(sql_select,", obselement.elementName AS element_name") - } - - if(include_acquisition_type){ - sql_select <-paste0(sql_select,", ", tableName,".acquisitionType"," AS acquisition_type") - } - - if(include_level){ - sql_select <-paste0(sql_select,", ", tableName,".obsLevel"," AS level") - } - - if(include_entry_form){ - sql_select <-paste0(sql_select,", ", tableName,".dataForm"," AS entry_form") - } - - if(include_captured_by){ - sql_select <-paste0(sql_select,", ", tableName,".capturedBy"," AS captured_by") - } - - if(include_qc_status){ - sql_select <-paste0(sql_select,", ", tableName,".qcStatus"," AS qc_status") - } - - sql_select <-paste0(sql_select,", ", tableName,".obsDatetime AS date_time") - sql_select <-paste0(sql_select,", DATE(", tableName,".obsDatetime) AS date") - - if(include_qc_log){ - sql_select <-paste0(sql_select,", ", tableName,".qcTypeLog"," AS qc_log") - } - - if(include_flag){ - sql_select <-paste0(sql_select,", ", tableName,".flag"," AS flag") - } - - sql_select <-paste0(sql_select,", ", tableName,".obsValue AS value") - - sql_select<- paste0("SELECT ", sql_select, " FROM ", tableName, - " INNER JOIN station ON ", tableName, ".recordedFrom = station.stationId", - " INNER JOIN obselement ON ",tableName,".describedBy = obselement.elementId") - #-------------------------------- - - #filters - #-------------------------------- - stations <- gsub("'", "''", stations) # Escape any apostrophes - elements <- gsub("'", "''", elements) # Escape any apostrophes - sql_stations_filter <- paste0(" station.", station_filter_column, " IN ", paste0("(", paste0("'", stations, "'", collapse = ", "), ")")) - sql_elements_filter <- paste0(" obselement.", element_filter_column, " IN ", paste0("(", paste0("'", elements, "'", collapse = ", "), ")")) - - sql_filter <- sql_stations_filter - sql_filter <- paste0(sql_filter," AND ",sql_elements_filter) - - if(qc_status>-1){ - sql_filter <- paste0(sql_filter," AND qcStatus = ", qc_status) - } - - if (!is.null(start_date)) { - sql_filter = paste0(sql_filter," AND obsDatetime >= ", sQuote(format(start_date, format = "%Y-%m-%d"))) - } - - if (!is.null(end_date)) { - sql_filter <- paste0(sql_filter," AND obsDatetime <=", sQuote(format(end_date, format = "%Y-%m-%d"))) - } - - sql_filter<- paste0(" WHERE ",sql_filter) - #-------------------------------- - - #order by - #-------------------------------- - sql_order_by <- paste0(" ORDER BY ",tableName,".recordedFrom, ",tableName, ".describedBy, ",tableName, ".obsDatetime",";") - #-------------------------------- - - # Data list to store all the imported data frames - data_list <- list() - - #import metadata - #-------------------------------- - - if(import_selected_stations_metadata){ - stations_metadata_name <- next_default_item("stations_metadata", self$get_data_names(), include_index = FALSE) - data_list[[stations_metadata_name]] <- DBI::dbGetQuery(con, paste0("SELECT * FROM station WHERE ", sql_stations_filter)) - } - - if(import_selected_elements_metadata){ - elements_metadata_name <- next_default_item("elements_metadata", self$get_data_names(), include_index = FALSE) - data_list[[elements_metadata_name]] <- DBI::dbGetQuery(con, paste0("SELECT * FROM obselement WHERE ", sql_elements_filter)) - } - - #-------------------------------- - - # import and transform observations data data - # -------------------------------- - - # Get observations data from database - observations_df <- DBI::dbGetQuery(con, paste0(sql_select, sql_filter, sql_order_by)) - - # Convert station name and abbreviation columns to factor - columns_to_convert <- c("station_id", "station_name", "element_abbrv") - observations_df[columns_to_convert] <- lapply(observations_df[columns_to_convert], as.factor) - - # Convert the date_time column to POSIXct (date-time) format - observations_df$date_time <- as.POSIXct(observations_df$date_time, format = "%Y-%m-%d %H:%M:%S") - - # convert the date column to date format - observations_df$date <- as.Date(x = observations_df$date) - - if(include_element_id){ - observations_df$element_id <- as.factor(observations_df$element_id) - } - - if(include_element_name){ - observations_df$element_name <- as.factor(observations_df$element_name) - } - - if(include_qc_status){ - observations_df$qc_status <- as.factor(observations_df$qc_status) - } - - if(include_acquisition_type){ - observations_df$acquisition_type <- as.factor(observations_df$acquisition_type) - } - - if(include_level){ - observations_df$level <- as.factor(observations_df$level) - } - - if(include_flag){ - observations_df$flag <- as.factor(observations_df$flag) - } - - if(include_entry_form){ - observations_df$entry_form <- as.factor(observations_df$entry_form) - } - - #-------------------------------- - - # Add observations data to list of data to be imported - # -------------------------------- - observations_data_name <- next_default_item("observations_data", self$get_data_names(), include_index = FALSE) - data_list[[observations_data_name]] <- observations_df - - if(unstack_data){ - observations_unstacked_data_name <- next_default_item("observations_unstacked_data", self$get_data_names(), include_index = FALSE) - data_list[[observations_unstacked_data_name]] <- tidyr::pivot_wider(data = observations_df, names_from=element_abbrv, values_from=value) - } - - # Import list of data frames to data book - self$import_data(data_tables = data_list) - }, - - #' @description - #' Import data from an IRI source and process it. - #' @param download_from Source to download data from. - #' @param data_file Name of the data file to import. - #' @param data_frame_name Name for the data frame created from the imported data. - #' @param location_data_name Name for the location data frame created from the imported data. - #' @param path Path to save the imported data. - #' @param X1 The starting coordinate for the x-axis. - #' @param X2 The ending coordinate for the x-axis (optional). - #' @param Y1 The starting coordinate for the y-axis. - #' @param Y2 The ending coordinate for the y-axis (optional). - #' @param get_area_point Method to determine area point (default is "area"). - import_from_iri = function(download_from, data_file, data_frame_name, location_data_name, path, X1, X2 = NA, Y1, Y2 = NA, get_area_point = "area") { - data_list <- import_from_iri(download_from, data_file, path, X1, X2, Y1, Y2, get_area_point) - names(data_list) = c(next_default_item(prefix = data_frame_name, existing_names = self$get_data_names(), include_index = FALSE), - next_default_item(prefix = location_data_name, existing_names = self$get_data_names(), include_index = FALSE)) - self$import_data(data_tables = data_list) - loc_col_names <- names(data_list[[2]]) - self$add_key(location_data_name, loc_col_names) - names(loc_col_names) <- loc_col_names - self$add_link(from_data_frame = names(data_list)[1], to_data_frame = names(data_list)[2], link_pairs = loc_col_names, type = keyed_link_label) - }, - - #' @description - #' Export the current workspace to a file, including optional components. - #' @param data_names Names of the data frames to export. - #' @param file Destination file to save the workspace. - #' @param include_graphs Whether to include graphs (default is TRUE). - #' @param include_models Whether to include models (default is TRUE). - #' @param include_metadata Whether to include metadata (default is TRUE). - export_workspace = function(data_names, file, include_graphs = TRUE, include_models = TRUE, include_metadata = TRUE) { - e <- new.env() - for(temp_name in data_names) { - e[[temp_name]] <- self$get_data_frame(temp_name, use_current_filter = FALSE) - if(include_graphs) { - graphs <- self$get_objects(data_name = temp_name, object_type_label = "graph") - graph_names <- names(graphs) - for(i in seq_along(graphs)) { - e[[paste(temp_name, graph_names[i], sep = "_")]] <- graphs[[i]] - } - } - if(include_models) { - models <- self$get_objects(data_name = temp_name, object_type_label = "model") - model_names <- names(models) - for(i in seq_along(models)) { - e[[paste(temp_name, model_names[i], sep = "_")]] <- models[[i]] - } - } - if(include_metadata) { - var_metadata <- self$get_variables_metadata(temp_name) - e[[paste(temp_name, "variables_metadata", sep = "_")]] <- var_metadata - } - } - save(list = ls(all.names = TRUE, envir = e), envir = e, file = file) - }, - - #' @description - #' Set new links in the data structure. - #' @param new_links A list of new links to be set. - set_links = function(new_links) { - private$.links <- new_links - }, - - #' @description - #' Display a daily graph for specified climatic elements. - #' @param data_name Name of the data frame containing the data. - #' @param date_col Column name for the date. - #' @param station_col Column name for the station (optional). - #' @param year_col Column name for the year (optional). - #' @param doy_col Column name for the day of the year (optional). - #' @param climatic_element Name of the climatic element to display (optional). - #' @param upper_limit Maximum value for the graph (default is 100). - #' @param bar_colour Color for the bars in the graph (default is "blue"). - #' @param rug_colour Color for the rug plot (default is "red"). - display_daily_graph = function(data_name, date_col = NULL, station_col = NULL, year_col = NULL, doy_col = NULL, climatic_element = NULL, upper_limit = 100, bar_colour = "blue", rug_colour = "red") { - self$get_data_objects(data_name)$display_daily_graph(date_col = date_col, station_col = station_col, year_col = year_col, doy_col = doy_col, climatic_element = climatic_element, rug_colour = rug_colour, bar_colour = bar_colour, upper_limit = upper_limit) - }, - - #' @description - #' Create a set of variables from specified columns in the data frame. - #' @param data_name Name of the data frame. - #' @param set_name Name for the new variable set. - #' @param columns Vector of column names to include in the set. - create_variable_set = function(data_name, set_name, columns) { - self$get_data_objects(data_name)$create_variable_set(set_name = set_name, columns = columns) - }, - - #' @description - #' Update an existing variable set with new columns. - #' @param data_name Name of the data frame. - #' @param set_name Name of the variable set to update. - #' @param columns Vector of new column names to include. - #' @param new_set_name New name for the updated variable set. - update_variable_set = function(data_name, set_name, columns, new_set_name) { - self$get_data_objects(data_name)$update_variable_set(set_name = set_name, columns = columns, new_set_name = new_set_name) - }, - - #' @description - #' Delete specified variable sets from the data frame. - #' @param data_name Name of the data frame. - #' @param set_names Vector of names of variable sets to delete. - delete_variable_sets = function(data_name, set_names) { - self$get_data_objects(data_name)$delete_variable_sets(set_names = set_names) - }, - - #' @description - #' Retrieve the names of variable sets in the data frame. - #' @param data_name Name of the data frame. - #' @param include_overall Whether to include overall set (default is TRUE). - #' @param include Additional filters for inclusion. - #' @param exclude Exclusion filters. - #' @param include_empty Whether to include empty sets (default is FALSE). - #' @param as_list Whether to return as a list (default is FALSE). - #' @param excluded_items Items to exclude from the results. - get_variable_sets_names = function(data_name, include_overall = TRUE, include, exclude, include_empty = FALSE, as_list = FALSE, excluded_items = c()) { - self$get_data_objects(data_name)$get_variable_sets_names(include_overall = include_overall, include = include, exclude = exclude, include_empty = include_empty, as_list = as_list, excluded_items = excluded_items) - }, - - #' @description - #' Get specific variable sets from the data frame. - #' @param data_name Name of the data frame. - #' @param set_names Names of the variable sets to retrieve. - #' @param force_as_list Whether to force the result as a list (default is FALSE). - get_variable_sets = function(data_name, set_names, force_as_list = FALSE) { - self$get_data_objects(data_name)$get_variable_sets(set_names = set_names, force_as_list = force_as_list) - }, - - #' @description - #' Define crop conditions and create a new crop definition data frame. - #' @param data_name Name of the data frame containing the data. - #' @param year Name of the column representing the year. - #' @param station Name of the column for the station (optional). - #' @param rain Name of the column containing rainfall data. - #' @param day Name of the column containing day data. - #' @param rain_totals Column name for rain totals. - #' @param plant_days Column name for planting days. - #' @param plant_lengths Column name for planting lengths. - #' @param start_check Boolean indicating whether to check start day (default is TRUE). - #' @param season_data_name Name of the season data frame (optional). - #' @param start_day Column name for the start day. - #' @param end_day Column name for the end day. - #' @param definition_props Boolean indicating whether to calculate properties (default is TRUE). - #' @param print_table Boolean indicating whether to print the table (default is TRUE). - crops_definitions = function(data_name, year, station, rain, day, rain_totals, plant_days, plant_lengths, start_check = TRUE, season_data_name, start_day, end_day, definition_props = TRUE, print_table = TRUE) { - plant_day_name <- "plant_day" - plant_length_name <- "plant_length" - rain_total_name <- "rain_total" - - is_station <- !missing(station) - - if(missing(year)) stop("Year column must be specified.") - if(!is_station) by <- year - else by <- c(year, station) - if(missing(season_data_name)) season_data_name <- data_name - if(season_data_name != data_name) { - season_by <- self$get_equivalent_columns(from_data_name = data_name, columns = by, to_data_name = season_data_name) - if(is.null(season_by)) stop("The data frames specified must be linked by the year/station columns.") - } - year_col <- self$get_columns_from_data(data_name, year) - unique_year <- na.omit(unique(year_col)) - - expand_list <- list() - names_list <- c() - - expand_list[[length(expand_list) + 1]] <- rain_totals - names_list[length(names_list) + 1] <- rain_total_name - - expand_list[[length(expand_list) + 1]] <- plant_lengths - names_list[length(names_list) + 1] <- plant_length_name - - expand_list[[length(expand_list) + 1]] <- plant_days - names_list[length(names_list) + 1] <- plant_day_name - - expand_list[[length(expand_list) + 1]] <- unique_year - names_list[length(names_list) + 1] <- year - - if(is_station) { - station_col <- self$get_columns_from_data(data_name, station) - unique_station <- na.omit(unique(station_col)) - expand_list[[length(expand_list) + 1]] <- unique_station - names_list[length(names_list) + 1] <- station - } - df <- setNames(expand.grid(expand_list), names_list) - daily_data <- self$get_data_frame(data_name) - if(season_data_name != data_name) { - join_by <- by - names(join_by) <- season_by - season_data <- self$get_data_frame(season_data_name) - vars <- c(season_by, start_day, end_day) - season_data <- season_data %>% dplyr::select(!!! rlang::syms(vars)) - df <- dplyr::left_join(df, season_data, by = join_by) - } - else { - col_names <- c(by, start_day, end_day) - season_data <- daily_data %>% - dplyr::select(!!! rlang::syms(col_names)) %>% - dplyr::group_by(!!! rlang::syms(by)) %>% - dplyr::summarise(!! rlang::sym(start_day) := dplyr::first(!! rlang::sym(start_day)), - !! rlang::sym(end_day) := dplyr::first(!! rlang::sym(end_day))) - df <- dplyr::left_join(df, season_data, by = by) - } - - # Plant day condition - if(start_check) { - df$plant_day_cond <- (df[[start_day]] <= df[[plant_day_name]]) - } - - # Plant length condition - df$length_cond <- (df[[plant_day_name]] + df[[plant_length_name]] <= df[[end_day]]) - - # Rain total condition - df[["rain_total_actual"]] <- sapply(1:nrow(df), - function(x) { - ind <- daily_data[[year]] == df[[year]][x] & daily_data[[day]] >= df[[plant_day_name]][x] & - daily_data[[day]] < (df[[plant_day_name]][x] + df[[plant_length_name]][x]) - if(is_station) ind <- ind & (daily_data[[station]] == df[[station]][x]) - rain_values <- daily_data[[rain]][ind] - sum_rain <- sum(rain_values, na.rm = TRUE) - # TODO + 1 is needed because of non leap years - # if period include 29 Feb then period is 1 less than required length - if(length(rain_values) + 1 < df[[plant_length_name]][x] || (anyNA(rain_values) && sum_rain < df[[rain_total_name]][x])) sum_rain <- NA - sum_rain - } - ) - df$rain_cond <- df[[rain_total_name]] <= df[["rain_total_actual"]] - - # All three conditions met - df$overall_cond <- ((if(start_check) df$plant_day_cond else TRUE) & df$length_cond & df$rain_cond) - - crops_name <- "crop_def" - crops_name <- next_default_item(prefix = crops_name, existing_names = self$get_data_names(), include_index = FALSE) - data_tables <- list(df) - names(data_tables) <- crops_name - self$import_data(data_tables = data_tables) - if(season_data_name != data_name) { - crops_by <- season_by - names(crops_by) <- by - self$add_link(crops_name, season_data_name, crops_by, keyed_link_label) - } - if(definition_props) { - calc_from <- list() - if(!missing(station)) calc_from[[length(calc_from) + 1]] <- station - calc_from[[length(calc_from) + 1]] <- plant_day_name - calc_from[[length(calc_from) + 1]] <- plant_length_name - calc_from[[length(calc_from) + 1]] <- rain_total_name - names(calc_from) <- rep(crops_name, length(calc_from)) - grouping <- instat_calculation$new(type = "by", calculated_from = calc_from) - prop_calc_from <- list("overall_cond") - names(prop_calc_from) <- crops_name - propor_table <- instat_calculation$new(function_exp="sum(overall_cond, na.rm = TRUE)/length(na.omit(overall_cond))", - save = 2, calculated_from = prop_calc_from, - manipulations = list(grouping), - type="summary", result_name = "prop_success", result_data_frame = "crop_prop") - prop_data_frame <- self$run_instat_calculation(propor_table, display = TRUE) - if(print_table) { - prop_data_frame$prop_success <- round(prop_data_frame$prop_success, 2) - prop_table_unstacked <- reshape2::dcast(formula = as.formula(paste(if(!missing(station)) paste(station, "+"), plant_length_name, "+", rain_total_name, "~", plant_day_name)), data = prop_data_frame, value.var = "prop_success") - if(!missing(station)) f <- interaction(prop_table_unstacked[[station]], prop_table_unstacked[[plant_length_name]], lex.order = TRUE) - else f <- prop_table_unstacked[[plant_length_name]] - prop_table_split <- split(prop_table_unstacked, f) - return(prop_table_split) - } - } - }, - - #' @description - #' Tidy climatic data into a specified format. - #' @param x The input data frame containing climatic data. - #' @param format A character string indicating the format of the data; must be either 'days', 'months', or 'years'. - #' @param stack_cols A vector of column names to be stacked. - #' @param day Optional; the name of the day column. - #' @param month Optional; the name of the month column. - #' @param year Optional; the name of the year column. - #' @param stack_years Optional; a vector of years corresponding to the stack columns. - #' @param station Optional; the name of the station column. - #' @param element Optional; the name of the element column. - #' @param element_name The name to assign to the value column for the climatic element. - #' @param ignore_invalid A boolean indicating whether to ignore invalid dates. - #' @param silent A boolean indicating whether to suppress output messages. - #' @param unstack_elements A boolean indicating whether to unstack multiple elements. - #' @param new_name Optional; the name to assign to the resulting tidy data frame. - tidy_climatic_data = function(x, format, stack_cols, day, month, year, - stack_years, station, element, - element_name = "value", - ignore_invalid = FALSE, - silent = FALSE, - unstack_elements = TRUE, - new_name) { - - if(!format %in% c("days", "months", "years")) stop("format must be either 'days', 'months' or 'years'") - if(!all(stack_cols %in% names(x))) stop("Some of the stack_cols were not found in x.") - if(!missing(day) && !day %in% names(x)) stop("day column not found in x.") - if(!missing(month) && !month %in% names(x)) stop("month column not found in x.") - if(!missing(year) && !year %in% names(x)) stop("year column not found in x.") - if(!missing(station) && !station %in% names(x)) stop("station column not found in x.") - if(!missing(element) && !element %in% names(x)) stop("element column not found in x.") - # Default to FALSE and updated if format == "days" - flags <- FALSE - - # check day column is valid (if specified) - if(!missing(day)) { - day_data <- x[[day]] - if(anyNA(day_data)) stop("day column contains: ", sum(is.na(day_data)), " missing values") - if(!is.numeric(day_data)) stop("day column must be numeric") - invalid_day <- (day_data < 1 | day_data > 31 | (day_data %% 1) != 0) - if(any(invalid_day)) { - invalid_values <- unique(day_data[invalid_day]) - stop("day column contains the following invalid values: ", paste(invalid_values, collapse = ",")) - } - } - - # check month column is valid (if specified) - if(!missing(month)) { - month_data <- x[[month]] - # Initialise no month format - month_format <- "" - if(anyNA(month_data)) stop("month column contains: ", sum(is.na(month_data)), " missing values") - if(is.numeric(month_data)) { - invalid_month <- (month_data < 1 | month_data > 12 | (month_data %% 1) != 0) - if(any(invalid_month)) { - invalid_values <- unique(month_data[invalid_month]) - stop("month column contains the following invalid values: ", paste(invalid_values, collapse = ",")) - } - # Month format will be used in as.Date() - month_format <- "%m" - } - # This case is for numeric months but stored as character e.g. c("1", "2") - else if(all(!is.na(as.numeric(month_data)))) { - if(all(as.numeric(month_data) %in% 1:12)) { - month_format <- "%m" - # This ensures format is correct and removes any spaces etc. e.g. "1 " -> 1 - x[[month]] <- as.numeric(month_data) - } - } - else { - # Convert to title case to match month.name and month.abb - month_data_title <- stringr::str_to_title(month_data) - if(all(month_data_title %in% month.abb)) month_format <- "%b" - else if(all(month_data_title %in% month.name)) month_format <- "%B" - if(month_format == "") { - invalid_short <- unique(month_data[!month_data_title %in% month.abb]) - invalid_long <- unique(month_data[!month_data_title %in% month.name]) - if(length(invalid_short) < 12) { - stop("Some month values were not unrecognised.\nIf specifying short names the following are invalid: ", paste(invalid_short, collapse = ", "), "\nAlternatively use a numeric month column.") - } - else if(length(invalid_long) < 12) { - stop("Some month values were not unrecognised.\nIf specifying full names the following are invalid: ", paste(invalid_long, collapse = ", "), "\nAlternatively use a numeric month column.") - } - else stop("No values in the month column were recognised.\nUse either\n short names: ", paste(month.abb, collapse = ", "), "\nfull names: ", paste(month.name, collapse = ", "), "\nor numbers 1 to 12.") - } - # Put title case months into the data as this will be needed to make the date column - x[[month]] <- month_data_title - } - } - - # check year column is valid (if specified) - if(!missing(year)) { - year_data <- x[[year]] - if(anyNA(year_data)) stop("year column contains: ", sum(is.na(year_data)), " missing values") - year_format <- "" - if(!is.numeric(year_data)) { - if(all(!is.na(as.numeric(year_data)))) { - x[[year]] <- as.numeric(year_data) - year_data <- x[[year]] - } - else stop("Cannot recognise years from year column. Try using a numeric year column.") - } - if(all(stringr::str_length(year_data) == 4)) year_format <- "%Y" - else if(all(stringr::str_length(year_data) == 2)) year_format <- "%y" - else stop("Inconsistent values found in year column. Year column must be column of four digit years or column of two digit years") - } - - if(format == "days") { - ndays <- 31 - # month column required in this case - if(missing(month)) stop("month column is required when format == 'days'") - - # year column required in this case - if(missing(year)) stop("year column is required when format == 'days'") - - # stack column checks - if(length(stack_cols) != ndays && length(stack_cols) != 2 * ndays) stop("You have specified: ", length(stack_cols), " stack columns\nThere must be exactly ", ndays, " or ", 2 * ndays, " stack columns when format == 'days'") - - # TRUE if flag columns are included - flags <- length(stack_cols) == 2 * ndays - if(flags) { - # We assume that value/flag columns alternate and are in correct order i.e. c(value1, flag1, value2, flag2, ..., value31, flag31) - val_col_names <- stack_cols[seq(1, 2 * ndays - 1, 2)] - flag_col_names <- stack_cols[seq(2, 2 * ndays, 2)] - # TODO This should be a more global function - if(!all(sapply(x[, val_col_names], function(col) is.numeric(col) || (is.logical(col) && all(is.na(col)))))) stop("Every other column must be numeric to represent values (starting with the first columns). \nThe following value columns are not numeric: ", paste(stack_cols[!sapply(x[, val_col_names], is.numeric)], collapse = ",")) - # Name of flag column - flag_name <- "flag" - } - else { - if(!all(sapply(x[, stack_cols], function(col) is.numeric(col) || (is.logical(col) && all(is.na(col)))))) stop("All stack_cols must be numeric\nThe following stack_cols are not numeric: ", paste(stack_cols[!sapply(x[, stack_cols], is.numeric)], collapse = ",")) - } - - # This ensures all other columns are dropped - y <- data.frame(year = x[[year]], month = x[[month]], x[ , stack_cols]) - if(!missing(station)) y$station <- x[[station]] - if(!missing(element)) y$element <- x[[element]] - # In case element_name is the name of an existing column in y - if(element_name %in% names(y)) element_name <- next_default_item(prefix = element_name, existing_names = names(y)) - if(flags) { - # renaming the stack_cols with a consistent pattern makes it possible for pivot_longer to stack both sets of columns together and construct the day column correctly - # This assumes stack_cols are in the correct order i.e. c(value1, flag1, value2, flag2, ..., value31, flag31) - new_stack_cols <- paste(c("value", "flag"), rep(1:ndays, each = 2), sep = "_") - names(y)[names(y) %in% stack_cols] <- new_stack_cols - # ".value" is a special sentinel used in names_to to ensure names of value columns come from the names of cols. See ?pivot_longer values_to section for details. - y <- tidyr::pivot_longer(y, cols = tidyselect::all_of(new_stack_cols), names_to = c(".value", "day"), names_sep = "_") - } - else { - # renaming the stack_cols so that the day column can be constructed correctly - # This assumes stack_cols are in the correct order i.e. 1 - 31 - new_stack_cols <- paste0("day", 1:ndays) - names(y)[names(y) %in% stack_cols] <- new_stack_cols - y <- tidyr::pivot_longer(y, cols = tidyselect::all_of(new_stack_cols), names_to = "day", values_to = element_name) - # extract day number from e.g. "day10" - y$day <- substr(y$day, 4, 5) - } - - y$date <- as.Date(paste(y$year, y$month, y$day), format = paste(year_format, month_format, "%d")) - } - else if(format == "months") { - if(!all(sapply(x[, stack_cols], function(col) is.numeric(col) || (is.logical(col) && all(is.na(col)))))) stop("All stack_cols must be numeric\nThe following stack_cols are not numeric: ", paste(stack_cols[!sapply(x[, stack_cols], is.numeric)], collapse = ",")) - - # month column required in this case - if(missing(day)) stop("day column is required when format == 'months'") - - # year column required in this case - if(missing(year)) stop("year column is required when format == 'months'") - - # stack column checks - if(length(stack_cols) != 12) stop("You have specified: ", length(stack_cols), " stack columns\nThere must be exactly 12 stack columns when format == 'months'") - - # This ensures all other columns are dropped - y <- data.frame(year = x[[year]], day = x[[day]], x[ , stack_cols]) - if(!missing(station)) y$station <- x[[station]] - if(!missing(element)) y$element <- x[[element]] - # In case element_name is the name of an existing column in y - if(element_name %in% names(y)) element_name <- next_default_item(prefix = element_name, existing_names = names(y)) - # renaming the stack_cols so that the day column can be constructed correctly - # This assumes stack_cols are in the correct order i.e. 1 - 12 - new_stack_cols <- paste0("month", 1:12) - names(y)[names(y) %in% stack_cols] <- new_stack_cols - y <- tidyr::pivot_longer(y, cols = tidyselect::all_of(new_stack_cols), names_to = "month", values_to = element_name) - # extract month number from e.g. "month10" - y$month <- substr(y$month, 6, 7) - - y$date <- as.Date(paste(y$year, y$month, y$day), format = paste(year_format, "%m", "%d")) - } - else if(format == "years") { - if(!all(sapply(x[, stack_cols], function(col) is.numeric(col) || (is.logical(col) && all(is.na(col)))))) stop("All stack_cols must be numeric\nThe following stack_cols are not numeric: ", paste(stack_cols[!sapply(x[, stack_cols], is.numeric)], collapse = ",")) - - by_cols <- c() - if(!missing(station)) by_cols <- c(by_cols, station) - if(!missing(element)) by_cols <- c(by_cols, element) - - if(length(by_cols) > 0) { - group_lengths <- x %>% dplyr::group_by(!!! rlang::syms(by_cols)) %>% dplyr::summarise(n = n()) - if(any(group_lengths$n != 366)) stop("data must have exactly 366 rows per station per element when format = 'years'") - } - else if(nrow(x) != 366) stop("data must have exactly 366 rows for a single station and element when format = 'years'") - - if(!missing(stack_years) && length(year_list) != length(stack_cols)) stop("stack_years must be the same length as stack_cols") - - # stack_years allows to specify the years represented by stack_cols. - # If this is blank, attempt to infer stack_years by assuming stack_cols are in the format c("X1990", "X1991", ...) - if(missing(stack_years)) { - # Remove first character and convert to numeric - stack_years <- as.numeric(stringr::str_sub(stack_cols, 2)) - invalid_ind <- is.na(stack_years) | stringr::str_length(stack_years) != 4 - if(any(invalid_ind)) { - cat("Unrecognised year columns:", paste(stack_years[invalid_ind], collapse = ", ")) - stop("Cannot determine year of some columns. Year columns must be named with format 'Xyyyy' where X is any character and yyyy is the year.") - } - } - x$doy <- 1:366 - # This ensures all other columns are dropped - y <- data.frame(doy = x$doy, x[ , stack_cols]) - if(!missing(station)) y$station <- x[[station]] - if(!missing(element)) y$element <- x[[element]] - # In case element_name is the name of an existing column in y - if(element_name %in% names(y)) element_name <- next_default_item(prefix = element_name, existing_names = names(y)) - y <- tidyr::pivot_longer(y, cols = tidyselect::all_of(stack_cols), names_to = "year", values_to = element_name) - - # This assumes stack_cols and stack_years are in the same order - y$year <- plyr::mapvalues(y$year, stack_cols, stack_years) - - # Replacing day 60 with 0 for non-leap years. This will result in NA dates. - y$doy[(!lubridate::leap_year(as.numeric(y$year))) & y$doy == 60] <- 0 - y$doy[(!lubridate::leap_year(as.numeric(y$year))) & y$doy > 60] <- y$doy[(!lubridate::leap_year(as.numeric(y$year))) & y$doy > 60] - 1 - y$date <- as.Date(paste(y$year, y$doy), format = paste("%Y", "%j")) - # Put day 0 back as 60. Needed in error displaying only. - y$doy[y$doy == 0] <- 60 - } - - continue <- TRUE - # check if there are any non missing values on missing dates - # this is a problem as missing dates are invalid dates so should not have values - invalid_ind <- is.na(y$date) & !is.na(y[[element_name]]) - if(sum(invalid_ind) > 0) { - cat("There are:", sum(invalid_ind), "measurement values on invalid dates.\n") - if(!silent) { - cat("\n*** Invalid dates ***\n\n") - invalid_data <- dplyr::filter(y, invalid_ind) - if(format == "days" || format == "months") { - invalid_data_display <- invalid_data %>% dplyr::select(year, month, day) - } - else { - invalid_data_display <- invalid_data %>% dplyr::select(year, doy) - } - # Also make a data.frame (instead of tibble) so that display will show all rows. - if(!missing(station)) { - invalid_data_display <- data.frame(station = invalid_data$station, invalid_data_display) - } - if(!missing(element)) { - invalid_data_display <- data.frame(element = invalid_data$element, invalid_data_display) - } - invalid_data_display <- data.frame(invalid_data_display) - invalid_data_display[[element_name]] <- invalid_data[[element_name]] - print(invalid_data_display, row.names = FALSE) - } - if(ignore_invalid) cat("Warning: These rows have been removed.\n") - else { - # This should be a stop but then detailed output can't be displayed by R-Instat - cat("There are:", sum(invalid_ind), "measurement values on invalid dates. Correct these or specify ignore_invalid = TRUE to ignore them. See output for more details.\n") - continue <- FALSE - } - } - - # This should have been a stop above but then detailed output can't be displayed by R-Instat - if(!continue) return() - - # Standard format of slowest varying structure variables first (station then element then date) followed by measurements - if(!missing(station)) z <- data.frame(station = forcats::as_factor(y$station), date = y$date) - else z <- data.frame(date = y$date) - if(!missing(element)) z$element <- y$element - z[[element_name]] <- y[[element_name]] - if(flags) z[[flag_name]] <- y[[flag_name]] - - # Initialise id columns used for sorting data - id_cols <- c() - if(!missing(station)) id_cols <- c(id_cols, "station") - - z <- dplyr::filter(z, !is.na(date)) - - # If data contains multiple elements, optionally unstack the element column - if(!missing(element)) { - if(unstack_elements) { - # pivot_wider allows unstacking multiple column sets, used when flags included. - values_from <- c(element_name) - if(flags) values_from <- c(values_from, flag_name) - # first check for unique combinations to ensure no duplicates - z_dup <- duplicated(z %>% dplyr::select(-tidyselect::all_of(values_from))) - if(any(z_dup > 0)) { - # This should be a stop but then detailed output can't be displayed by R-Instat - cat("\nError: Cannot tidy data as some elements have multiple values on the same date. Check and resolve duplicates first.\n") - z_check <- z %>% filter(z_dup > 0) - if(!silent) { - cat("\n*** Duplicates ***\n\n") - print(z_check, row.names = FALSE) - } - continue <- FALSE - } - else z <- tidyr::pivot_wider(z, names_from = element, values_from = tidyselect::all_of(values_from)) - } - # If not unstacking then need to sort by element column - else id_cols <- c(id_cols, "element") - } - - # This should have been a stop above but then detailed output can't be displayed by R-Instat - if(!continue) return() - - # Add this last to ensure date varies fastest - id_cols <- c(id_cols, "date") - # TODO Find a better way to do this. Update if there could be more the 3 id cols. - if(length(id_cols) == 1) { - z <- z %>% dplyr::arrange(.data[[id_cols[1]]]) - } - else if(length(id_cols) == 2) { - z <- z %>% dplyr::arrange(.data[[id_cols[1]]], .data[[id_cols[2]]]) - } - else if(length(id_cols) == 3) { - z <- z %>% dplyr::arrange(.data[[id_cols[1]]], .data[[id_cols[2]]], .data[[id_cols[3]]]) - } - if(missing(new_name) || new_name == "") new_name <- next_default_item("data", existing_names = self$get_data_names()) - data_list <- list(z) - names(data_list) <- new_name - self$import_data(data_tables=data_list) - }, - #' @description - #' Retrieve the geometry column from a given data object. - #' @param data The data object from which to retrieve the geometry column. - #' @return The name of the geometry column if found, otherwise an empty string. - get_geometry = function(data) { - if (missing(data)) stop("data_name is required") - else if ("sf" %in% class(data)) return(attr(data, "sf_column")) - else if ("geometry" %in% colnames(data)) return("geometry") - else return("") - }, - - #' @description - #' Check the installation status and version of a specified package. - #' @param package The name of the package to check. - #' @return A list containing the status of the package: - #' 1 if installed and up to date, 2 if installed but outdated, - #' and 0 if not installed or misspelled. - package_check = function(package) { - out <- list() - av_packs <- available.packages() - av_packs <- data.frame(av_packs) - if (package %in% rownames(installed.packages())) { - out[[1]] <- 1 - v_machine <- as.character(packageVersion(package)) - v_web <- as.character(av_packs[av_packs$Package == package, "Version"]) - out[[2]] <- compareVersion(v_machine, v_web) - out[[3]] <- v_machine - out[[4]] <- v_web - return(out) - } else { - if (package %in% av_packs) { - out[[1]] <- 2 - return(out) - } else { - out[[1]] <- 0 - return(out) - } - } - }, - - - - - - #' @description - #' Download data from the IRI database based on specified parameters. - #' @param source The source from which to download data. - #' @param data The specific data to download. - #' @param path The directory path for saving the downloaded file. - #' @param min_lon Minimum longitude for area selection. - #' @param max_lon Maximum longitude for area selection. - #' @param min_lat Minimum latitude for area selection. - #' @param max_lat Maximum latitude for area selection. - #' @param min_date Minimum date for the data. - #' @param max_date Maximum date for the data. - #' @param name The name to assign to the imported data. - #' @param download_type The type of download (Point or Area). - #' @param import Boolean indicating whether to import the downloaded data. - download_from_IRI = function(source, data, path = tempdir(), min_lon, max_lon, min_lat, max_lat, min_date, max_date, name, download_type = "Point", import = TRUE) { - init_URL <- "https://iridl.ldeo.columbia.edu/SOURCES/" - dim_x <- "X" - dim_y <- "Y" - dim_t <- "T" - if (source == "UCSB_CHIRPS") { - prexyaddress <- paste0(init_URL, ".UCSB/.CHIRPS/.v2p0") - if (data == "daily_improved_global_0p25_prcp") { - extension <- ".daily-improved/.global/.0p25/.prcp" - } # 1 Jan 1981 to 31 Jul 2020 - else if (data == "daily_improved_global_0p05_prcp") { - extension <- ".daily-improved/.global/.0p05/.prcp" - } # 1 Jan 1981 to 31 Jul 2020 - else if (data == "dekad_prcp") { - extension <- ".dekad/.prcp" - } # (days since 1960-01-01) ordered [ (1-10 Jan 1981) (11-20 Jan 1981) (21-31 Jan 1981) ... (21-31 Aug 2020)] - else if (data == "monthly_global_prcp") { - extension <- ".monthly/.global/.precipitation" - } # grid: /T (months since 1960-01-01) ordered (Jan 1981) to (Jul 2020) by 1.0 N= 475 pts :grid - else { - stop("Data file does not exist for CHIRPS V2P0 data") - } - } else if (source == "TAMSAT_v3.0") { - dim_x <- "lon" - dim_y <- "lat" - prexyaddress <- paste0(init_URL, ".Reading/.Meteorology/.TAMSAT/.TARCAT/.v3p0") - if (data == "daily_rfe") { - dim_t <- "time" - extension <- ".daily/.rfe" - } # grid: /time (julian_day) ordered (1 Jan 1983) to (10 Sep 2020) by 1.0 N= 13768 pts :grid - else if (data == "dekadal_rfe") { - extension <- ".dekadal/.rfe" - } # grid: /T (days since 1960-01-01) ordered [ (1-10 Jan 1983) (11-20 Jan 1983) (21-31 Jan 1983) ... (1-10 Sep 2020)] N= 1357 pts :grid - else if (data == "monthly_rfe") { - dim_t <- "time" - extension <- ".monthly/.rfe" - } # grid: /time (months since 1960-01-01) ordered (Jan 1983) to (Aug 2020) by 1.0 N= 452 pts :grid - else if (data == "monthly_rfe_calc") { - dim_t <- "time" - extension <- ".monthly/.rfe_calc" - } # grid: /time (months since 1960-01-01) ordered (Feb 1983) to (Sep 2020) by 1.0 N= 452 pts :grid - else { - stop("Data file does not exist for TAMSAT_v3.0 data") - } - } else if (source == "TAMSAT_v3.1") { - prexyaddress <- paste0(init_URL, ".Reading/.Meteorology/.TAMSAT/.TARCAT/.v3p1") - if (data == "daily_rfe") { - extension <- ".daily/.rfe" - } # grid: /T (julian_day) ordered (1 Jan 1983) to (10 Sep 2020) by 1.0 N= 13768 pts :grid - else if (data == "daily_rfe_filled") { - extension <- ".daily/.rfe_filled" - } # grid: /T (julian_day) ordered (1 Jan 1983) to (10 Sep 2020) by 1.0 N= 13768 pts :grid - else if (data == "dekadal_rfe") { - extension <- ".dekadal/.rfe" - } # grid: /T (days since 1960-01-01) ordered [ (1-10 Jan 1983) (11-20 Jan 1983) (21-31 Jan 1983) ... (1-10 Sep 2020)] N= 1357 pts :grid - else if (data == "dekadal_rfe_filled") { - extension <- ".dekadal/.rfe_filled" - } # grid: /T (days since 1960-01-01) ordered [ (1-10 Jan 1983) (11-20 Jan 1983) (21-31 Jan 1983) ... (1-10 Sep 2020)] N= 1357 pts :grid - else if (data == "monthly_rfe") { - extension <- ".monthly/.rfe" - } # grid: /T (months since 1960-01-01) ordered (Jan 1983) to (Aug 2020) by 1.0 N= 452 pts :grid - else if (data == "monthly_rfe_filled") { - extension <- ".monthly/.rfe_filled" - } # grid: /T (months since 1960-01-01) ordered (Jan 1983) to (Aug 2020) by 1.0 N= 452 pts :grid - else { - stop("Data file does not exist for TAMSAT_v3.1 data") - } - } else if (source == "NOAA") { - prexyaddress <- paste0(init_URL, ".NOAA/.NCEP/.CPC/.FEWS/.Africa") - if (data == "daily_rfev2_est_prcp") { - extension <- ".DAILY/.RFEv2/.est_prcp" - } # (days since 2000-10-31 12:00:00) ordered (31 Oct 2000) to (12 Sep 2020) - else if (data == "10day_rfev2_est_prcp") { - extension <- ".TEN-DAY/.RFEv2/.est_prcp" - } # grid: /T (days since 1960-01-01) ordered [ (1-10 Dec 1999) (11-20 Dec 1999) (21-31 Dec 1999) ... (1-10 Sep 2020)] N= 748 pts :grid - else if (data == "daily_est_prcp") { - extension <- ".DAILY/.ARC2/.daily/.est_prcp" - } # (days since 1960-01-01 12:00:00) ordered (1 Jan 1983) to (12 Sep 2020) - else if (data == "monthly_est_prcp") { - extension <- ".DAILY/.ARC2/.monthly/.est_prcp" - } # (months since 1960-01-01) ordered (Jan 1983) to (Aug 2020) - else { - stop("Data file does not exist for NOAA data") - } - } else if (source == "NOAA_CMORPH_DAILY" || source == "NOAA_CMORPH_3HOURLY" || source == "NOAA_CMORPH_DAILY_CALCULATED") { - if (source == "NOAA_CMORPH_DAILY") { - prexyaddress <- paste0(init_URL, ".NOAA/.NCEP/.CPC/.CMORPH/.daily") - } - else if (source == "NOAA_CMORPH_3HOURLY") { - prexyaddress <- paste0(init_URL, ".NOAA/.NCEP/.CPC/.CMORPH/.3-hourly") - } - else if (source == "NOAA_CMORPH_DAILY_CALCULATED") { - prexyaddress <- paste0(init_URL, ".NOAA/.NCEP/.CPC/.CMORPH/.daily_calculated") - } - if (data == "mean_microwave_only_est_prcp") { - extension <- ".mean/.microwave-only/.comb" - } - else if (data == "mean_morphed_est_prcp") { - extension <- ".mean/.morphed/.cmorph" - } - else if (data == "orignames_mean_microwave_only_est_prcp") { - extension <- ".orignames/.mean/.microwave-only/.comb" - } - else if (data == "orignames_mean_morphed_est_prcp") { - extension <- ".orignames/.mean/.morphed/.cmorph" - } - else if (data == "renamed102015_mean_microwave_only_est_prcp") { - extension <- ".renamed102015/.mean/.microwave-only/.comb" - } - else if (data == "renamed102015_mean_morphed_est_prcp") { - extension <- ".renamed102015/.mean/.morphed/.cmorph" - } - else { - stop("Data file does not exist for NOAA CMORPH data") - } - } else if (source == "NASA") { - prexyaddress <- paste0(init_URL, ".NASA/.GES-DAAC/.TRMM_L3/.TRMM_3B42/.v7") - if (data == "daily_prcp") { - extension <- ".daily/.precipitation" - } # (days since 1998-01-01 00:00:00) ordered (1 Jan 1998) to (31 May 2015) - else if (data == "3_hourly_prcp") { - extension <- ".three-hourly/.precipitation" - } # (days since 1998-01-01 00:00:00) ordered (2230 31 Dec 1997 - 0130 1 Jan 1998) to (2230 30 May 2015 - 0130 31 May 2015) - else { - stop("Data file does not exist for NASA TRMM 3B42 data") - } - } else { - stop("Source not specified correctly.") - } - prexyaddress <- paste(prexyaddress, extension, sep = "/") - if (download_type == "Area") { - URL <- add_xy_area_range(path = prexyaddress, min_lon = min_lon, min_lat = min_lat, max_lon = max_lon, max_lat = max_lat, dim_x = dim_x, dim_y = dim_y) - } - else if (download_type == "Point") { - URL <- add_xy_point_range(path = prexyaddress, min_lon = min_lon, min_lat = min_lat, dim_x = dim_x, dim_y = dim_y) - } - if (!missing(min_date) & !missing(max_date)) { - URL <- URL %>% add_t_range(min_date = min_date, max_date = max_date, dim_t = dim_t) - } - URL <- URL %>% add_nc() - file_name <- tempfile(pattern = tolower(source), tmpdir = path, fileext = ".nc") - result <- download.file(url = URL, destfile = file_name, method = "libcurl", mode = "wb", cacheOK = FALSE) - if (import && result == 0) { - nc <- ncdf4::nc_open(filename = file_name) - self$import_NetCDF(nc = nc, name = name) - ncdf4::nc_close(nc = nc) - } else if (result != 0) { - stop("No file downloaded please check your internet connection") - } - if (missing(path)) { - file.remove(file_name) - } - }, - - #' @description - #' Patch a climate element in the specified data. - #' @param data_name The name of the data to patch. - #' @param date_col_name The name of the date column. - #' @param var The variable to patch. - #' @param vars A vector of variables to patch. - #' @param max_mean_bias Maximum allowable mean bias for the patching. - #' @param max_stdev_bias Maximum allowable standard deviation bias for the patching. - #' @param time_interval The time interval for the patching (default is "month"). - #' @param column_name The name of the column to patch. - #' @param station_col_name The name of the station column. - patch_climate_element = function(data_name, date_col_name = "", var = "", vars = c(), max_mean_bias = NA, max_stdev_bias = NA, time_interval = "month", column_name, station_col_name = station_col_name) { - self$get_data_objects(data_name)$patch_climate_element(date_col_name = date_col_name, var = var, vars = vars, max_mean_bias = max_mean_bias, max_stdev_bias = max_stdev_bias, time_interval = time_interval, column_name = column_name, station_col_name = station_col_name) - }, - - #' @description - #' Visualize the missing values in a specified element within a dataset. - #' @param data_name The name of the data table. - #' @param element_col_name The name of the column containing the element of interest. - #' @param element_col_name_imputed The name of the column for imputed values of the element. - #' @param station_col_name The name of the column representing the station. - #' @param x_axis_labels_col_name The name of the column for x-axis labels. - #' @param ncol The number of columns for visualization layout. - #' @param type The type of visualization (e.g., distribution). - #' @param xlab Label for the x-axis. - #' @param ylab Label for the y-axis. - #' @param legend Logical indicating whether to include a legend. - #' @param orientation Orientation of the plot (e.g., horizontal). - #' @param interval_size Size of intervals for the visualization. - #' @param x_with_truth Optional truth values for comparison. - #' @param measure Measurement type (e.g., percent). - visualize_element_na = function(data_name, element_col_name, element_col_name_imputed, - station_col_name, x_axis_labels_col_name, ncol = 2, - type = "distribution", xlab = NULL, ylab = NULL, - legend = TRUE, orientation = "horizontal", - interval_size = interval_size, x_with_truth = NULL, - measure = "percent") { - self$get_data_objects(data_name)$visualize_element_na( - element_col_name = element_col_name, - element_col_name_imputed = element_col_name_imputed, - station_col_name = station_col_name, - x_axis_labels_col_name = x_axis_labels_col_name, - ncol = ncol, type = type, xlab = xlab, - ylab = ylab, legend = legend, - orientation = orientation, interval_size = interval_size, - x_with_truth = x_with_truth, measure = measure - ) - }, - - #' @description - #' Retrieve data entry for specified elements within a date range. - #' @param data_name The name of the data table. - #' @param station The station of interest. - #' @param date The date of interest. - #' @param elements The elements to retrieve. - #' @param view_variables Variables to view in the output. - #' @param station_name The name of the station. - #' @param type The type of data to retrieve. - #' @param start_date The start date of the data range. - #' @param end_date The end date of the data range. - get_data_entry_data = function(data_name, station, date, elements, - view_variables, station_name, - type, start_date, end_date) { - self$get_data_objects(data_name)$get_data_entry_data( - station = station, date = date, elements = elements, - view_variables = view_variables, station_name = station_name, - type = type, start_date = start_date, end_date = end_date - ) - }, - - #' @description - #' Save new data entries and associated comments to the dataset. - #' @param data_name The name of the data table. - #' @param new_data The new data to save. - #' @param rows_changed The rows that have been modified. - #' @param comments_list A list of comments for changes made. - #' @param add_flags Logical indicating whether to add flags. - save_data_entry_data = function(data_name, new_data, rows_changed, - comments_list = list(), add_flags = FALSE, ...) { - if (!missing(comments_list)) { - for (i in seq_along(comments_list)) { - com <- comments_list[[i]] - if (!("row" %in% names(com))) { - com[["row"]] <- "" - } - if (!("column" %in% names(com))) { - com[["column"]] <- "" - } - } - if (length(comments_list) > 0) { - cat("Comments added:", length(comments_list), "\n") - self$add_new_comment(data_name = data_name, - row = com$row, column = com$column, - comment = com$comment) - } - } - self$get_data_objects(data_name)$save_data_entry_data( - new_data = new_data, rows_changed = rows_changed, - add_flags = add_flags - ) - }, - - #' @description - #' Import data from CDS (Climate Data Store) for specified parameters. - #' @param user The user credentials for accessing CDS. - #' @param dataset The dataset to import. - #' @param elements The elements to retrieve from the dataset. - #' @param start_date The starting date for the data. - #' @param end_date The ending date for the data. - #' @param lon Longitude for area definition. - #' @param lat Latitude for area definition. - #' @param path The path to save the imported data. - #' @param import Logical indicating whether to import the data. - #' @param new_name Optional new name for the imported data. - import_from_cds = function(user, dataset, elements, start_date, - end_date, lon, lat, path, import = FALSE, - new_name) { - all_dates <- seq(start_date, end_date, by = 1) - all_periods <- unique(paste(lubridate::year(all_dates), - sprintf("%02d", lubridate::month(all_dates)), sep = "-")) - area <- c(lat[2], lon[1], lat[1], lon[2]) - is_win <- Sys.info()['sysname'] == "Windows" - if (is_win) pb <- winProgressBar(title = "Requesting data from CDS", - min = 0, max = length(all_periods)) - nc_files <- vector(mode = "character", length = length(all_periods)) - for (i in seq_along(all_periods)) { - y <- substr(all_periods[i], 1, 4) - m <- substr(all_periods[i], 6, 7) - curr_dates <- all_dates[lubridate::month(all_dates) == as.numeric(m) & - lubridate::year(all_dates) == as.numeric(y)] - d <- sprintf("%02d", lubridate::day(curr_dates)) - request <- list( - dataset_short_name = dataset, - product_type = "reanalysis", - variable = elements, - year = y, - month = m, - day = d, - time = sprintf("%02d:00", 0:23), - format = "netcdf", - area = area, - target = paste0(dataset, "-", paste(elements, collapse = "_"), "-", - all_periods[i], ".nc") - ) - info <- paste0("Requesting data for ", all_periods[i], " - ", - round(100 * i / length(all_periods)), "%") - if (is_win) setWinProgressBar(pb, value = i, title = info, label = info) - ncfile <- ecmwfr::wf_request(user = user, request = request, - transfer = TRUE, path = path, - time_out = 3 * 3600) - if (import) { - nc <- ncdf4::nc_open(filename = ncfile) - self$import_NetCDF(nc = nc, name = new_name) - ncdf4::nc_close(nc = nc) - } - } - if (is_win) close(pb) - }, - - #' @description - #' Add flag fields to a specified dataset. - #' @param data_name The name of the data table. - #' @param col_names The names of the columns to flag. - #' @param key_column_names The names of key columns. - add_flag_fields = function(data_name, col_names, key_column_names) { - if (!self$has_key(data_name)) { - self$add_key(data_name, key_column_names) - } - self$get_data_objects(data_name)$add_flag_fields(col_names = col_names) - }, - - #' @description - #' Remove empty rows or columns from a dataset. - #' @param data_name The name of the data table. - #' @param which The option to remove either "rows" or "cols". - remove_empty = function(data_name, which = c("rows", "cols")) { - self$get_data_objects(data_name)$remove_empty(which = which) - }, - - #' @description - #' Replace specified values with NA in a dataset. - #' @param data_name The name of the data table. - #' @param row_index The index of the row to modify. - #' @param column_index The index of the column to modify. - replace_values_with_NA = function(data_name, row_index, column_index) { - self$get_data_objects(data_name)$replace_values_with_NA(row_index = row_index, column_index = column_index) - }, - - #' @description - #' Check if specified columns in a dataset have labels. - #' @param data_name The name of the data table. - #' @param col_names The names of the columns to check. - has_labels = function(data_name, col_names) { - self$get_data_objects(data_name)$has_labels(col_names) - }, - - #' @description - #' Wrap or unwrap data in a specified column of a dataset. - #' @param data_name The name of the data table. - #' @param col_name The name of the column to modify. - #' @param column_data The data in the column. - #' @param width The width for wrapping. - #' @param wrap Logical indicating whether to wrap or unwrap data. - wrap_or_unwrap_data = function(data_name, col_name, column_data, width, wrap = TRUE) { - original_type <- class(column_data) - desired_types <- c("factor", "numeric", "Date", "character", "integer", "list", "double") - if (original_type %in% desired_types) { - if (any(!is.na(stringr::str_detect(column_data, "\n")))) { - column_data <- stringr::str_replace_all(column_data, "\n", " ") - } - - if (!is.null(width) && wrap) { - column_data <- stringr::str_wrap(column_data, width = width) - } - curr_data <- self$get_data_frame(data_name = data_name, retain_attr = TRUE) - - if (original_type != class(column_data)) { - if (original_type %in% c("factor", "ordered_factor")) { - column_data <- make_factor(column_data) - } else if (original_type == "list") { - result <- curr_data %>% - dplyr::mutate(list_column = lapply(column_data, convert_to_list)) - column_data <- result$list_column - } else { - column_data <- as(column_data, original_type) - } - } - - attributes(column_data) <- attributes(curr_data[[col_name]]) - self$add_columns_to_data(data_name = data_name, col_name = col_name, col_data = column_data, before = FALSE) - } - }, - - #' @description Generate ANOVA tables for specified columns in a dataset. - #' @param data_name The name of the data table. - #' @param x_col_names The names of the columns for the independent variables. - #' @param y_col_name The name of the column for the dependent variable. - #' @param signif.stars Logical indicating whether to show significance stars. - #' @param sign_level Logical indicating whether to show significance level. - #' @param means Logical indicating whether to include means in the output. - anova_tables2 = function(data_name, x_col_names, y_col_name, signif.stars = FALSE, sign_level = FALSE, means = FALSE) { - 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 #' Define options by context for a specified dataset. @@ -9049,13 +4760,13 @@ DataBook <- R6::R6Class("DataBook", } }, - #' @title Import SST + #' 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 @@ -9066,8 +4777,8 @@ DataBook <- R6::R6Class("DataBook", names(link_pairs) = c("Lon", "Lat") self$add_link(from_data_frame = data_names[1], to_data_frame = data_names[2], link_pairs = link_pairs, type = keyed_link_label) } + ), - private = list( .data_sheets = list(), .metadata = list(), @@ -9088,4 +4799,4 @@ DataBook <- R6::R6Class("DataBook", } } ) -) +) \ No newline at end of file diff --git a/man/DataBook.Rd b/man/DataBook.Rd index 46f2934..f1a5a17 100644 --- a/man/DataBook.Rd +++ b/man/DataBook.Rd @@ -3,21 +3,13 @@ \docType{class} \name{DataBook} \alias{DataBook} -\title{Append Property to Variables Metadata} +\alias{DataBook$new} +\alias{DataBook$} +\title{DataBook Class} \format{ -An R6 class object. - An R6 class object. } \usage{ -DataBook$new(data_tables = list(), instat_obj_metadata = list(), - data_tables_variables_metadata = rep(list(data.frame()), length(data_tables)), - data_tables_metadata = rep(list(list()), length(data_tables)), - data_tables_filters = rep(list(list()), length(data_tables)), - data_tables_column_selections = rep(list(list()), length(data_tables)), - imported_from = as.list(rep("", length(data_tables))), - messages = TRUE, convert = TRUE, create = TRUE) - DataBook$new(data_tables = list(), instat_obj_metadata = list(), data_tables_variables_metadata = rep(list(data.frame()), length(data_tables)), data_tables_metadata = rep(list(list()), length(data_tables)), @@ -27,223 +19,6 @@ DataBook$new(data_tables = list(), instat_obj_metadata = list(), messages = TRUE, convert = TRUE, create = TRUE) } \description{ -Append Property to Variables Metadata - -Append Property to Variables Metadata - -Append Property to Dataframe Metadata - -Append Property to Metadata - -Add Metadata Field - -Reorder Dataframes - -Copy Columns - -Drop Unused Factor Levels - -Set Factor Levels - -Edit Factor Level - -Set Factor Reference Level - -Get Column Count - -Reorder Factor Levels - -Get Data Type - -Copy Data Frame - -Copy Column Metadata to Clipboard - -Copy Data Frame Metadata to Clipboard - -Copy to Clipboard - -Set Hidden Columns - -Unhide All Columns - -Set Hidden Data Frames - -Get Hidden Data Frames - -Set Row Names - -Get Row Names - -Set Protected Columns - -Get Metadata Fields - -Freeze Columns - -Unfreeze Columns - -Is Variables Metadata - -Data Frame Exists - -Add Key - -Is Key - -Has Key - -Get Keys - -Add New Comment - -Get Comments - -Get Links - -Set Structure Columns - -Add Dependent Columns - -Set Column Colours - -Has Colours - -Remove Column Colours - -Set Column Colours by Metadata - -Graph One Variable - -Make Date YearMonthDay - -Make Date YearDoY - -Set Contrasts of Factor - -Create Factor Data Frame - -Split Date - -Import SST - -Append Property to Variables Metadata - -Append Property to Variables Metadata - -Append Property to Dataframe Metadata - -Append Property to Metadata - -Add Metadata Field - -Reorder Dataframes - -Copy Columns - -Drop Unused Factor Levels - -Set Factor Levels - -Edit Factor Level - -Set Factor Reference Level - -Get Column Count - -Reorder Factor Levels - -Get Data Type - -Copy Data Frame - -Copy Column Metadata to Clipboard - -Copy Data Frame Metadata to Clipboard - -Copy to Clipboard - -Set Hidden Columns - -Unhide All Columns - -Set Hidden Data Frames - -Get Hidden Data Frames - -Set Row Names - -Get Row Names - -Set Protected Columns - -Get Metadata Fields - -Freeze Columns - -Unfreeze Columns - -Is Variables Metadata - -Data Frame Exists - -Add Key - -Is Key - -Has Key - -Get Keys - -Add New Comment - -Get Comments - -Get Links - -Set Structure Columns - -Add Dependent Columns - -Set Column Colours - -Has Colours - -Remove Column Colours - -Set Column Colours by Metadata - -Graph One Variable - -Make Date YearMonthDay - -Make Date YearDoY - -Set Contrasts of Factor - -Create Factor Data Frame - -Split Date - -Import SST -} -\details{ -DataBook Class - -An R6 class to manage a collection of data tables along with their metadata and other associated properties. - -This function first checks if a key is defined and valid for the data sheet. -It also verifies that \code{new_comment} is an \code{instat_comment} object and that the key columns in \code{new_comment} are valid keys in the data frame. -If the comment ID already exists, a warning is issued and the existing comment is replaced. - -If the specified comment ID does not exist in the data sheet, an error is thrown. - -This function collects various fields from each comment and returns them in a data frame. -The number of replies and attributes for each comment is also included. -Currently, nested comments (replies) and additional attributes are not displayed in detail. - -DataBook Class - An R6 class to manage a collection of data tables along with their metadata and other associated properties. } \section{Methods}{ @@ -364,5458 +139,110 @@ An R6 class to manage a collection of data tables along with their metadata and \item{\code{reorder_factor_levels(data_name, col_name, new_level_names)}}{Reorders the factor levels in the specified column of the given data table.} \item{\code{get_data_type(data_name, col_name)}}{Returns the data type of the specified column in the given data table.} \item{\code{copy_data_frame(data_name, new_name, label = "", copy_to_clipboard = FALSE)}}{Copies the specified data table to a new data table with an optional new name, label, and option to copy to the clipboard.} -\item{\code{copy_col_metadata_to_clipboard(data_name, property_names)}}{Copies the specified column metadata properties from the given data table to the clipboard.} -\item{\code{copy_data_frame_metadata_to_clipboard(data_name, property_names)}}{Copies the specified data frame metadata properties from the given data table to the clipboard.} -\item{\code{copy_to_clipboard(content)}}{Copies the given content to the clipboard.} -\item{\code{set_hidden_columns(data_name, col_names = c())}}{Sets the specified columns in the given data table to be hidden.} -\item{\code{unhide_all_columns(data_name)}}{Unhides all columns in the specified data table.} -\item{\code{set_hidden_data_frames(data_names = c())}}{Sets the specified data frames to be hidden.} -\item{\code{get_hidden_data_frames()}}{Returns the names of all hidden data frames.} -\item{\code{set_row_names(data_name, row_names)}}{Sets new row names for the specified data table.} -\item{\code{get_row_names(data_name)}}{Returns the row names of the specified data table.} -\item{\code{set_protected_columns(data_name, col_names)}}{Sets the specified columns in the given data table to be protected.} -\item{\code{get_metadata_fields(data_name, include_overall, as_list = FALSE, include, exclude, excluded_items = c())}}{Returns the metadata fields for the specified data table and overall metadata, with options to include or exclude specific fields.} -\item{\code{freeze_columns(data_name, column)}}{Freezes the specified columns in the given data table.} -\item{\code{unfreeze_columns(data_name)}}{Unfreezes all columns in the specified data table.} -\item{\code{is_variables_metadata(data_name, property, column, return_vector = FALSE)}}{Checks if the specified property is part of the variables metadata for the given column in the specified data table.} -\item{\code{data_frame_exists(data_name)}}{Checks if the specified data table exists in the object.} -\item{\code{add_key(data_name, col_names, key_name)}}{Adds a key to the specified data table using the given columns and key name.} -\item{\code{is_key(data_name, col_names)}}{Checks if the specified columns form a key in the given data table.} -\item{\code{has_key(data_name)}}{Checks if the specified data table has a key.} -\item{\code{get_keys(data_name, key_name)}}{Returns the keys for the specified data table and key name.} -\item{\code{add_new_comment(data_name, row = "", column = "", comment)}}{Adds a new comment to the specified data table, optionally specifying the row and column.} -\item{\code{get_comments(data_name, comment_id)}}{Returns the comments for the specified data table and comment ID.} -\item{\code{get_links(link_name, ...)}}{Returns the links for the specified link name or all links if no name is provided.} -\item{\code{set_structure_columns(data_name, struc_type_1 = c(), struc_type_2 = c(), struc_type_3 = c())}}{Sets the structure columns for the specified data table.} -\item{\code{add_dependent_columns(data_name, columns, dependent_cols)}}{Adds dependent columns to the specified columns in the given data table.} -\item{\code{set_column_colours(data_name, columns, colours)}}{Sets the colors for the specified columns in the given data table.} -\item{\code{has_colours(data_name, columns)}}{Checks if the specified columns in the given data table have colors.} -\item{\code{remove_column_colours(data_name)}}{Removes colors from all columns in the specified data table.} -\item{\code{set_column_colours_by_metadata(data_name, columns, property)}}{Sets the colors for the specified columns in the given data table based on the specified metadata property.} -\item{\code{graph_one_variable(data_name, columns, numeric = "geom_boxplot", categorical = "geom_bar", character = "geom_bar", output = "facets", free_scale_axis = FALSE, ncol = NULL, coord_flip = FALSE, ... = ...)}}{Creates a graph for one variable in the specified data table with options for the type of graph, axis scaling, and other parameters.} -\item{\code{make_date_yearmonthday(data_name, year, month, day, f_year, f_month, f_day, year_format = "\%Y", month_format = "\%m")}}{Creates a date column from the specified year, month, and day columns in the given data table, with options for formatting.} -\item{\code{make_date_yeardoy(data_name, year, doy, base, doy_typical_length = "366")}}{Creates a date column from the specified year and day of year columns in the given data table.} -\item{\code{set_contrasts_of_factor(data_name, col_name, new_contrasts, defined_contr_matrix)}}{Sets the contrasts for the specified factor column in the given data table.} -\item{\code{create_factor_data_frame(data_name, factor, factor_data_frame_name, include_contrasts = FALSE, replace = FALSE, summary_count = TRUE)}}{Creates a new data frame for the specified factor column in the given data table, with options to include contrasts and summary counts.} -\item{\code{split_date(data_name, col_name = "", year_val = FALSE, year_name = FALSE, leap_year = FALSE, month_val = FALSE, month_abbr = FALSE, month_name = FALSE, week_val = FALSE, week_abbr = FALSE, week_name = FALSE, weekday_val = FALSE, weekday_abbr = FALSE, weekday_name = FALSE, day = FALSE, day_in_month = FALSE, day_in_year = FALSE, day_in_year_366 = FALSE, pentad_val = FALSE, pentad_abbr = FALSE, dekad_val = FALSE, dekad_abbr = FALSE, quarter_val = FALSE, quarter_abbr = FALSE, with_year = FALSE, s_start_month = 1, s_start_day_in_month = 1, days_in_month = FALSE)}}{Splits the specified date column into multiple components such as year, month, day, etc. in the given data table.} -\item{\code{import_SST(dataset, data_from = 5, data_names = c())}}{Imports SST data from the specified dataset and data source, creating data tables with the specified names.} -\item{\code{make_inventory_plot(data_name, date_col, station_col = NULL, year_col = NULL, doy_col = NULL, element_cols = NULL, add_to_data = FALSE, year_doy_plot = FALSE, coord_flip = FALSE, facet_by = NULL, graph_title = "Inventory Plot", graph_subtitle = NULL, graph_caption = NULL, title_size = NULL, subtitle_size = NULL, caption_size = NULL, labelXAxis, labelYAxis, xSize = NULL, ySize = NULL, Xangle = NULL, Yangle = NULL, scale_xdate, fromXAxis = NULL, toXAxis = NULL, byXaxis = NULL, date_ylabels, legend_position = NULL, xlabelsize = NULL, ylabelsize = NULL, scale = NULL, dir = "", row_col_number, nrow = NULL, ncol = NULL, key_colours = c("red", "grey"), display_rain_days = FALSE, facet_xsize = 9, facet_ysize = 9, facet_xangle = 90, facet_yangle = 90, scale_ydate = FALSE, date_ybreaks, step = 1, rain_cats = list(breaks = c(0, 0.85, Inf), labels = c("Dry", "Rain"), key_colours = c("tan3", "blue")))}}{Creates an inventory plot for the specified data table with various customisation options.} -\item{\code{import_NetCDF(nc, path, name, only_data_vars = TRUE, keep_raw_time = TRUE, include_metadata = TRUE, boundary, lon_points = NULL, lat_points = NULL, id_points = NULL, show_requested_points = TRUE, great_circle_dist = FALSE)}}{Imports data from a NetCDF file, with options to specify the data variables, time format, metadata inclusion, and boundaries.} -\item{\code{infill_missing_dates(data_name, date_name, factors, start_month, start_date, end_date, resort = TRUE)}}{Infills missing dates in the specified data table using the provided date column and factors.} -\item{\code{get_key_names(data_name, include_overall = TRUE, include, exclude, include_empty = FALSE, as_list = FALSE, excluded_items = c())}}{Returns the key names for the specified data table, with options to include overall keys, exclude specific keys, and return as a list.} -\item{\code{remove_key(data_name, key_name)}}{Removes the specified key from the given data table.} -\item{\code{add_climdex_indices(data_name, climdex_output, freq = "annual", station, year, month)}}{Adds climdex indices to the specified data table, with options for frequency, station, year, and month.} -\item{\code{is_metadata(data_name, str)}}{Checks if the specified string is part of the metadata for the given data table.} -\item{\code{get_climatic_column_name(data_name, col_name)}}{Returns the climatic column name for the specified column in the given data table.} -\item{\code{merge_data(data_name, new_data, by = NULL, type = "left", match = "all")}}{Merges new data into the specified data table using the provided columns and merge type.} -\item{\code{get_corruption_data_names()}}{Returns the names of all data tables with corruption data.} -\item{\code{get_corruption_contract_data_names()}}{Returns the names of all data tables with corruption contract data.} -\item{\code{get_database_variable_names(query, data_name, include_overall = TRUE, include, exclude, include_empty = FALSE, as_list = FALSE, excluded_items = c())}}{Returns the database variable names for the specified query and data table, with options to include overall variables, exclude specific variables, and return as a list.} -\item{\code{get_nc_variable_names(file = "", as_list = FALSE, ...)}}{Returns the variable names from the specified NetCDF file, with an option to return as a list.} -\item{\code{has_database_connection()}}{Checks if there is a database connection.} -\item{\code{database_connect(dbname, user, host, port, drv = RMySQL::MySQL())}}{Connects to a database using the provided credentials and driver.} -\item{\code{get_database_connection()}}{Returns the current database connection.} -\item{\code{set_database_connection(dbi_connection)}}{Sets the database connection to the specified DBI connection object.} -\item{\code{database_disconnect()}}{Disconnects from the current database.} -\item{\code{import_from_climsoft(stationfiltercolumn = "stationId", stations = c(), elementfiltercolumn = "elementId", elements = c(), include_observation_data = FALSE, include_observation_flags = FALSE, unstack_data = FALSE, include_elements_info = FALSE, start_date = NULL, end_date = NULL)}}{Imports data from CLIMSOFT using the specified filters and options for observation data, flags, and unstacking.} -\item{\code{import_from_iri(download_from, data_file, data_frame_name, location_data_name, path, X1, X2 = NA, Y1, Y2 = NA, get_area_point = "area")}}{Imports data from IRI using the specified parameters for download, file path, coordinates, and area type.} -\item{\code{export_workspace(data_names, file, include_graphs = TRUE, include_models = TRUE, include_metadata = TRUE)}}{Exports the workspace to a file, including the specified data tables, graphs, models, and metadata.} -\item{\code{set_links(new_links)}}{Sets the links in the object to the specified new links.} -\item{\code{display_daily_graph(data_name, date_col = NULL, station_col = NULL, year_col = NULL, doy_col = NULL, climatic_element = NULL, upper_limit = 100, bar_colour = "blue", rug_colour = "red")}}{Displays a daily graph for the specified data table with options for columns, element, colors, and limits.} -\item{\code{create_variable_set(data_name, set_name, columns)}}{Creates a variable set with the specified name and columns in the given data table.} -\item{\code{update_variable_set(data_name, set_name, columns, new_set_name)}}{Updates the specified variable set with new columns and optionally a new name in the given data table.} -\item{\code{delete_variable_sets(data_name, set_names)}}{Deletes the specified variable sets from the given data table.} -\item{\code{get_variable_sets_names(data_name, include_overall = TRUE, include, exclude, include_empty = FALSE, as_list = FALSE, excluded_items = c())}}{Returns the names of variable sets for the specified data table, with options to include overall sets, exclude specific sets, and return as a list.} -\item{\code{get_variable_sets(data_name, set_names, force_as_list = FALSE)}}{Returns the specified variable sets from the given data table, with an option to force the result as a list.} -\item{\code{crops_definitions(data_name, year, station, rain, day, rain_totals, plant_days, plant_lengths, start_check = TRUE, season_data_name, start_day, end_day, definition_props = TRUE, print_table = TRUE)}}{Defines crop parameters for the specified data table using the provided columns and options for seasons, days, and properties.} -\item{\code{tidy_climatic_data(x, format, stack_cols, day, month, year, stack_years, station, element, element_name="value", ignore_invalid = FALSE, silent = FALSE, unstack_elements = TRUE, new_name)}}{Converts wide-format daily climatic data to long format using the specified columns and options for format, elements, and validation.} -\item{\code{get_geometry(data)}}{Returns the geometry column for the specified data table.} -\item{\code{package_check(package)}}{Checks if the specified package is installed and returns information about its version and availability.} -\item{\code{download_from_IRI(source, data, path = tempdir(), min_lon, max_lon, min_lat, max_lat, min_date, max_date, name, download_type = "Point", import = TRUE)}}{Downloads data from IRI using the specified source, data, coordinates, date range, and options for download type and import.} -\item{\code{patch_climate_element(data_name, date_col_name = "", var = "", vars = c(), max_mean_bias = NA, max_stdev_bias = NA, time_interval = "month", column_name, station_col_name = station_col_name)}}{Patches the specified climate element in the given data table using the provided columns and options for bias, time interval, and station.} -\item{\code{visualize_element_na(data_name, element_col_name, element_col_name_imputed, station_col_name, x_axis_labels_col_name, ncol = 2, type = "distribution", xlab = NULL, ylab = NULL, legend = TRUE, orientation = "horizontal", interval_size = interval_size, x_with_truth = NULL, measure = "percent")}}{Visualizes missing data for the specified element in the given data table using the provided columns and options for labels, legend, orientation, and measure.} -\item{\code{get_data_entry_data(data_name, station, date, elements, view_variables, station_name, type, start_date, end_date)}}{Returns data entry data for the specified data table using the provided columns and options for date range, variables, and type.} -\item{\code{save_data_entry_data(data_name, new_data, rows_changed, comments_list = list(), add_flags = FALSE, ...)}}{Saves data entry data to the specified data table with options for adding comments, flags, and rows changed.} -\item{\code{import_from_cds(user, dataset, elements, start_date, end_date, lon, lat, path, import = FALSE, new_name)}}{Imports data from CDS using the specified user, dataset, elements, date range, coordinates, and options for file path and import.} -\item{\code{add_flag_fields(data_name, col_names, key_column_names)}}{Adds flag fields to the specified columns in the given data table, using the provided key columns.} -\item{\code{remove_empty(data_name, which = c("rows","cols"))}}{Removes empty rows or columns from the specified data table.} -\item{\code{replace_values_with_NA(data_name, row_index, column_index)}}{Replaces values with NA in the specified rows and columns of the given data table.} -\item{\code{has_labels(data_name, col_names)}}{Checks if the specified columns in the given data table have labels.} -\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.} -\item{\code{add_comment(new_comment)}}{Adds a new \code{instat_comment} object to the data sheet if the key is defined and valid.} -\item{\code{delete_comment(comment_id)}}{Deletes a comment from the data sheet based on the comment ID.} -\item{\code{get_comment_ids()}}{Retrieves all comment IDs currently stored in the data sheet.} -\item{\code{get_comments_as_data_frame()}}{Converts all comments in the data sheet to a data frame format for easier inspection and analysis.} -\item{\code{update_links_rename_data_frame(old_data_name, new_data_name)}}{This function updates all links that reference a data frame with a specified old name, renaming it to a new name.} -\item{\code{update_links_rename_column(data_name, old_column_name, new_column_name)}}{This function updates all links referencing a column in a data frame with a specified old column name, renaming it to a new column name.} -\item{\code{add_link(from_data_frame, to_data_frame, link_pairs, type, link_name)}}{This function adds a new link between two data frames with the specified link pairs and type. It will check if the link already exists or if the link columns are keys.} -\item{\code{get_link_names(data_name, include_overall = TRUE, include, exclude, include_empty = FALSE, as_list = FALSE)}}{Retrieves the names of all links involving a specified data frame, with options to include or exclude specific types.} -\item{\code{link_exists_from(curr_data_frame, link_pairs)}}{Verifies if a link exists from a specific data frame with given link pairs.} -\item{\code{link_exists_between(from_data_frame, to_data_frame, ordered = FALSE)}}{This function checks if there is an ordered or unordered link between two specified data frames.} -\item{\code{get_link_between(from_data_frame, to_data_frame, ordered = FALSE)}}{Retrieves the link definition between two specified data frames.} -\item{\code{link_exists_from_by_to(first_data_frame, link_pairs, second_data_frame)}}{This function checks if a link exists from \code{first_data_frame} to \code{second_data_frame} using the specified \code{link_pairs} columns.} -\item{\code{get_linked_to_data_name(from_data_frame, link_cols = c(), include_self = FALSE)}}{This function returns the names of data frames linked to \code{from_data_frame}. Optionally, includes \code{from_data_frame} itself in the output if \code{include_self} is TRUE. Filters results by \code{link_cols}, if provided.} -\item{\code{get_linked_to_definition(from_data_frame, link_pairs)}}{This function returns a list of the target data frame and matched columns.} -\item{\code{get_possible_linked_to_definition(from_data_frame, link_pairs)}}{This function attempts to find a linked data frame that matches \code{link_pairs}. Recursively explores links between multiple data frames.} -\item{\code{get_equivalent_columns(from_data_name, columns, to_data_name)}}{This function returns columns in \code{to_data_name} equivalent to \code{columns} in \code{from_data_name}. Recursively searches links between multiple data frames.} -\item{\code{link_between_containing(from_data_frame, containing_columns, to_data_frame)}}{This function returns columns in \code{to_data_frame} corresponding to \code{containing_columns} in \code{from_data_frame} if a link exists between them.} -\item{\code{view_link(link_name)}}{Displays the details of a specified link.} - -@export - - -\describe{ -\item{\code{set_data(new_data, messages, check_names)}}{Sets the data for the DataSheet object.} -\item{\code{standardise_country_names(data_name, country_columns = c())}}{Standardizes country names in the specified data table.} -\item{\code{define_as_climatic(data_name, types, key_col_names, key_name)}}{Defines a data table as climatic data.} -\item{\code{define_corruption_outputs(data_name, output_columns = c())}}{Defines corruption output columns in the specified data table.} -\item{\code{define_red_flags(data_name, red_flags = c())}}{Defines red flag columns in the specified data table.} -\item{\code{define_as_procurement(data_name, primary_types = c(), calculated_types = c(), country_data_name, country_types, auto_generate = TRUE)}}{Defines a data table as procurement data.} -\item{\code{define_as_procurement_country_level_data(data_name, contract_level_data_name, types = c(), auto_generate = TRUE)}}{Defines a data table as procurement country-level data.} -\item{\code{get_CRI_component_column_names(data_name)}}{Gets the names of CRI component columns in the specified data table.} -\item{\code{get_red_flag_column_names(data_name)}}{Gets the names of red flag columns in the specified data table.} -\item{\code{get_CRI_column_names(data_name)}}{Gets the names of CRI columns in the specified data table.} -\item{\code{get_corruption_column_name(data_name, type)}}{Gets the name of the corruption column in the specified data table.} -\item{\code{import_data(data_tables = list(), data_tables_variables_metadata = rep(list(data.frame()),length(data_tables)), data_tables_metadata = rep(list(list()),length(data_tables)), data_tables_filters = rep(list(list()),length(data_tables)), data_tables_column_selections = rep(list(list()),length(data_tables)), imported_from = as.list(rep("",length(data_tables))), data_names = NULL, messages=TRUE, convert=TRUE, create=TRUE, prefix=TRUE, add_to_graph_book = TRUE)}}{Imports data into the DataBook from a list of data tables and their metadata.} -\item{\code{replace_instat_object(new_instat_object)}}{Replaces the current instat object with a new one.} -\item{\code{set_data_objects(new_data_objects)}}{Sets the data objects for the DataBook.} -\item{\code{copy_data_object(data_name, new_name, filter_name = "", column_selection_name = "", reset_row_names = TRUE)}}{Copies a data object with optional filtering and column selection.} -\item{\code{import_RDS(data_RDS, keep_existing = TRUE, overwrite_existing = FALSE, include_objects = TRUE, include_metadata = TRUE, include_logs = TRUE, include_filters = TRUE, include_column_selections = TRUE, include_calculations = TRUE, include_comments = TRUE)}}{Imports data from an RDS file into the DataBook.} -\item{\code{clone_data_object(curr_data_object, include_objects = TRUE, include_metadata = TRUE, include_logs = TRUE, include_filters = TRUE, include_column_selections = TRUE, include_calculations = TRUE, include_comments = TRUE, ...)}}{Clones a data object with options to include various components.} -\item{\code{clone_instat_calculation(curr_instat_calculation, ...)}}{Clones an instat calculation.} -\item{\code{import_from_ODK(username, form_name, platform)}}{Imports data from ODK (Open Data Kit).} -\item{\code{set_meta(new_meta)}}{Sets the metadata for the DataBook.} -\item{\code{set_objects(new_objects)}}{Sets the objects for the DataBook.} -\item{\code{append_data_object(name, obj, add_to_graph_book = TRUE)}}{Appends a data object to the DataBook.} -\item{\code{get_data_objects(data_name, as_list = FALSE, ...)}}{Gets data objects from the DataBook.} -\item{\code{get_data_frame(data_name, convert_to_character = FALSE, stack_data = FALSE, include_hidden_columns = TRUE, use_current_filter = TRUE, filter_name = "", use_column_selection = TRUE, column_selection_name = "", remove_attr = FALSE, retain_attr = FALSE, max_cols, max_rows, drop_unused_filter_levels = FALSE, start_row, start_col, ...)}}{Gets a data frame from the DataBook with various options.} -\item{\code{get_variables_metadata(data_name, data_type = "all", convert_to_character = FALSE, property, column, error_if_no_property = TRUE, direct_from_attributes = FALSE, use_column_selection = TRUE)}}{Gets the variables metadata for the specified data table.} -\item{\code{get_column_data_types(data_name, columns)}}{Gets the data types of the specified columns in the data table.} -\item{\code{get_column_labels(data_name, columns)}}{Gets the labels of the specified columns in the data table.} -\item{\code{get_data_frame_label(data_name, use_current_filter = FALSE)}}{Gets the label of the data frame.} -\item{\code{get_data_frame_metadata(data_name, label, include_calculated = TRUE, excluded_not_for_display = TRUE)}}{Gets the metadata of the data frame.} -\item{\code{get_combined_metadata(convert_to_character = FALSE)}}{Gets combined metadata from all data tables.} -\item{\code{get_metadata(name, ...)}}{Gets metadata for the specified name.} -\item{\code{get_data_names(as_list = FALSE, include, exclude, excluded_items, include_hidden = TRUE, ...)}}{Gets the names of the data tables in the DataBook.} -\item{\code{get_data_changed(data_name)}}{Checks if the data has changed.} -\item{\code{get_variables_metadata_changed(data_name)}}{Checks if the variables metadata has changed.} -\item{\code{get_metadata_changed(data_name)}}{Checks if the metadata has changed.} -\item{\code{get_calculations(data_name)}}{Gets the calculations for the specified data table.} -\item{\code{get_calculation_names(data_name, as_list = FALSE, excluded_items = c())}}{Gets the names of the calculations for the specified data table.} -\item{\code{dataframe_count()}}{Gets the count of data frames in the DataBook.} -\item{\code{set_data_frames_changed(data_name = "", new_val)}}{Sets the changed status for data frames.} -\item{\code{set_variables_metadata_changed(data_name = "", new_val)}}{Sets the changed status for variables metadata.} -\item{\code{set_metadata_changed(data_name = "", new_val)}}{Sets the changed status for metadata.} -\item{\code{add_columns_to_data(data_name, col_name = "", col_data, use_col_name_as_prefix = FALSE, hidden = FALSE, before, adjacent_column = "", num_cols, require_correct_length = TRUE, keep_existing_position = TRUE)}}{Adds columns to the specified data table.} -\item{\code{get_columns_from_data(data_name, col_names, from_stacked_data = FALSE, force_as_data_frame = FALSE, use_current_filter = TRUE, remove_labels = FALSE, drop_unused_filter_levels = FALSE)}}{Gets columns from the specified data table.} -\item{\code{create_graph_data_book()}}{Creates a graph data book.} -\item{\code{add_object(data_name = NULL, object_name = NULL, object_type_label, object_format, object)}}{Adds an object to the DataBook.} -\item{\code{get_object_names(data_name = NULL, object_type_label = NULL, as_list = FALSE, ...)}}{Gets the names of the objects in the DataBook.} -\item{\code{get_objects(data_name = NULL, object_type_label = NULL)}}{Gets the objects from the DataBook.} -\item{\code{get_object(data_name = NULL, object_name)}}{Gets a specific object from the DataBook.} -\item{\code{get_object_data(data_name = NULL, object_name, as_file = FALSE)}}{Gets the data of a specific object from the DataBook.} -\item{\code{get_objects_data(data_name = NULL, object_names = NULL, as_files = FALSE)}}{Gets the data of multiple objects from the DataBook.} -\item{\code{get_last_object_data(object_type_label, as_file = TRUE)}}{Gets the data of the last object of a specified type from the DataBook.} -\item{\code{rename_object(data_name, object_name, new_name, object_type = "object")}}{Renames an object in the DataBook.} -\item{\code{delete_objects(data_name, object_names, object_type = "object")}}{Deletes objects from the DataBook.} -\item{\code{reorder_objects(data_name, new_order)}}{Reorders the objects in the DataBook.} -\item{\code{get_from_object(data_name, object_name, value1, value2, value3)}}{Gets values from a specified object in the DataBook.} -\item{\code{add_filter(data_name, filter, filter_name = "", replace = TRUE, set_as_current_filter = FALSE, na.rm = TRUE, is_no_filter = FALSE, and_or = "&", inner_not = FALSE, outer_not = FALSE)}}{Adds a filter to the specified data table.} -\item{\code{add_filter_as_levels(data_name, filter_levels, column)}}{Adds filter levels to the specified column.} -\item{\code{current_filter(data_name)}}{Gets the current filter for the specified data table.} -\item{\code{set_current_filter(data_name, filter_name = "")}}{Sets the current filter for the specified data table.} -\item{\code{get_filter(data_name, filter_name)}}{Gets a filter by name from the specified data table.} -\item{\code{get_filter_as_logical(data_name, filter_name)}}{Gets a filter as a logical vector from the specified data table.} -\item{\code{get_current_filter(data_name)}}{Gets the current filter for the specified data table.} -\item{\code{get_filter_row_names(data_name, filter_name)}}{Gets the row names that match a specified filter in the data table.} -\item{\code{get_current_filter_name(data_name)}}{Gets the name of the current filter for the specified data table.} -\item{\code{get_filter_names(data_name, as_list = FALSE, include = list(), exclude = list(), excluded_items = c())}}{Gets the names of the filters in the specified data table.} -\item{\code{remove_current_filter(data_name)}}{Removes the current filter from the specified data table.} -\item{\code{filter_applied(data_name)}}{Checks if a filter is applied to the specified data table.} -\item{\code{filter_string(data_name, filter_name)}}{Gets the filter string for a specified filter in the data table.} -\item{\code{get_filter_as_instat_calculation(data_name, filter_name)}}{Gets a filter as an instat calculation from the specified data table.} -\item{\code{add_column_selection(data_name, column_selection, name = "", replace = TRUE, set_as_current = FALSE, is_everything = FALSE, and_or = "|")}}{Adds a column selection to the specified data table.} -\item{\code{current_column_selection(data_name)}}{Gets the current column selection for the specified data table.} -\item{\code{set_current_column_selection(data_name, name = "")}}{Sets the current column selection for the specified data table.} -\item{\code{get_column_selection(data_name, name)}}{Gets a column selection by name from the specified data table.} -\item{\code{get_column_selection_column_names(data_name, filter_name)}}{Gets the column names for a specified filter in the data table.} -\item{\code{get_column_selected_column_names(data_name, column_selection_name = "")}}{Gets the names of the selected columns in the specified data table.} -\item{\code{get_current_column_selection(data_name)}}{Gets the current column selection for the specified data table.} -\item{\code{get_current_column_selection_name(data_name)}}{Gets the name of the current column selection for the specified data table.} -\item{\code{get_column_selection_names(data_name, as_list = FALSE, include = list(), exclude = list(), excluded_items = c())}}{Gets the names of the column selections in the specified data table.} -\item{\code{remove_current_column_selection(data_name)}}{Removes the current column selection from the specified data table.} -\item{\code{column_selection_applied(data_name)}}{Checks if a column selection is applied to the specified data table.} -\item{\code{replace_value_in_data(data_name, col_names, rows, old_value, old_is_missing = FALSE, start_value = NA, end_value = NA, new_value, new_is_missing = FALSE, closed_start_value = TRUE, closed_end_value = TRUE, locf = FALSE, from_last = FALSE)}}{Replaces values in the specified columns and rows of the data table.} -\item{\code{paste_from_clipboard(data_name, col_names, start_row_pos = 1, first_clip_row_is_header = TRUE, clip_board_text)}}{Pastes data from the clipboard into the specified columns of the data table.} -\item{\code{rename_column_in_data(data_name, column_name = NULL, new_val = NULL, label = "", type = "single", .fn, .cols = everything(), new_column_names_df, new_labels_df, ...)}}{Renames a column in the specified data table.} -\item{\code{frequency_tables(data_name, x_col_names, y_col_name, n_column_factors = 1, store_results = TRUE, drop = TRUE, na.rm = FALSE, summary_name = NA, include_margins = FALSE, return_output = TRUE, treat_columns_as_factor = FALSE, page_by = "default", as_html = TRUE, signif_fig = 2, na_display = "", na_level_display = "NA", weights = NULL, caption = NULL, result_names = NULL, percentage_type = "none", perc_total_columns = NULL, perc_total_factors = c(), perc_total_filter = NULL, perc_decimal = FALSE, margin_name = "(All)", additional_filter, ...)}}{Creates frequency tables for the specified data table.} -\item{\code{anova_tables(data_name, x_col_names, y_col_name, signif.stars = FALSE, sign_level = FALSE, means = FALSE)}}{Creates ANOVA tables for the specified data table.} -\item{\code{cor(data_name, x_col_names, y_col_name, use = "everything", method = c("pearson", "kendall", "spearman"))}}{Calculates correlations for the specified columns in the data table.} -\item{\code{remove_columns_in_data(data_name, cols, allow_delete_all = FALSE)}}{Removes columns from the specified data table.} -\item{\code{remove_rows_in_data(data_name, row_names)}}{Removes rows from the specified data table.} -\item{\code{get_next_default_column_name(data_name, prefix)}}{Gets the next default column name for the specified data table.} -\item{\code{get_column_names(data_name, as_list = FALSE, include = list(), exclude = list(), excluded_items = c(), max_no, use_current_column_selection = TRUE)}}{Gets the column names in the specified data table.} -\item{\code{reorder_columns_in_data(data_name, col_order)}}{Reorders the columns in the specified data table.} -\item{\code{insert_row_in_data(data_name, start_row, row_data = c(), number_rows = 1, before = FALSE)}}{Inserts rows into the specified data table.} -\item{\code{get_data_frame_length(data_name, use_current_filter = FALSE)}}{Gets the length of the data frame in the specified data table.} -\item{\code{get_next_default_dataframe_name(prefix, include_index = TRUE, start_index = 1)}}{Gets the next default name for a data frame in the DataBook.} -\item{\code{delete_dataframes(data_names, delete_graph_book = TRUE)}}{Deletes data frames from the DataBook.} -\item{\code{remove_link(link_name)}}{Removes a link from the DataBook.} -\item{\code{get_column_factor_levels(data_name, col_name = "")}}{Gets the factor levels of a column in the specified data table.} -\item{\code{get_factor_data_frame(data_name, col_name = "", include_levels = TRUE, include_NA_level = FALSE)}}{Gets a factor data frame for the specified column in the data table.} -\item{\code{sort_dataframe(data_name, col_names = c(), decreasing = FALSE, na.last = TRUE, by_row_names = FALSE, row_names_as_numeric = TRUE)}}{Sorts the specified data table.} -\item{\code{rename_dataframe(data_name, new_value = "", label = "")}}{Renames the specified data table.} -\item{\code{convert_column_to_type(data_name, col_names = c(), to_type, factor_values = NULL, set_digits, set_decimals = FALSE, keep_attr = TRUE, ignore_labels = FALSE, keep.labels = TRUE)}}{Converts the specified columns to a different type in the data table.} -\item{\code{append_to_variables_metadata(data_name, col_names, property, new_val = "")}}{Appends a new value to the specified property in the variables metadata for the given columns in the specified data table.} -\item{\code{append_to_dataframe_metadata(data_name, property, new_val = "")}}{Appends a new value to the specified property in the dataframe metadata for the specified data table.} -\item{\code{append_to_metadata(property, new_val = "", allow_override_special = FALSE)}}{Appends a new value to the specified property in the overall metadata, with an option to override special properties.} -\item{\code{add_metadata_field(data_name, property, new_val = "")}}{Adds a new metadata field to the specified data table or to the overall metadata.} -\item{\code{reorder_dataframes(data_frames_order)}}{Reorders the data frames in the object based on the provided order.} -\item{\code{copy_columns(data_name, col_names = "", copy_to_clipboard = FALSE)}}{Copies the specified columns from the given data table, with an option to copy to the clipboard.} -\item{\code{drop_unused_factor_levels(data_name, col_name)}}{Drops unused factor levels from the specified column in the given data table.} -\item{\code{set_factor_levels(data_name, col_name, new_labels, new_levels, set_new_labels = TRUE)}}{Sets new factor levels and labels for the specified column in the given data table.} -\item{\code{edit_factor_level(data_name, col_name, old_level, new_level)}}{Edits an existing factor level in the specified column of the given data table.} -\item{\code{set_factor_reference_level(data_name, col_name, new_ref_level)}}{Sets a new reference level for the specified factor column in the given data table.} -\item{\code{get_column_count(data_name, use_column_selection = FALSE)}}{Returns the count of columns in the specified data table, with an option to use the current column selection.} -\item{\code{reorder_factor_levels(data_name, col_name, new_level_names)}}{Reorders the factor levels in the specified column of the given data table.} -\item{\code{get_data_type(data_name, col_name)}}{Returns the data type of the specified column in the given data table.} -\item{\code{copy_data_frame(data_name, new_name, label = "", copy_to_clipboard = FALSE)}}{Copies the specified data table to a new data table with an optional new name, label, and option to copy to the clipboard.} -\item{\code{copy_col_metadata_to_clipboard(data_name, property_names)}}{Copies the specified column metadata properties from the given data table to the clipboard.} -\item{\code{copy_data_frame_metadata_to_clipboard(data_name, property_names)}}{Copies the specified data frame metadata properties from the given data table to the clipboard.} -\item{\code{copy_to_clipboard(content)}}{Copies the given content to the clipboard.} -\item{\code{set_hidden_columns(data_name, col_names = c())}}{Sets the specified columns in the given data table to be hidden.} -\item{\code{unhide_all_columns(data_name)}}{Unhides all columns in the specified data table.} -\item{\code{set_hidden_data_frames(data_names = c())}}{Sets the specified data frames to be hidden.} -\item{\code{get_hidden_data_frames()}}{Returns the names of all hidden data frames.} -\item{\code{set_row_names(data_name, row_names)}}{Sets new row names for the specified data table.} -\item{\code{get_row_names(data_name)}}{Returns the row names of the specified data table.} -\item{\code{set_protected_columns(data_name, col_names)}}{Sets the specified columns in the given data table to be protected.} -\item{\code{get_metadata_fields(data_name, include_overall, as_list = FALSE, include, exclude, excluded_items = c())}}{Returns the metadata fields for the specified data table and overall metadata, with options to include or exclude specific fields.} -\item{\code{freeze_columns(data_name, column)}}{Freezes the specified columns in the given data table.} -\item{\code{unfreeze_columns(data_name)}}{Unfreezes all columns in the specified data table.} -\item{\code{is_variables_metadata(data_name, property, column, return_vector = FALSE)}}{Checks if the specified property is part of the variables metadata for the given column in the specified data table.} -\item{\code{data_frame_exists(data_name)}}{Checks if the specified data table exists in the object.} -\item{\code{add_key(data_name, col_names, key_name)}}{Adds a key to the specified data table using the given columns and key name.} -\item{\code{is_key(data_name, col_names)}}{Checks if the specified columns form a key in the given data table.} -\item{\code{has_key(data_name)}}{Checks if the specified data table has a key.} -\item{\code{get_keys(data_name, key_name)}}{Returns the keys for the specified data table and key name.} -\item{\code{add_new_comment(data_name, row = "", column = "", comment)}}{Adds a new comment to the specified data table, optionally specifying the row and column.} -\item{\code{get_comments(data_name, comment_id)}}{Returns the comments for the specified data table and comment ID.} -\item{\code{get_links(link_name, ...)}}{Returns the links for the specified link name or all links if no name is provided.} -\item{\code{set_structure_columns(data_name, struc_type_1 = c(), struc_type_2 = c(), struc_type_3 = c())}}{Sets the structure columns for the specified data table.} -\item{\code{add_dependent_columns(data_name, columns, dependent_cols)}}{Adds dependent columns to the specified columns in the given data table.} -\item{\code{set_column_colours(data_name, columns, colours)}}{Sets the colors for the specified columns in the given data table.} -\item{\code{has_colours(data_name, columns)}}{Checks if the specified columns in the given data table have colors.} -\item{\code{remove_column_colours(data_name)}}{Removes colors from all columns in the specified data table.} -\item{\code{set_column_colours_by_metadata(data_name, columns, property)}}{Sets the colors for the specified columns in the given data table based on the specified metadata property.} -\item{\code{graph_one_variable(data_name, columns, numeric = "geom_boxplot", categorical = "geom_bar", character = "geom_bar", output = "facets", free_scale_axis = FALSE, ncol = NULL, coord_flip = FALSE, ... = ...)}}{Creates a graph for one variable in the specified data table with options for the type of graph, axis scaling, and other parameters.} -\item{\code{make_date_yearmonthday(data_name, year, month, day, f_year, f_month, f_day, year_format = "\%Y", month_format = "\%m")}}{Creates a date column from the specified year, month, and day columns in the given data table, with options for formatting.} -\item{\code{make_date_yeardoy(data_name, year, doy, base, doy_typical_length = "366")}}{Creates a date column from the specified year and day of year columns in the given data table.} -\item{\code{set_contrasts_of_factor(data_name, col_name, new_contrasts, defined_contr_matrix)}}{Sets the contrasts for the specified factor column in the given data table.} -\item{\code{create_factor_data_frame(data_name, factor, factor_data_frame_name, include_contrasts = FALSE, replace = FALSE, summary_count = TRUE)}}{Creates a new data frame for the specified factor column in the given data table, with options to include contrasts and summary counts.} -\item{\code{split_date(data_name, col_name = "", year_val = FALSE, year_name = FALSE, leap_year = FALSE, month_val = FALSE, month_abbr = FALSE, month_name = FALSE, week_val = FALSE, week_abbr = FALSE, week_name = FALSE, weekday_val = FALSE, weekday_abbr = FALSE, weekday_name = FALSE, day = FALSE, day_in_month = FALSE, day_in_year = FALSE, day_in_year_366 = FALSE, pentad_val = FALSE, pentad_abbr = FALSE, dekad_val = FALSE, dekad_abbr = FALSE, quarter_val = FALSE, quarter_abbr = FALSE, with_year = FALSE, s_start_month = 1, s_start_day_in_month = 1, days_in_month = FALSE)}}{Splits the specified date column into multiple components such as year, month, day, etc. in the given data table.} -\item{\code{import_SST(dataset, data_from = 5, data_names = c())}}{Imports SST data from the specified dataset and data source, creating data tables with the specified names.} -\item{\code{make_inventory_plot(data_name, date_col, station_col = NULL, year_col = NULL, doy_col = NULL, element_cols = NULL, add_to_data = FALSE, year_doy_plot = FALSE, coord_flip = FALSE, facet_by = NULL, graph_title = "Inventory Plot", graph_subtitle = NULL, graph_caption = NULL, title_size = NULL, subtitle_size = NULL, caption_size = NULL, labelXAxis, labelYAxis, xSize = NULL, ySize = NULL, Xangle = NULL, Yangle = NULL, scale_xdate, fromXAxis = NULL, toXAxis = NULL, byXaxis = NULL, date_ylabels, legend_position = NULL, xlabelsize = NULL, ylabelsize = NULL, scale = NULL, dir = "", row_col_number, nrow = NULL, ncol = NULL, key_colours = c("red", "grey"), display_rain_days = FALSE, facet_xsize = 9, facet_ysize = 9, facet_xangle = 90, facet_yangle = 90, scale_ydate = FALSE, date_ybreaks, step = 1, rain_cats = list(breaks = c(0, 0.85, Inf), labels = c("Dry", "Rain"), key_colours = c("tan3", "blue")))}}{Creates an inventory plot for the specified data table with various customisation options.} -\item{\code{import_NetCDF(nc, path, name, only_data_vars = TRUE, keep_raw_time = TRUE, include_metadata = TRUE, boundary, lon_points = NULL, lat_points = NULL, id_points = NULL, show_requested_points = TRUE, great_circle_dist = FALSE)}}{Imports data from a NetCDF file, with options to specify the data variables, time format, metadata inclusion, and boundaries.} -\item{\code{infill_missing_dates(data_name, date_name, factors, start_month, start_date, end_date, resort = TRUE)}}{Infills missing dates in the specified data table using the provided date column and factors.} -\item{\code{get_key_names(data_name, include_overall = TRUE, include, exclude, include_empty = FALSE, as_list = FALSE, excluded_items = c())}}{Returns the key names for the specified data table, with options to include overall keys, exclude specific keys, and return as a list.} -\item{\code{remove_key(data_name, key_name)}}{Removes the specified key from the given data table.} -\item{\code{add_climdex_indices(data_name, climdex_output, freq = "annual", station, year, month)}}{Adds climdex indices to the specified data table, with options for frequency, station, year, and month.} -\item{\code{is_metadata(data_name, str)}}{Checks if the specified string is part of the metadata for the given data table.} -\item{\code{get_climatic_column_name(data_name, col_name)}}{Returns the climatic column name for the specified column in the given data table.} -\item{\code{merge_data(data_name, new_data, by = NULL, type = "left", match = "all")}}{Merges new data into the specified data table using the provided columns and merge type.} -\item{\code{get_corruption_data_names()}}{Returns the names of all data tables with corruption data.} -\item{\code{get_corruption_contract_data_names()}}{Returns the names of all data tables with corruption contract data.} -\item{\code{get_database_variable_names(query, data_name, include_overall = TRUE, include, exclude, include_empty = FALSE, as_list = FALSE, excluded_items = c())}}{Returns the database variable names for the specified query and data table, with options to include overall variables, exclude specific variables, and return as a list.} -\item{\code{get_nc_variable_names(file = "", as_list = FALSE, ...)}}{Returns the variable names from the specified NetCDF file, with an option to return as a list.} -\item{\code{has_database_connection()}}{Checks if there is a database connection.} -\item{\code{database_connect(dbname, user, host, port, drv = RMySQL::MySQL())}}{Connects to a database using the provided credentials and driver.} -\item{\code{get_database_connection()}}{Returns the current database connection.} -\item{\code{set_database_connection(dbi_connection)}}{Sets the database connection to the specified DBI connection object.} -\item{\code{database_disconnect()}}{Disconnects from the current database.} -\item{\code{import_from_climsoft(stationfiltercolumn = "stationId", stations = c(), elementfiltercolumn = "elementId", elements = c(), include_observation_data = FALSE, include_observation_flags = FALSE, unstack_data = FALSE, include_elements_info = FALSE, start_date = NULL, end_date = NULL)}}{Imports data from CLIMSOFT using the specified filters and options for observation data, flags, and unstacking.} -\item{\code{import_from_iri(download_from, data_file, data_frame_name, location_data_name, path, X1, X2 = NA, Y1, Y2 = NA, get_area_point = "area")}}{Imports data from IRI using the specified parameters for download, file path, coordinates, and area type.} -\item{\code{export_workspace(data_names, file, include_graphs = TRUE, include_models = TRUE, include_metadata = TRUE)}}{Exports the workspace to a file, including the specified data tables, graphs, models, and metadata.} -\item{\code{set_links(new_links)}}{Sets the links in the object to the specified new links.} -\item{\code{display_daily_graph(data_name, date_col = NULL, station_col = NULL, year_col = NULL, doy_col = NULL, climatic_element = NULL, upper_limit = 100, bar_colour = "blue", rug_colour = "red")}}{Displays a daily graph for the specified data table with options for columns, element, colors, and limits.} -\item{\code{create_variable_set(data_name, set_name, columns)}}{Creates a variable set with the specified name and columns in the given data table.} -\item{\code{update_variable_set(data_name, set_name, columns, new_set_name)}}{Updates the specified variable set with new columns and optionally a new name in the given data table.} -\item{\code{delete_variable_sets(data_name, set_names)}}{Deletes the specified variable sets from the given data table.} -\item{\code{get_variable_sets_names(data_name, include_overall = TRUE, include, exclude, include_empty = FALSE, as_list = FALSE, excluded_items = c())}}{Returns the names of variable sets for the specified data table, with options to include overall sets, exclude specific sets, and return as a list.} -\item{\code{get_variable_sets(data_name, set_names, force_as_list = FALSE)}}{Returns the specified variable sets from the given data table, with an option to force the result as a list.} -\item{\code{crops_definitions(data_name, year, station, rain, day, rain_totals, plant_days, plant_lengths, start_check = TRUE, season_data_name, start_day, end_day, definition_props = TRUE, print_table = TRUE)}}{Defines crop parameters for the specified data table using the provided columns and options for seasons, days, and properties.} -\item{\code{tidy_climatic_data(x, format, stack_cols, day, month, year, stack_years, station, element, element_name="value", ignore_invalid = FALSE, silent = FALSE, unstack_elements = TRUE, new_name)}}{Converts wide-format daily climatic data to long format using the specified columns and options for format, elements, and validation.} -\item{\code{get_geometry(data)}}{Returns the geometry column for the specified data table.} -\item{\code{package_check(package)}}{Checks if the specified package is installed and returns information about its version and availability.} -\item{\code{download_from_IRI(source, data, path = tempdir(), min_lon, max_lon, min_lat, max_lat, min_date, max_date, name, download_type = "Point", import = TRUE)}}{Downloads data from IRI using the specified source, data, coordinates, date range, and options for download type and import.} -\item{\code{patch_climate_element(data_name, date_col_name = "", var = "", vars = c(), max_mean_bias = NA, max_stdev_bias = NA, time_interval = "month", column_name, station_col_name = station_col_name)}}{Patches the specified climate element in the given data table using the provided columns and options for bias, time interval, and station.} -\item{\code{visualize_element_na(data_name, element_col_name, element_col_name_imputed, station_col_name, x_axis_labels_col_name, ncol = 2, type = "distribution", xlab = NULL, ylab = NULL, legend = TRUE, orientation = "horizontal", interval_size = interval_size, x_with_truth = NULL, measure = "percent")}}{Visualizes missing data for the specified element in the given data table using the provided columns and options for labels, legend, orientation, and measure.} -\item{\code{get_data_entry_data(data_name, station, date, elements, view_variables, station_name, type, start_date, end_date)}}{Returns data entry data for the specified data table using the provided columns and options for date range, variables, and type.} -\item{\code{save_data_entry_data(data_name, new_data, rows_changed, comments_list = list(), add_flags = FALSE, ...)}}{Saves data entry data to the specified data table with options for adding comments, flags, and rows changed.} -\item{\code{import_from_cds(user, dataset, elements, start_date, end_date, lon, lat, path, import = FALSE, new_name)}}{Imports data from CDS using the specified user, dataset, elements, date range, coordinates, and options for file path and import.} -\item{\code{add_flag_fields(data_name, col_names, key_column_names)}}{Adds flag fields to the specified columns in the given data table, using the provided key columns.} -\item{\code{remove_empty(data_name, which = c("rows","cols"))}}{Removes empty rows or columns from the specified data table.} -\item{\code{replace_values_with_NA(data_name, row_index, column_index)}}{Replaces values with NA in the specified rows and columns of the given data table.} -\item{\code{has_labels(data_name, col_names)}}{Checks if the specified columns in the given data table have labels.} -\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.} -} - -\section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{data_objects_changed}}{Logical indicating whether the data objects have changed.} -} -\if{html}{\out{
}} -} -\section{Methods}{ -\subsection{Public methods}{ -\itemize{ -\item \href{#method-DataBook-new}{\code{DataBook$new()}} -\item \href{#method-DataBook-standardise_country_names}{\code{DataBook$standardise_country_names()}} -\item \href{#method-DataBook-define_as_climatic}{\code{DataBook$define_as_climatic()}} -\item \href{#method-DataBook-define_corruption_outputs}{\code{DataBook$define_corruption_outputs()}} -\item \href{#method-DataBook-define_red_flags}{\code{DataBook$define_red_flags()}} -\item \href{#method-DataBook-define_as_procurement}{\code{DataBook$define_as_procurement()}} -\item \href{#method-DataBook-define_as_procurement_country_level_data}{\code{DataBook$define_as_procurement_country_level_data()}} -\item \href{#method-DataBook-get_CRI_component_column_names}{\code{DataBook$get_CRI_component_column_names()}} -\item \href{#method-DataBook-get_red_flag_column_names}{\code{DataBook$get_red_flag_column_names()}} -\item \href{#method-DataBook-get_CRI_column_names}{\code{DataBook$get_CRI_column_names()}} -\item \href{#method-DataBook-get_corruption_column_name}{\code{DataBook$get_corruption_column_name()}} -\item \href{#method-DataBook-import_data}{\code{DataBook$import_data()}} -\item \href{#method-DataBook-replace_instat_object}{\code{DataBook$replace_instat_object()}} -\item \href{#method-DataBook-set_data_objects}{\code{DataBook$set_data_objects()}} -\item \href{#method-DataBook-copy_data_object}{\code{DataBook$copy_data_object()}} -\item \href{#method-DataBook-import_RDS}{\code{DataBook$import_RDS()}} -\item \href{#method-DataBook-clone_data_object}{\code{DataBook$clone_data_object()}} -\item \href{#method-DataBook-clone_instat_calculation}{\code{DataBook$clone_instat_calculation()}} -\item \href{#method-DataBook-import_from_ODK}{\code{DataBook$import_from_ODK()}} -\item \href{#method-DataBook-set_meta}{\code{DataBook$set_meta()}} -\item \href{#method-DataBook-set_objects}{\code{DataBook$set_objects()}} -\item \href{#method-DataBook-set_scalars}{\code{DataBook$set_scalars()}} -\item \href{#method-DataBook-append_data_object}{\code{DataBook$append_data_object()}} -\item \href{#method-DataBook-get_data_objects}{\code{DataBook$get_data_objects()}} -\item \href{#method-DataBook-get_data_frame}{\code{DataBook$get_data_frame()}} -\item \href{#method-DataBook-get_variables_metadata}{\code{DataBook$get_variables_metadata()}} -\item \href{#method-DataBook-get_column_data_types}{\code{DataBook$get_column_data_types()}} -\item \href{#method-DataBook-get_column_labels}{\code{DataBook$get_column_labels()}} -\item \href{#method-DataBook-get_data_frame_label}{\code{DataBook$get_data_frame_label()}} -\item \href{#method-DataBook-get_data_frame_metadata}{\code{DataBook$get_data_frame_metadata()}} -\item \href{#method-DataBook-get_combined_metadata}{\code{DataBook$get_combined_metadata()}} -\item \href{#method-DataBook-get_metadata}{\code{DataBook$get_metadata()}} -\item \href{#method-DataBook-get_data_names}{\code{DataBook$get_data_names()}} -\item \href{#method-DataBook-get_data_changed}{\code{DataBook$get_data_changed()}} -\item \href{#method-DataBook-get_variables_metadata_changed}{\code{DataBook$get_variables_metadata_changed()}} -\item \href{#method-DataBook-get_metadata_changed}{\code{DataBook$get_metadata_changed()}} -\item \href{#method-DataBook-get_calculations}{\code{DataBook$get_calculations()}} -\item \href{#method-DataBook-get_calculation_names}{\code{DataBook$get_calculation_names()}} -\item \href{#method-DataBook-get_scalars}{\code{DataBook$get_scalars()}} -\item \href{#method-DataBook-get_scalar_names}{\code{DataBook$get_scalar_names()}} -\item \href{#method-DataBook-get_scalar_value}{\code{DataBook$get_scalar_value()}} -\item \href{#method-DataBook-add_scalar}{\code{DataBook$add_scalar()}} -\item \href{#method-DataBook-dataframe_count}{\code{DataBook$dataframe_count()}} -\item \href{#method-DataBook-set_data_frames_changed}{\code{DataBook$set_data_frames_changed()}} -\item \href{#method-DataBook-set_variables_metadata_changed}{\code{DataBook$set_variables_metadata_changed()}} -\item \href{#method-DataBook-set_metadata_changed}{\code{DataBook$set_metadata_changed()}} -\item \href{#method-DataBook-add_columns_to_data}{\code{DataBook$add_columns_to_data()}} -\item \href{#method-DataBook-get_columns_from_data}{\code{DataBook$get_columns_from_data()}} -\item \href{#method-DataBook-create_graph_data_book}{\code{DataBook$create_graph_data_book()}} -\item \href{#method-DataBook-add_object}{\code{DataBook$add_object()}} -\item \href{#method-DataBook-get_object_names}{\code{DataBook$get_object_names()}} -\item \href{#method-DataBook-get_objects}{\code{DataBook$get_objects()}} -\item \href{#method-DataBook-get_object}{\code{DataBook$get_object()}} -\item \href{#method-DataBook-get_object_data}{\code{DataBook$get_object_data()}} -\item \href{#method-DataBook-get_objects_data}{\code{DataBook$get_objects_data()}} -\item \href{#method-DataBook-get_last_object_data}{\code{DataBook$get_last_object_data()}} -\item \href{#method-DataBook-rename_object}{\code{DataBook$rename_object()}} -\item \href{#method-DataBook-delete_objects}{\code{DataBook$delete_objects()}} -\item \href{#method-DataBook-reorder_objects}{\code{DataBook$reorder_objects()}} -\item \href{#method-DataBook-get_from_object}{\code{DataBook$get_from_object()}} -\item \href{#method-DataBook-add_filter}{\code{DataBook$add_filter()}} -\item \href{#method-DataBook-add_filter_as_levels}{\code{DataBook$add_filter_as_levels()}} -\item \href{#method-DataBook-current_filter}{\code{DataBook$current_filter()}} -\item \href{#method-DataBook-set_current_filter}{\code{DataBook$set_current_filter()}} -\item \href{#method-DataBook-get_filter}{\code{DataBook$get_filter()}} -\item \href{#method-DataBook-get_filter_as_logical}{\code{DataBook$get_filter_as_logical()}} -\item \href{#method-DataBook-get_current_filter}{\code{DataBook$get_current_filter()}} -\item \href{#method-DataBook-get_filter_row_names}{\code{DataBook$get_filter_row_names()}} -\item \href{#method-DataBook-get_current_filter_name}{\code{DataBook$get_current_filter_name()}} -\item \href{#method-DataBook-get_filter_names}{\code{DataBook$get_filter_names()}} -\item \href{#method-DataBook-remove_current_filter}{\code{DataBook$remove_current_filter()}} -\item \href{#method-DataBook-filter_applied}{\code{DataBook$filter_applied()}} -\item \href{#method-DataBook-filter_string}{\code{DataBook$filter_string()}} -\item \href{#method-DataBook-get_filter_as_instat_calculation}{\code{DataBook$get_filter_as_instat_calculation()}} -\item \href{#method-DataBook-add_column_selection}{\code{DataBook$add_column_selection()}} -\item \href{#method-DataBook-current_column_selection}{\code{DataBook$current_column_selection()}} -\item \href{#method-DataBook-set_current_column_selection}{\code{DataBook$set_current_column_selection()}} -\item \href{#method-DataBook-get_column_selection}{\code{DataBook$get_column_selection()}} -\item \href{#method-DataBook-get_column_selection_column_names}{\code{DataBook$get_column_selection_column_names()}} -\item \href{#method-DataBook-get_column_selected_column_names}{\code{DataBook$get_column_selected_column_names()}} -\item \href{#method-DataBook-get_current_column_selection}{\code{DataBook$get_current_column_selection()}} -\item \href{#method-DataBook-get_current_column_selection_name}{\code{DataBook$get_current_column_selection_name()}} -\item \href{#method-DataBook-get_column_selection_names}{\code{DataBook$get_column_selection_names()}} -\item \href{#method-DataBook-remove_current_column_selection}{\code{DataBook$remove_current_column_selection()}} -\item \href{#method-DataBook-column_selection_applied}{\code{DataBook$column_selection_applied()}} -\item \href{#method-DataBook-replace_value_in_data}{\code{DataBook$replace_value_in_data()}} -\item \href{#method-DataBook-paste_from_clipboard}{\code{DataBook$paste_from_clipboard()}} -\item \href{#method-DataBook-rename_column_in_data}{\code{DataBook$rename_column_in_data()}} -\item \href{#method-DataBook-frequency_tables}{\code{DataBook$frequency_tables()}} -\item \href{#method-DataBook-anova_tables}{\code{DataBook$anova_tables()}} -\item \href{#method-DataBook-cor}{\code{DataBook$cor()}} -\item \href{#method-DataBook-remove_columns_in_data}{\code{DataBook$remove_columns_in_data()}} -\item \href{#method-DataBook-remove_rows_in_data}{\code{DataBook$remove_rows_in_data()}} -\item \href{#method-DataBook-get_next_default_column_name}{\code{DataBook$get_next_default_column_name()}} -\item \href{#method-DataBook-get_column_names}{\code{DataBook$get_column_names()}} -\item \href{#method-DataBook-reorder_columns_in_data}{\code{DataBook$reorder_columns_in_data()}} -\item \href{#method-DataBook-insert_row_in_data}{\code{DataBook$insert_row_in_data()}} -\item \href{#method-DataBook-get_data_frame_length}{\code{DataBook$get_data_frame_length()}} -\item \href{#method-DataBook-get_next_default_dataframe_name}{\code{DataBook$get_next_default_dataframe_name()}} -\item \href{#method-DataBook-delete_dataframes}{\code{DataBook$delete_dataframes()}} -\item \href{#method-DataBook-remove_link}{\code{DataBook$remove_link()}} -\item \href{#method-DataBook-get_column_factor_levels}{\code{DataBook$get_column_factor_levels()}} -\item \href{#method-DataBook-get_factor_data_frame}{\code{DataBook$get_factor_data_frame()}} -\item \href{#method-DataBook-sort_dataframe}{\code{DataBook$sort_dataframe()}} -\item \href{#method-DataBook-rename_dataframe}{\code{DataBook$rename_dataframe()}} -\item \href{#method-DataBook-convert_column_to_type}{\code{DataBook$convert_column_to_type()}} -\item \href{#method-DataBook-append_to_variables_metadata}{\code{DataBook$append_to_variables_metadata()}} -\item \href{#method-DataBook-append_to_dataframe_metadata}{\code{DataBook$append_to_dataframe_metadata()}} -\item \href{#method-DataBook-append_to_metadata}{\code{DataBook$append_to_metadata()}} -\item \href{#method-DataBook-add_metadata_field}{\code{DataBook$add_metadata_field()}} -\item \href{#method-DataBook-reorder_dataframes}{\code{DataBook$reorder_dataframes()}} -\item \href{#method-DataBook-copy_columns}{\code{DataBook$copy_columns()}} -\item \href{#method-DataBook-drop_unused_factor_levels}{\code{DataBook$drop_unused_factor_levels()}} -\item \href{#method-DataBook-set_factor_levels}{\code{DataBook$set_factor_levels()}} -\item \href{#method-DataBook-edit_factor_level}{\code{DataBook$edit_factor_level()}} -\item \href{#method-DataBook-set_factor_reference_level}{\code{DataBook$set_factor_reference_level()}} -\item \href{#method-DataBook-get_column_count}{\code{DataBook$get_column_count()}} -\item \href{#method-DataBook-reorder_factor_levels}{\code{DataBook$reorder_factor_levels()}} -\item \href{#method-DataBook-get_data_type}{\code{DataBook$get_data_type()}} -\item \href{#method-DataBook-copy_data_frame}{\code{DataBook$copy_data_frame()}} -\item \href{#method-DataBook-copy_col_metadata_to_clipboard}{\code{DataBook$copy_col_metadata_to_clipboard()}} -\item \href{#method-DataBook-copy_data_frame_metadata_to_clipboard}{\code{DataBook$copy_data_frame_metadata_to_clipboard()}} -\item \href{#method-DataBook-copy_to_clipboard}{\code{DataBook$copy_to_clipboard()}} -\item \href{#method-DataBook-set_hidden_columns}{\code{DataBook$set_hidden_columns()}} -\item \href{#method-DataBook-unhide_all_columns}{\code{DataBook$unhide_all_columns()}} -\item \href{#method-DataBook-set_hidden_data_frames}{\code{DataBook$set_hidden_data_frames()}} -\item \href{#method-DataBook-get_hidden_data_frames}{\code{DataBook$get_hidden_data_frames()}} -\item \href{#method-DataBook-set_row_names}{\code{DataBook$set_row_names()}} -\item \href{#method-DataBook-get_row_names}{\code{DataBook$get_row_names()}} -\item \href{#method-DataBook-set_protected_columns}{\code{DataBook$set_protected_columns()}} -\item \href{#method-DataBook-get_metadata_fields}{\code{DataBook$get_metadata_fields()}} -\item \href{#method-DataBook-freeze_columns}{\code{DataBook$freeze_columns()}} -\item \href{#method-DataBook-unfreeze_columns}{\code{DataBook$unfreeze_columns()}} -\item \href{#method-DataBook-is_variables_metadata}{\code{DataBook$is_variables_metadata()}} -\item \href{#method-DataBook-data_frame_exists}{\code{DataBook$data_frame_exists()}} -\item \href{#method-DataBook-add_key}{\code{DataBook$add_key()}} -\item \href{#method-DataBook-is_key}{\code{DataBook$is_key()}} -\item \href{#method-DataBook-has_key}{\code{DataBook$has_key()}} -\item \href{#method-DataBook-get_keys}{\code{DataBook$get_keys()}} -\item \href{#method-DataBook-add_new_comment}{\code{DataBook$add_new_comment()}} -\item \href{#method-DataBook-get_comments}{\code{DataBook$get_comments()}} -\item \href{#method-DataBook-get_links}{\code{DataBook$get_links()}} -\item \href{#method-DataBook-set_structure_columns}{\code{DataBook$set_structure_columns()}} -\item \href{#method-DataBook-add_dependent_columns}{\code{DataBook$add_dependent_columns()}} -\item \href{#method-DataBook-set_column_colours}{\code{DataBook$set_column_colours()}} -\item \href{#method-DataBook-has_colours}{\code{DataBook$has_colours()}} -\item \href{#method-DataBook-remove_column_colours}{\code{DataBook$remove_column_colours()}} -\item \href{#method-DataBook-set_column_colours_by_metadata}{\code{DataBook$set_column_colours_by_metadata()}} -\item \href{#method-DataBook-graph_one_variable}{\code{DataBook$graph_one_variable()}} -\item \href{#method-DataBook-make_date_yearmonthday}{\code{DataBook$make_date_yearmonthday()}} -\item \href{#method-DataBook-make_date_yeardoy}{\code{DataBook$make_date_yeardoy()}} -\item \href{#method-DataBook-set_contrasts_of_factor}{\code{DataBook$set_contrasts_of_factor()}} -\item \href{#method-DataBook-create_factor_data_frame}{\code{DataBook$create_factor_data_frame()}} -\item \href{#method-DataBook-split_date}{\code{DataBook$split_date()}} -\item \href{#method-DataBook-make_inventory_plot}{\code{DataBook$make_inventory_plot()}} -\item \href{#method-DataBook-import_NetCDF}{\code{DataBook$import_NetCDF()}} -\item \href{#method-DataBook-infill_missing_dates}{\code{DataBook$infill_missing_dates()}} -\item \href{#method-DataBook-get_key_names}{\code{DataBook$get_key_names()}} -\item \href{#method-DataBook-remove_key}{\code{DataBook$remove_key()}} -\item \href{#method-DataBook-add_climdex_indices}{\code{DataBook$add_climdex_indices()}} -\item \href{#method-DataBook-is_metadata}{\code{DataBook$is_metadata()}} -\item \href{#method-DataBook-get_climatic_column_name}{\code{DataBook$get_climatic_column_name()}} -\item \href{#method-DataBook-merge_data}{\code{DataBook$merge_data()}} -\item \href{#method-DataBook-get_corruption_data_names}{\code{DataBook$get_corruption_data_names()}} -\item \href{#method-DataBook-get_corruption_contract_data_names}{\code{DataBook$get_corruption_contract_data_names()}} -\item \href{#method-DataBook-get_database_variable_names}{\code{DataBook$get_database_variable_names()}} -\item \href{#method-DataBook-get_nc_variable_names}{\code{DataBook$get_nc_variable_names()}} -\item \href{#method-DataBook-has_database_connection}{\code{DataBook$has_database_connection()}} -\item \href{#method-DataBook-database_connect}{\code{DataBook$database_connect()}} -\item \href{#method-DataBook-get_database_connection}{\code{DataBook$get_database_connection()}} -\item \href{#method-DataBook-set_database_connection}{\code{DataBook$set_database_connection()}} -\item \href{#method-DataBook-database_disconnect}{\code{DataBook$database_disconnect()}} -\item \href{#method-DataBook-get_db_table_row_count}{\code{DataBook$get_db_table_row_count()}} -\item \href{#method-DataBook-import_climsoft_metadata}{\code{DataBook$import_climsoft_metadata()}} -\item \href{#method-DataBook-import_climsoft_data}{\code{DataBook$import_climsoft_data()}} -\item \href{#method-DataBook-import_from_iri}{\code{DataBook$import_from_iri()}} -\item \href{#method-DataBook-export_workspace}{\code{DataBook$export_workspace()}} -\item \href{#method-DataBook-set_links}{\code{DataBook$set_links()}} -\item \href{#method-DataBook-display_daily_graph}{\code{DataBook$display_daily_graph()}} -\item \href{#method-DataBook-create_variable_set}{\code{DataBook$create_variable_set()}} -\item \href{#method-DataBook-update_variable_set}{\code{DataBook$update_variable_set()}} -\item \href{#method-DataBook-delete_variable_sets}{\code{DataBook$delete_variable_sets()}} -\item \href{#method-DataBook-get_variable_sets_names}{\code{DataBook$get_variable_sets_names()}} -\item \href{#method-DataBook-get_variable_sets}{\code{DataBook$get_variable_sets()}} -\item \href{#method-DataBook-crops_definitions}{\code{DataBook$crops_definitions()}} -\item \href{#method-DataBook-tidy_climatic_data}{\code{DataBook$tidy_climatic_data()}} -\item \href{#method-DataBook-get_geometry}{\code{DataBook$get_geometry()}} -\item \href{#method-DataBook-package_check}{\code{DataBook$package_check()}} -\item \href{#method-DataBook-download_from_IRI}{\code{DataBook$download_from_IRI()}} -\item \href{#method-DataBook-patch_climate_element}{\code{DataBook$patch_climate_element()}} -\item \href{#method-DataBook-visualize_element_na}{\code{DataBook$visualize_element_na()}} -\item \href{#method-DataBook-get_data_entry_data}{\code{DataBook$get_data_entry_data()}} -\item \href{#method-DataBook-save_data_entry_data}{\code{DataBook$save_data_entry_data()}} -\item \href{#method-DataBook-import_from_cds}{\code{DataBook$import_from_cds()}} -\item \href{#method-DataBook-add_flag_fields}{\code{DataBook$add_flag_fields()}} -\item \href{#method-DataBook-remove_empty}{\code{DataBook$remove_empty()}} -\item \href{#method-DataBook-replace_values_with_NA}{\code{DataBook$replace_values_with_NA()}} -\item \href{#method-DataBook-has_labels}{\code{DataBook$has_labels()}} -\item \href{#method-DataBook-wrap_or_unwrap_data}{\code{DataBook$wrap_or_unwrap_data()}} -\item \href{#method-DataBook-anova_tables2}{\code{DataBook$anova_tables2()}} -\item \href{#method-DataBook-define_as_options_by_context}{\code{DataBook$define_as_options_by_context()}} -\item \href{#method-DataBook-update_links_rename_data_frame}{\code{DataBook$update_links_rename_data_frame()}} -\item \href{#method-DataBook-update_links_rename_column}{\code{DataBook$update_links_rename_column()}} -\item \href{#method-DataBook-add_link}{\code{DataBook$add_link()}} -\item \href{#method-DataBook-get_link_names}{\code{DataBook$get_link_names()}} -\item \href{#method-DataBook-link_exists_from}{\code{DataBook$link_exists_from()}} -\item \href{#method-DataBook-link_exists_between}{\code{DataBook$link_exists_between()}} -\item \href{#method-DataBook-get_link_between}{\code{DataBook$get_link_between()}} -\item \href{#method-DataBook-link_exists_from_by_to}{\code{DataBook$link_exists_from_by_to()}} -\item \href{#method-DataBook-get_linked_to_data_name}{\code{DataBook$get_linked_to_data_name()}} -\item \href{#method-DataBook-get_linked_to_definition}{\code{DataBook$get_linked_to_definition()}} -\item \href{#method-DataBook-get_possible_linked_to_definition}{\code{DataBook$get_possible_linked_to_definition()}} -\item \href{#method-DataBook-get_equivalent_columns}{\code{DataBook$get_equivalent_columns()}} -\item \href{#method-DataBook-link_between_containing}{\code{DataBook$link_between_containing()}} -\item \href{#method-DataBook-view_link}{\code{DataBook$view_link()}} -\item \href{#method-DataBook-import_SST}{\code{DataBook$import_SST()}} -\item \href{#method-DataBook-clone}{\code{DataBook$clone()}} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-new}{}}} -\subsection{Method \code{new()}}{ -Initialize a new DataBook object. - - -Standardize country names in the specified data table. - - -Define a data table as climatic data. - - -Define corruption output columns in the specified data table. - - -Define red flag columns in the specified data table. - - -Define a data table as procurement data. - - -Define a data table as procurement country-level data. - - -Get the names of CRI component columns in the specified data table. - - -Get the names of red flag columns in the specified data table. - - -Get the names of CRI columns in the specified data table. - - -Get the name of the corruption column in the specified data table. - - -Imports data tables and their associated metadata into the DataBook object. - - -Replaces the instat object in the DataBook. - - -Sets the data objects within the DataBook. - - -Copies a data object with an optional filter and column selection. - - -Imports data from an RDS file into the DataBook. - - -Clones a data object with options to include metadata, logs, filters, etc. - - -Clones an instat calculation with manipulations and sub-calculations. - - -Imports data from an ODK platform. - - -Sets metadata for the DataBook. - - -Sets objects in the DataBook. - - -Sets scalar values in the DataBook. - - -Appends a data object to the DataBook. - - -Retrieve data objects from the DataBook by name. - - -Retrieve data frames from the DataBook. - - -Retrieve metadata for variables in a data frame. - - -Retrieve data types for specific columns in a data frame. - - -Retrieve labels for specific columns in a data frame. - - -Retrieve the label of a data frame. - - -Retrieve metadata for a data frame. - - -Retrieve combined metadata across all data objects in the DataBook. - - -Retrieve metadata for a specific property. - - -Retrieve data names from the data book. - - -Check if data has changed. - - -Check if variables metadata has changed. - - -Check if metadata has changed. - - -Retrieve calculations for a specific data table. - - -Retrieve calculation names for a specific data table. - - -Retrieve scalars for a specific data table. - - -Retrieve scalar names for a specific data table. - - -Retrieve the value of a specific scalar for a data table. - - -Add a scalar to a data table. - - -Get the count of data frames in the DataBook. - - -Set the data changed status for the specified data frame. - - -Set the variables metadata changed status for the specified data frame. - - -Set the metadata changed status for the specified data frame. - - -Add columns to the specified data frame. - - -Get specified columns from the data frame. - - -Create a new graph data book and assign it to the global environment. - - -Add an object to the DataBook. - - -Get the names of objects in the DataBook. - - -Get objects from the DataBook. - - -Get a specific object from the DataBook. - - -Get the data of a specific object. - - -Retrieve data objects from a specified data table. - - -Retrieve the last object data based on the specified type label. - - -Rename an object within a specified data table. - - -Delete specified objects from a data table. - - -Reorder objects in a specified data table. - - -Retrieve a value from a specified object. - - -Add a filter to the specified data table. - - -Add a filter as levels for a specified column in the data table. - - -Retrieve the current filter applied to a specified data table. - - -Set the current filter for a specified data table. - - -Retrieve a specific filter by name. - - -Retrieve a filter as a logical vector. - - -Retrieve the currently applied filter for a specified data table. - - -Retrieve row names based on a specific filter for a data table. - - -Retrieve the name of the current filter for a specified data table. - - -Retrieve the names of all filters for a specified data table. - - -Remove the current filter from a specified data table. - - -Check if a filter is applied to a specified data table. - - -Retrieve the string representation of a specific filter. - - -Retrieve a filter as an Instat calculation. - - -Add a column selection to a data table. - - -Get the current column selection for a data table. - - -Set the current column selection for a data table. - - -Get a specific column selection from a data table. - - -Get column names from a specified filter in a data table. - - -Get column names selected in a specific column selection. - - -Get the current column selection for a data table. - - -Get the name of the current column selection for a data table. - - -Get names of all column selections for a data table. - - -Remove the current column selection for a data table. - - -Check if a column selection has been applied to a data table. - - -Replace values in the data of a specified table. - - -Paste data from the clipboard into a specified data table. - - -Rename a column in the data of a specified table. - - -Generate frequency tables for specified columns in a data table. - - -Generate ANOVA tables for specified columns in a data table. - - -Calculate correlation between specified columns in a data table. - - -Remove specified columns from a data table. - - -Remove specified rows from a data table. - - -Get the next available default column name for a data table. - - -Retrieve the column names of a data table. - - -Reorder the columns in a data table. - - -Insert rows into a data table. - - -Get the length of a data frame. - - -Get the next default name for a data frame. - - -Delete specified data frames. - - -Remove a link by its name. - - -Get the factor levels of a specified column in a data table. - - -Get the data frame for a specified factor column. - - -Sort a data frame by specified column(s). - - -Rename a data frame and optionally update its label. - - -Convert specified columns to a different type. - - -Appends a new property and its value to the metadata of specified columns in a data table. - - -Appends a new property and its value to the metadata of a data table. - - -Appends a new property and its value to the metadata of the current object. - - -Adds a new metadata field and its value to the specified data table or all data tables. - - -Reorders the dataframes in the object according to the specified order. - - -Copies specified columns from a data table to another location or clipboard. - - -Drops unused levels from a factor column in the specified data table. - - -Sets new levels for a factor column in the specified data table. - - -Edits a level in a factor column in the specified data table. - - -Sets the reference level for a factor column in the specified data table. - - -Returns the number of columns in the specified data table. - - -Reorders the levels of a factor column in the specified data table. - - -Returns the data type of the specified column in the given data table. - - -Copies a data frame to a new name or clipboard. - - -Copies the metadata of specified columns to the clipboard. - - -Copies the metadata of the specified data table to the clipboard. - - -Copies the specified content to the clipboard. - - -Sets the specified columns as hidden in the given data table. - - -Unhides all columns in the specified data table or all data tables if data_name is missing. - - -Sets the specified data tables as hidden. - - -Returns a list of hidden data tables. - - -Sets the row names for the specified data table. - - -Returns the row names of the specified data table. - - -Sets the specified columns as protected in the given data table. - - -Returns the metadata fields of the specified data table. - - -Freezes the specified columns in the given data table. - - -Unfreezes all columns in the specified data table. - - -Checks if the specified property is metadata for the given columns in the data table. - - -Checks if the specified data table exists. - - -Adds a key to the specified columns in the given data table. - - -Checks if the specified columns are keys in the given data table. - - -Checks if the specified data table has a key. - - -Returns the keys of the specified data table. - - -Adds a new comment to the specified row and column in the given data table. - - -Returns the comments for the specified data table and comment ID. - - -Returns the links for the specified link name or all links. - - -Sets the structure columns for the specified data table. - - -Adds dependent columns to the specified columns in the given data table. - - -Sets the colours for the specified columns in the given data table. - - -Checks if the specified columns have colours in the given data table. - - -Removes the colours from all columns in the specified data table. - - -Sets the colours for the specified columns based on metadata in the given data table. - - -Creates a graph for a single variable in the specified data table. - - -Creates a date column from year, month, and day columns in the specified data table. - - -Creates a date column from year and day of year columns in the specified data table. - - -Sets the contrasts for a factor column in the specified data table. - - -Creates a new data frame for a factor column in the specified data table. - - -Splits a date column into multiple date components in the specified data table. - - -Create an inventory plot based on the provided data. - - -Import NetCDF data and convert it into a data frame. - - -Infill missing dates in the specified data. - - -Retrieve key names from a specified data table. - - -Remove a specified key from a data table. - - -Add climdex indices to a specified data table. - - -Check if a specified string is part of the metadata for a data table. - - -Get the climatic column name from the specified data table. - - -Merge new data into the specified data table. - - -Retrieve names of data tables containing corruption data. - - -Retrieve names of data tables containing corruption contract level data. - - -Get variable names from a database based on a query. - - -Get variable names from a NetCDF file. - - -Check if there is an active database connection. - - -Establish a connection to a database. - - -Retrieve the current database connection. - - -Set the database connection. - - -Disconnect from the database if a connection exists. - - -Get the row count of a specified table in the database. - - -Import Climsoft metadata, including stations, elements, and flags. - - -Imports data from Climsoft observation tables, either initial or final. -This function also imports selected stations and elements metadata. - - -Import data from an IRI source and process it. - - -Export the current workspace to a file, including optional components. - - -Set new links in the data structure. - - -Display a daily graph for specified climatic elements. - - -Create a set of variables from specified columns in the data frame. - - -Update an existing variable set with new columns. - - -Delete specified variable sets from the data frame. - - -Retrieve the names of variable sets in the data frame. - - -Get specific variable sets from the data frame. - - -Define crop conditions and create a new crop definition data frame. - - -Tidy climatic data into a specified format. - - -Retrieve the geometry column from a given data object. - - -Check the installation status and version of a specified package. - - -Download data from the IRI database based on specified parameters. - - -Patch a climate element in the specified data. - - -Visualize the missing values in a specified element within a dataset. - - -Retrieve data entry for specified elements within a date range. - - -Save new data entries and associated comments to the dataset. - - -Import data from CDS (Climate Data Store) for specified parameters. - - -Add flag fields to a specified dataset. - - -Remove empty rows or columns from a dataset. - - -Replace specified values with NA in a dataset. - - -Check if specified columns in a dataset have labels. - - -Wrap or unwrap data in a specified column of a dataset. - - -Generate ANOVA tables for specified columns in a dataset. - - -Display a daily summary table for a specified climatic data element. - - -Adds a new \code{instat_comment} object to the data sheet if the key is defined and valid. - - -Deletes a comment from the data sheet based on the comment ID. - - -Retrieves all comment IDs currently stored in the data sheet. - - -Converts all comments in the data sheet to a data frame format for easier inspection and analysis. - - -Imports SST data and adds keys and links to the specified data tables. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$new( - data_tables = list(), - instat_obj_metadata = list(), - data_tables_variables_metadata = rep(list(data.frame()), length(data_tables)), - data_tables_metadata = rep(list(list()), length(data_tables)), - data_tables_filters = rep(list(list()), length(data_tables)), - data_tables_column_selections = rep(list(list()), length(data_tables)), - imported_from = as.list(rep("", length(data_tables))), - messages = TRUE, - convert = TRUE, - create = TRUE -)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{data_tables}}{A list of data frames to be included in the DataBook.} - -\item{\code{data_tables}}{A list of data tables to be imported.} - -\item{\code{instat_obj_metadata}}{Metadata for the instat object.} - -\item{\code{data_tables_variables_metadata}}{A list of data frames, each containing metadata for the corresponding data table.} - -\item{\code{data_tables_variables_metadata}}{Metadata for the variables of each data table.} - -\item{\code{data_tables_metadata}}{A list of lists, each containing metadata for the corresponding data table.} - -\item{\code{data_tables_metadata}}{General metadata for each data table.} - -\item{\code{data_tables_filters}}{A list of lists, each containing filter information for the corresponding data table.} - -\item{\code{data_tables_filters}}{Filters applied to each data table.} - -\item{\code{data_tables_column_selections}}{A list of lists, each containing column selection information for the corresponding data table.} - -\item{\code{data_tables_column_selections}}{Column selections for each data table.} - -\item{\code{imported_from}}{A list of strings indicating the source from which each data table was imported.} - -\item{\code{imported_from}}{The origin/source of the imported data.} - -\item{\code{messages}}{A boolean indicating whether to display messages.} - -\item{\code{messages}}{A boolean indicating if messages should be displayed.} - -\item{\code{convert}}{A boolean indicating whether to perform data conversion.} - -\item{\code{convert}}{A boolean indicating if data conversion should occur.} - -\item{\code{create}}{A boolean indicating whether to create new data objects.} - -\item{\code{create}}{A boolean to create new data objects.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{country_columns}}{A vector of column names containing country data.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{types}}{A vector specifying the types of climatic data.} - -\item{\code{key_col_names}}{A vector of column names to be used as keys.} - -\item{\code{key_name}}{The name of the key.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{output_columns}}{A vector of column names to be defined as corruption outputs.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{red_flags}}{A vector of column names to be defined as red flags.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{primary_types}}{A vector of primary types of procurement data.} - -\item{\code{calculated_types}}{A vector of calculated types of procurement data.} - -\item{\code{country_data_name}}{The name of the country-level data table.} - -\item{\code{country_types}}{A vector of types for the country-level data.} - -\item{\code{auto_generate}}{A boolean indicating whether to auto-generate procurement types.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{contract_level_data_name}}{The name of the contract-level data table.} - -\item{\code{types}}{A vector of types for the procurement country-level data.} - -\item{\code{auto_generate}}{A boolean indicating whether to auto-generate procurement types.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{type}}{The type of the corruption column.} - -\item{\code{data_names}}{Optional names for the data tables.} - -\item{\code{prefix}}{A boolean indicating whether to prefix data names.} - -\item{\code{add_to_graph_book}}{A boolean to add the data to a graph book.} - -\item{\code{new_instat_object}}{The new instat object to replace the existing one.} - -\item{\code{new_data_objects}}{A list of data objects to be set.} - -\item{\code{data_name}}{The name of the data object to copy.} - -\item{\code{new_name}}{The new name for the copied data object.} - -\item{\code{filter_name}}{Optional filter to apply during the copy.} - -\item{\code{column_selection_name}}{Optional column selection to apply during the copy.} - -\item{\code{reset_row_names}}{A boolean indicating whether to reset row names.} - -\item{\code{data_RDS}}{The RDS file containing data.} - -\item{\code{keep_existing}}{A boolean to keep existing data.} - -\item{\code{overwrite_existing}}{A boolean to overwrite existing data if necessary.} - -\item{\code{include_objects}}{A boolean to include objects in the import.} - -\item{\code{include_metadata}}{A boolean to include metadata in the import.} - -\item{\code{include_logs}}{A boolean to include logs in the import.} - -\item{\code{include_filters}}{A boolean to include filters in the import.} - -\item{\code{include_column_selections}}{A boolean to include column selections in the import.} - -\item{\code{include_calculations}}{A boolean to include calculations in the import.} - -\item{\code{include_comments}}{A boolean to include comments in the import.} - -\item{\code{curr_data_object}}{The current data object to be cloned.} - -\item{\code{include_objects}}{A boolean to include objects in the clone.} - -\item{\code{include_metadata}}{A boolean to include metadata in the clone.} - -\item{\code{include_logs}}{A boolean to include logs in the clone.} - -\item{\code{include_filters}}{A boolean to include filters in the clone.} - -\item{\code{include_column_selections}}{A boolean to include column selections in the clone.} - -\item{\code{include_calculations}}{A boolean to include calculations in the clone.} - -\item{\code{include_comments}}{A boolean to include comments in the clone.} - -\item{\code{curr_instat_calculation}}{The current instat calculation to be cloned.} - -\item{\code{username}}{The username for ODK.} - -\item{\code{form_name}}{The name of the ODK form.} - -\item{\code{platform}}{The platform used for ODK.} - -\item{\code{new_meta}}{A list of metadata to be set.} - -\item{\code{new_objects}}{A list of objects to be set.} - -\item{\code{new_scalars}}{A list of scalar values to be set.} - -\item{\code{name}}{The name of the data object.} - -\item{\code{obj}}{The data object to append.} - -\item{\code{add_to_graph_book}}{A boolean to add the data to the graph book.} - -\item{\code{data_name}}{The name or index of the data object(s) to retrieve.} - -\item{\code{as_list}}{A boolean to return the data objects as a list (default: FALSE).} - -\item{\code{...}}{Additional arguments.} - -\item{\code{data_name}}{The name of the data frame to retrieve.} - -\item{\code{convert_to_character}}{A boolean indicating whether to convert data to character type (default: FALSE).} - -\item{\code{stack_data}}{A boolean to stack data (default: FALSE).} - -\item{\code{include_hidden_columns}}{A boolean to include hidden columns (default: TRUE).} - -\item{\code{use_current_filter}}{A boolean to apply the current filter (default: TRUE).} - -\item{\code{...}}{Additional arguments.} - -\item{\code{data_name}}{The name of the data frame.} - -\item{\code{data_type}}{The type of data to retrieve (default: "all").} - -\item{\code{convert_to_character}}{A boolean indicating whether to convert data to character type (default: FALSE).} - -\item{\code{property}}{The specific property to retrieve.} - -\item{\code{column}}{The column for which metadata is to be retrieved.} - -\item{\code{...}}{Additional arguments.} - -\item{\code{data_name}}{The name of the data frame.} - -\item{\code{columns}}{A vector of columns to retrieve the data types for.} - -\item{\code{data_name}}{The name of the data frame.} - -\item{\code{columns}}{A vector of columns to retrieve the labels for.} - -\item{\code{data_name}}{The name of the data frame.} - -\item{\code{use_current_filter}}{A boolean indicating whether to use the current filter (default: FALSE).} - -\item{\code{data_name}}{The name of the data frame.} - -\item{\code{label}}{The label for the metadata to retrieve.} - -\item{\code{include_calculated}}{A boolean indicating whether to include calculated columns (default: TRUE).} - -\item{\code{excluded_not_for_display}}{A boolean to exclude columns not for display (default: TRUE).} - -\item{\code{convert_to_character}}{A boolean to convert the metadata to a character matrix (default: FALSE).} - -\item{\code{name}}{The name of the metadata to retrieve.} - -\item{\code{as_list}}{A boolean indicating whether to return results as a list.} - -\item{\code{include}}{A vector of names to include.} - -\item{\code{exclude}}{A vector of names to exclude.} - -\item{\code{excluded_items}}{A vector of excluded items.} - -\item{\code{include_hidden}}{A boolean indicating whether to include hidden items.} - -\item{\code{data_name}}{The name of the data table to check.} - -\item{\code{data_name}}{The name of the data table to check.} - -\item{\code{data_name}}{The name of the data table to check.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{as_list}}{A boolean indicating whether to return results as a list.} - -\item{\code{excluded_items}}{A vector of excluded items.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{as_list}}{A boolean indicating whether to return results as a list.} - -\item{\code{excluded_items}}{A vector of excluded items.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{scalar_name}}{The name of the scalar.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{scalar_name}}{The name of the scalar (optional).} - -\item{\code{scalar_value}}{The value of the scalar.} - -\item{\code{data_name}}{The name of the data frame. Defaults to an empty string.} - -\item{\code{new_val}}{A boolean indicating the new changed status.} - -\item{\code{data_name}}{The name of the data frame. Defaults to an empty string.} - -\item{\code{new_val}}{A boolean indicating the new changed status.} - -\item{\code{data_name}}{The name of the data frame. Defaults to an empty string.} - -\item{\code{new_val}}{A boolean indicating the new changed status.} - -\item{\code{data_name}}{The name of the data frame.} - -\item{\code{col_name}}{The name of the new column.} - -\item{\code{col_data}}{The data for the new column.} - -\item{\code{use_col_name_as_prefix}}{A boolean indicating if the column name should be prefixed.} - -\item{\code{hidden}}{A boolean indicating if the column should be hidden.} - -\item{\code{before}}{The name of the column before which to insert the new column.} - -\item{\code{adjacent_column}}{The name of an adjacent column.} - -\item{\code{num_cols}}{The number of columns to add.} - -\item{\code{require_correct_length}}{A boolean indicating if the lengths of the data should match.} - -\item{\code{keep_existing_position}}{A boolean indicating if the existing column position should be maintained.} - -\item{\code{data_name}}{The name of the data frame.} - -\item{\code{col_names}}{A vector of column names to retrieve.} - -\item{\code{from_stacked_data}}{A boolean indicating if the data is stacked.} - -\item{\code{force_as_data_frame}}{A boolean indicating if the output should be a data frame.} - -\item{\code{use_current_filter}}{A boolean indicating if the current filter should be used.} - -\item{\code{remove_labels}}{A boolean indicating if labels should be removed.} - -\item{\code{drop_unused_filter_levels}}{A boolean indicating if unused filter levels should be dropped.} - -\item{\code{data_name}}{The name of the data frame.} - -\item{\code{object_name}}{The name of the object. If NULL, a default name is generated.} - -\item{\code{object_type_label}}{The label for the object type.} - -\item{\code{object_format}}{The format of the object.} - -\item{\code{object}}{The object to add.} - -\item{\code{data_name}}{The name of the data frame.} - -\item{\code{object_type_label}}{The label for the object type.} - -\item{\code{as_list}}{A boolean indicating if the output should be a list.} - -\item{\code{data_name}}{The name of the data frame.} - -\item{\code{object_type_label}}{The label for the object type.} - -\item{\code{data_name}}{The name of the data frame.} - -\item{\code{object_name}}{The name of the object to retrieve.} - -\item{\code{data_name}}{The name of the data frame.} - -\item{\code{object_name}}{The name of the object.} - -\item{\code{as_file}}{A boolean indicating if the output should be formatted as a file.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{object_names}}{A character vector of object names to retrieve.} - -\item{\code{as_files}}{A boolean indicating whether to return data as files.} - -\item{\code{object_type_label}}{The label of the object type to retrieve.} - -\item{\code{as_file}}{A boolean indicating whether to return the data as a file.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{object_name}}{The current name of the object to rename.} - -\item{\code{new_name}}{The new name for the object.} - -\item{\code{object_type}}{The type of the object being renamed.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{object_names}}{A character vector of object names to delete.} - -\item{\code{object_type}}{The type of the objects being deleted.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{new_order}}{A character vector specifying the new order of object names.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{object_name}}{The name of the object to retrieve data from.} - -\item{\code{value1}}{The first value/key to retrieve.} - -\item{\code{value2}}{The second value/key to retrieve.} - -\item{\code{value3}}{The third value/key to retrieve.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{filter}}{The filter to apply.} - -\item{\code{filter_name}}{The name of the filter.} - -\item{\code{replace}}{A boolean indicating whether to replace existing filters.} - -\item{\code{set_as_current_filter}}{A boolean indicating whether to set this filter as the current filter.} - -\item{\code{na.rm}}{A boolean indicating whether to remove NA values.} - -\item{\code{is_no_filter}}{A boolean indicating whether this is a "no filter".} - -\item{\code{and_or}}{A string indicating whether to apply AND or OR logic.} - -\item{\code{inner_not}}{A boolean for inner negation.} - -\item{\code{outer_not}}{A boolean for outer negation.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{filter_levels}}{The levels of the filter to add.} - -\item{\code{column}}{The column to apply the filter to.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{filter_name}}{The name of the filter to set as current.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{filter_name}}{The name of the filter to retrieve.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{filter_name}}{The name of the filter to retrieve.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{filter_name}}{The name of the filter to use for retrieval.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{as_list}}{A boolean indicating whether to return as a list.} - -\item{\code{include}}{A list of items to include.} - -\item{\code{exclude}}{A list of items to exclude.} - -\item{\code{excluded_items}}{A vector of excluded items.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{filter_name}}{The name of the filter to retrieve the string for.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{filter_name}}{The name of the filter to retrieve.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{column_selection}}{The selection of columns.} - -\item{\code{name}}{Optional name for the selection.} - -\item{\code{replace}}{Logical indicating if the selection should replace an existing one.} - -\item{\code{set_as_current}}{Logical indicating if the selection should be set as current.} - -\item{\code{is_everything}}{Logical indicating if all columns should be selected.} - -\item{\code{and_or}}{String indicating the logical operator to use.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{name}}{The name of the column selection to set as current.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{name}}{The name of the column selection to retrieve.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{filter_name}}{The name of the filter.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{column_selection_name}}{Optional name of the column selection.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{as_list}}{Logical indicating if results should be returned as a list.} - -\item{\code{include}}{List of items to include.} - -\item{\code{exclude}}{List of items to exclude.} - -\item{\code{excluded_items}}{Optional vector of excluded items.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_names}}{Names of the columns to modify.} - -\item{\code{rows}}{The rows to be modified.} - -\item{\code{old_value}}{The value to replace.} - -\item{\code{old_is_missing}}{Logical indicating if old_value is missing.} - -\item{\code{start_value}}{Optional starting value for replacement.} - -\item{\code{end_value}}{Optional ending value for replacement.} - -\item{\code{new_value}}{The new value to replace with.} - -\item{\code{new_is_missing}}{Logical indicating if new_value is missing.} - -\item{\code{closed_start_value}}{Logical for start value closure.} - -\item{\code{closed_end_value}}{Logical for end value closure.} - -\item{\code{locf}}{Logical indicating if last observation carried forward should be used.} - -\item{\code{from_last}}{Logical indicating if the replacement should start from the last.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_names}}{Names of the columns to paste into.} - -\item{\code{start_row_pos}}{Position to start pasting in the data.} - -\item{\code{first_clip_row_is_header}}{Logical indicating if the first row of the clipboard is a header.} - -\item{\code{clip_board_text}}{The text to paste from the clipboard.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{column_name}}{Optional name of the column to rename.} - -\item{\code{new_val}}{The new name for the column.} - -\item{\code{label}}{Optional label for the column.} - -\item{\code{type}}{Type of renaming operation.} - -\item{\code{.fn}}{Optional function for renaming.} - -\item{\code{.cols}}{Optional columns to rename.} - -\item{\code{new_column_names_df}}{Data frame with new column names.} - -\item{\code{new_labels_df}}{Data frame with new labels.} - -\item{\code{...}}{Additional parameters.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{x_col_names}}{Names of columns for x-axis.} - -\item{\code{y_col_name}}{Name of column for y-axis.} - -\item{\code{n_column_factors}}{Number of column factors.} - -\item{\code{store_results}}{Logical indicating if results should be stored.} - -\item{\code{drop}}{Logical indicating if to drop unused levels.} - -\item{\code{na.rm}}{Logical indicating if NA values should be removed.} - -\item{\code{summary_name}}{Optional name for the summary.} - -\item{\code{include_margins}}{Logical indicating if margins should be included.} - -\item{\code{return_output}}{Logical indicating if output should be returned.} - -\item{\code{treat_columns_as_factor}}{Logical indicating if columns should be treated as factors.} - -\item{\code{page_by}}{Pagination option.} - -\item{\code{as_html}}{Logical indicating if output should be in HTML format.} - -\item{\code{signif_fig}}{Number of significant figures.} - -\item{\code{na_display}}{Optional display for NA values.} - -\item{\code{na_level_display}}{Optional display for NA levels.} - -\item{\code{weights}}{Optional weights for frequency calculations.} - -\item{\code{caption}}{Optional caption for the output.} - -\item{\code{result_names}}{Optional names for results.} - -\item{\code{percentage_type}}{Type of percentage calculation.} - -\item{\code{perc_total_columns}}{Optional columns for total percentages.} - -\item{\code{perc_total_factors}}{Optional factors for total percentages.} - -\item{\code{perc_total_filter}}{Optional filter for total percentages.} - -\item{\code{perc_decimal}}{Logical indicating if percentages should be decimal.} - -\item{\code{margin_name}}{Name for the margin.} - -\item{\code{additional_filter}}{Optional additional filter.} - -\item{\code{...}}{Additional parameters.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{x_col_names}}{Names of columns for x-axis.} - -\item{\code{y_col_name}}{Name of column for y-axis.} - -\item{\code{signif.stars}}{Logical indicating if significance stars should be shown.} - -\item{\code{sign_level}}{Logical indicating if significance level should be displayed.} - -\item{\code{means}}{Logical indicating if means should be displayed.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{x_col_names}}{Names of columns for x-axis.} - -\item{\code{y_col_name}}{Name of column for y-axis.} - -\item{\code{use}}{How to handle missing values.} - -\item{\code{method}}{The method to use for correlation.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{cols}}{The columns to remove.} - -\item{\code{allow_delete_all}}{Logical indicating if all columns can be deleted.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{row_names}}{The names of the rows to remove.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{prefix}}{The prefix for the new column name.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{as_list}}{A boolean indicating whether to return the names as a list.} - -\item{\code{include}}{A list of column names to include.} - -\item{\code{exclude}}{A list of column names to exclude.} - -\item{\code{excluded_items}}{A vector of items to be excluded.} - -\item{\code{max_no}}{The maximum number of column names to return.} - -\item{\code{use_current_column_selection}}{A boolean indicating whether to use the current column selection.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_order}}{A vector specifying the new order of columns.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{start_row}}{The row number to start inserting at.} - -\item{\code{row_data}}{A vector of data for the new row(s).} - -\item{\code{number_rows}}{The number of rows to insert.} - -\item{\code{before}}{A boolean indicating whether to insert before the start_row.} - -\item{\code{data_name}}{The name of the data frame.} - -\item{\code{use_current_filter}}{A boolean indicating whether to use the current filter.} - -\item{\code{prefix}}{The prefix for the new data frame name.} - -\item{\code{include_index}}{A boolean indicating whether to include an index.} - -\item{\code{start_index}}{The starting index for naming.} - -\item{\code{data_names}}{A vector of data frame names to delete.} - -\item{\code{delete_graph_book}}{A boolean indicating whether to delete the associated graph book.} - -\item{\code{link_name}}{The name of the link to remove.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_name}}{The name of the column to check.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_name}}{The name of the column to retrieve.} - -\item{\code{include_levels}}{A boolean indicating whether to include levels.} - -\item{\code{include_NA_level}}{A boolean indicating whether to include NA as a level.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_names}}{A vector of column names to sort by.} - -\item{\code{decreasing}}{A boolean indicating whether to sort in decreasing order.} - -\item{\code{na.last}}{A boolean indicating how to handle NA values.} - -\item{\code{by_row_names}}{A boolean indicating whether to sort by row names.} - -\item{\code{row_names_as_numeric}}{A boolean indicating whether row names should be treated as numeric.} - -\item{\code{data_name}}{The current name of the data frame.} - -\item{\code{new_value}}{The new name for the data frame.} - -\item{\code{label}}{An optional label for the data frame.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_names}}{A vector of column names to convert.} - -\item{\code{to_type}}{The target data type.} - -\item{\code{factor_values}}{Optional values for factors.} - -\item{\code{set_digits}}{Number of digits to set.} - -\item{\code{set_decimals}}{A boolean indicating whether to set decimals.} - -\item{\code{keep_attr}}{A boolean indicating whether to keep attributes.} - -\item{\code{ignore_labels}}{A boolean indicating whether to ignore labels.} - -\item{\code{keep.labels}}{A boolean indicating whether to keep labels.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_names}}{A vector of column names to which the property should be appended.} - -\item{\code{property}}{The name of the property to append.} - -\item{\code{new_val}}{The value of the property to append. Default is an empty string.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{property}}{The name of the property to append.} - -\item{\code{new_val}}{The value of the property to append. Default is an empty string.} - -\item{\code{property}}{The name of the property to append.} - -\item{\code{new_val}}{The value of the property to append. Default is an empty string.} - -\item{\code{allow_override_special}}{Boolean flag to allow overriding special properties. Default is FALSE.} - -\item{\code{data_name}}{The name of the data table. Use overall_label to apply to all data tables.} - -\item{\code{property}}{The name of the property to append.} - -\item{\code{new_val}}{The value of the property to append. Default is an empty string.} - -\item{\code{data_frames_order}}{A vector specifying the new order of dataframes.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_names}}{A vector of column names to copy.} - -\item{\code{copy_to_clipboard}}{Boolean flag to copy to clipboard. Default is FALSE.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_name}}{The name of the column.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_name}}{The name of the column.} - -\item{\code{new_labels}}{A vector of new labels for the factor levels.} - -\item{\code{new_levels}}{A vector of new levels.} - -\item{\code{set_new_labels}}{Boolean flag to set new labels. Default is TRUE.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_name}}{The name of the column.} - -\item{\code{old_level}}{The old level to replace.} - -\item{\code{new_level}}{The new level to set.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_name}}{The name of the column.} - -\item{\code{new_ref_level}}{The new reference level.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{use_column_selection}}{Boolean flag to use column selection. Default is FALSE.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_name}}{The name of the column.} - -\item{\code{new_level_names}}{A vector specifying the new order of factor levels.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_name}}{The name of the column.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{new_name}}{The new name for the copied data frame.} - -\item{\code{label}}{A label for the new data frame. Default is an empty string.} - -\item{\code{copy_to_clipboard}}{Boolean flag to copy to clipboard. Default is FALSE.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{property_names}}{A vector of property names to copy. Default is all properties.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{property_names}}{A vector of property names to copy. Default is all properties.} - -\item{\code{content}}{The content to copy to the clipboard.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_names}}{A vector of column names to set as hidden.} - -\item{\code{data_name}}{The name of the data table. If missing, applies to all data tables.} - -\item{\code{data_names}}{A vector of data table names to set as hidden.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{row_names}}{A vector of row names to set.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_names}}{A vector of column names to set as protected.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{include_overall}}{Boolean flag to include overall metadata fields. Default is TRUE.} - -\item{\code{as_list}}{Boolean flag to return the result as a list. Default is FALSE.} - -\item{\code{include}}{A vector of metadata fields to include. Default is all fields.} - -\item{\code{exclude}}{A vector of metadata fields to exclude. Default is none.} - -\item{\code{excluded_items}}{A vector of metadata fields to exclude. Default is an empty vector.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{column}}{A vector of column names to freeze.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{property}}{The name of the property to check.} - -\item{\code{column}}{The name of the column.} - -\item{\code{return_vector}}{Boolean flag to return the result as a vector. Default is FALSE.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_names}}{A vector of column names to add as keys.} - -\item{\code{key_name}}{The name of the key.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_names}}{A vector of column names to check.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{key_name}}{The name of the key. Default is all keys.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{row}}{The name of the row.} - -\item{\code{column}}{The name of the column.} - -\item{\code{comment}}{The comment text.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{comment_id}}{The ID of the comment.} - -\item{\code{link_name}}{The name of the link. Default is all links.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{struc_type_1}}{A vector of column names for the first structure type.} - -\item{\code{struc_type_2}}{A vector of column names for the second structure type.} - -\item{\code{struc_type_3}}{A vector of column names for the third structure type.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{columns}}{A vector of column names to add dependents to.} - -\item{\code{dependent_cols}}{A vector of dependent column names.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{columns}}{A vector of column names to set colours for.} - -\item{\code{colours}}{A vector of colours.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{columns}}{A vector of column names to check.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{columns}}{A vector of column names to set colours for.} - -\item{\code{property}}{The metadata property to use for setting colours.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{columns}}{A vector of column names to graph.} - -\item{\code{numeric}}{The type of graph for numeric columns. Default is "geom_boxplot".} - -\item{\code{categorical}}{The type of graph for categorical columns. Default is "geom_bar".} - -\item{\code{character}}{The type of graph for character columns. Default is "geom_bar".} - -\item{\code{output}}{The output type for the graph. Default is "facets".} - -\item{\code{free_scale_axis}}{Boolean flag to allow free scaling of axes. Default is FALSE.} - -\item{\code{ncol}}{The number of columns in the output. Default is NULL.} - -\item{\code{coord_flip}}{Boolean flag to flip coordinates. Default is FALSE.} - -\item{\code{...}}{Additional arguments passed to the graph function.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{year}}{The name of the year column.} - -\item{\code{month}}{The name of the month column.} - -\item{\code{day}}{The name of the day column.} - -\item{\code{f_year}}{The format for the year column.} - -\item{\code{f_month}}{The format for the month column.} - -\item{\code{f_day}}{The format for the day column.} - -\item{\code{year_format}}{The format for the year. Default is "\%Y".} - -\item{\code{month_format}}{The format for the month. Default is "\%m".} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{year}}{The name of the year column.} - -\item{\code{doy}}{The name of the day of year column.} - -\item{\code{base}}{The base date for the day of year.} - -\item{\code{doy_typical_length}}{The typical length of the day of year. Default is "366".} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_name}}{The name of the column.} - -\item{\code{new_contrasts}}{A vector of new contrasts.} - -\item{\code{defined_contr_matrix}}{A defined contrast matrix.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{factor}}{The name of the factor column.} - -\item{\code{factor_data_frame_name}}{The name of the new data frame.} - -\item{\code{include_contrasts}}{Boolean flag to include contrasts. Default is FALSE.} - -\item{\code{replace}}{Boolean flag to replace the existing factor data frame. Default is FALSE.} - -\item{\code{summary_count}}{Boolean flag to include summary count. Default is TRUE.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_name}}{The name of the date column.} - -\item{\code{year_val}}{Boolean flag to include year value. Default is FALSE.} - -\item{\code{year_name}}{Boolean flag to include year name. Default is FALSE.} - -\item{\code{leap_year}}{Boolean flag to include leap year. Default is FALSE.} - -\item{\code{month_val}}{Boolean flag to include month value. Default is FALSE.} - -\item{\code{month_abbr}}{Boolean flag to include month abbreviation. Default is FALSE.} - -\item{\code{month_name}}{Boolean flag to include month name. Default is FALSE.} - -\item{\code{week_val}}{Boolean flag to include week value. Default is FALSE.} - -\item{\code{week_abbr}}{Boolean flag to include week abbreviation. Default is FALSE.} - -\item{\code{week_name}}{Boolean flag to include week name. Default is FALSE.} - -\item{\code{weekday_val}}{Boolean flag to include weekday value. Default is FALSE.} - -\item{\code{weekday_abbr}}{Boolean flag to include weekday abbreviation. Default is FALSE.} - -\item{\code{weekday_name}}{Boolean flag to include weekday name. Default is FALSE.} - -\item{\code{day}}{Boolean flag to include day value. Default is FALSE.} - -\item{\code{day_in_month}}{Boolean flag to include day in month. Default is FALSE.} - -\item{\code{day_in_year}}{Boolean flag to include day in year. Default is FALSE.} - -\item{\code{day_in_year_366}}{Boolean flag to include day in year (366). Default is FALSE.} - -\item{\code{pentad_val}}{Boolean flag to include pentad value. Default is FALSE.} - -\item{\code{pentad_abbr}}{Boolean flag to include pentad abbreviation. Default is FALSE.} - -\item{\code{dekad_val}}{Boolean flag to include dekad value. Default is FALSE.} - -\item{\code{dekad_abbr}}{Boolean flag to include dekad abbreviation. Default is FALSE.} - -\item{\code{quarter_val}}{Boolean flag to include quarter value. Default is FALSE.} - -\item{\code{quarter_abbr}}{Boolean flag to include quarter abbreviation. Default is FALSE.} - -\item{\code{with_year}}{Boolean flag to include with year. Default is FALSE.} - -\item{\code{s_start_month}}{The start month. Default is 1.} - -\item{\code{s_start_day_in_month}}{The start day in month. Default is 1.} - -\item{\code{days_in_month}}{Boolean flag to include days in month. Default is FALSE.} - -\item{\code{data_name}}{The name of the data table containing inventory data.} - -\item{\code{date_col}}{The name of the column representing dates.} - -\item{\code{station_col}}{Optional; the name of the column representing station identifiers.} - -\item{\code{year_col}}{Optional; the name of the column representing years.} - -\item{\code{doy_col}}{Optional; the name of the column representing day of the year.} - -\item{\code{element_cols}}{Optional; a vector of column names representing different elements.} - -\item{\code{add_to_data}}{Optional; a boolean indicating whether to add the plot to the existing data.} - -\item{\code{year_doy_plot}}{Optional; a boolean indicating whether to plot by year and day of year.} - -\item{\code{coord_flip}}{Optional; a boolean indicating whether to flip coordinates.} - -\item{\code{facet_by}}{Optional; the variable to facet the plot by.} - -\item{\code{graph_title}}{The title of the plot.} - -\item{\code{graph_subtitle}}{Optional; the subtitle of the plot.} - -\item{\code{graph_caption}}{Optional; the caption of the plot.} - -\item{\code{title_size}}{Optional; the size of the title text.} - -\item{\code{subtitle_size}}{Optional; the size of the subtitle text.} - -\item{\code{caption_size}}{Optional; the size of the caption text.} - -\item{\code{labelXAxis}}{Optional; the label for the x-axis.} - -\item{\code{labelYAxis}}{Optional; the label for the y-axis.} - -\item{\code{xSize}}{Optional; the size of the x-axis text.} - -\item{\code{ySize}}{Optional; the size of the y-axis text.} - -\item{\code{Xangle}}{Optional; the angle of the x-axis labels.} - -\item{\code{Yangle}}{Optional; the angle of the y-axis labels.} - -\item{\code{scale_xdate}}{Optional; a boolean indicating whether to scale x-axis by date.} - -\item{\code{fromXAxis}}{Optional; the starting point for the x-axis.} - -\item{\code{toXAxis}}{Optional; the ending point for the x-axis.} - -\item{\code{byXaxis}}{Optional; the interval for the x-axis.} - -\item{\code{date_ylabels}}{Optional; the labels for the y-axis dates.} - -\item{\code{legend_position}}{Optional; the position of the legend.} - -\item{\code{xlabelsize}}{Optional; the size of the x-axis label text.} - -\item{\code{ylabelsize}}{Optional; the size of the y-axis label text.} - -\item{\code{scale}}{Optional; scaling factor for the plot.} - -\item{\code{dir}}{Optional; the directory to save the plot.} - -\item{\code{row_col_number}}{The number of rows and columns for the plot layout.} - -\item{\code{nrow}}{Optional; the number of rows for the plot layout.} - -\item{\code{ncol}}{Optional; the number of columns for the plot layout.} - -\item{\code{key_colours}}{A vector of colors for the keys in the plot.} - -\item{\code{display_rain_days}}{Optional; a boolean indicating whether to display rain days.} - -\item{\code{facet_xsize}}{Optional; the size of the x-axis facets.} - -\item{\code{facet_ysize}}{Optional; the size of the y-axis facets.} - -\item{\code{facet_xangle}}{Optional; the angle of the x-axis facet labels.} - -\item{\code{facet_yangle}}{Optional; the angle of the y-axis facet labels.} - -\item{\code{scale_ydate}}{Optional; a boolean indicating whether to scale y-axis by date.} - -\item{\code{date_ybreaks}}{Optional; the breaks for y-axis dates.} - -\item{\code{step}}{Optional; the step for the y-axis.} - -\item{\code{rain_cats}}{A list defining categories for rainfall.} - -\item{\code{nc}}{The NetCDF file object.} - -\item{\code{path}}{Optional; the path to the NetCDF file.} - -\item{\code{name}}{The name for the imported data table.} - -\item{\code{only_data_vars}}{A boolean indicating whether to only include data variables.} - -\item{\code{keep_raw_time}}{A boolean indicating whether to keep raw time data.} - -\item{\code{include_metadata}}{A boolean indicating whether to include metadata.} - -\item{\code{boundary}}{Optional; the boundary for the data.} - -\item{\code{lon_points}}{Optional; specific longitude points to include.} - -\item{\code{lat_points}}{Optional; specific latitude points to include.} - -\item{\code{id_points}}{Optional; identifiers for the points to include.} - -\item{\code{show_requested_points}}{A boolean indicating whether to show requested points.} - -\item{\code{great_circle_dist}}{A boolean indicating whether to calculate great circle distances.} - -\item{\code{data_name}}{The name of the data table to process.} - -\item{\code{date_name}}{The name of the column representing dates.} - -\item{\code{factors}}{A vector of factors to use for infilling dates.} - -\item{\code{start_month}}{The starting month for date infilling.} - -\item{\code{start_date}}{The starting date for date infilling.} - -\item{\code{end_date}}{The ending date for date infilling.} - -\item{\code{resort}}{A boolean indicating whether to resort the data after infilling.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{include_overall}}{A boolean indicating whether to include overall keys.} - -\item{\code{include}}{A vector of specific keys to include.} - -\item{\code{exclude}}{A vector of specific keys to exclude.} - -\item{\code{include_empty}}{A boolean indicating whether to include empty keys.} - -\item{\code{as_list}}{A boolean indicating whether to return the keys as a list.} - -\item{\code{excluded_items}}{A vector of items to exclude from the results.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{key_name}}{The name of the key to remove.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{climdex_output}}{The output from climdex calculations.} - -\item{\code{freq}}{A string indicating the frequency of the data ('annual' or 'monthly').} - -\item{\code{station}}{The name of the station column (optional).} - -\item{\code{year}}{The name of the year column.} - -\item{\code{month}}{The name of the month column (optional for monthly frequency).} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{str}}{The string to check in the metadata.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_name}}{The name of the climatic column to retrieve.} - -\item{\code{data_name}}{The name of the existing data table.} - -\item{\code{new_data}}{The new data to be merged.} - -\item{\code{by}}{The column(s) to merge by.} - -\item{\code{type}}{The type of merge (e.g., "left", "right", "inner").} - -\item{\code{match}}{How to handle matches (e.g., "all" or "first").} - -\item{\code{query}}{The SQL query to execute.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{include_overall}}{A boolean indicating whether to include overall data.} - -\item{\code{include}}{Additional items to include.} - -\item{\code{exclude}}{Additional items to exclude.} - -\item{\code{include_empty}}{A boolean indicating whether to include empty values.} - -\item{\code{as_list}}{A boolean indicating whether to return results as a list.} - -\item{\code{excluded_items}}{A vector of items to exclude from results.} - -\item{\code{file}}{The path to the NetCDF file.} - -\item{\code{as_list}}{A boolean indicating whether to return results as a list.} - -\item{\code{dbname}}{The name of the database.} - -\item{\code{user}}{The username for database access.} - -\item{\code{host}}{The host address of the database.} - -\item{\code{port}}{The port number for database connection.} - -\item{\code{drv}}{The database driver to use (default is MySQL).} - -\item{\code{dbi_connection}}{The database connection object to set.} - -\item{\code{tableName}}{The name of the table to count rows in.} - -\item{\code{query_condition}}{An optional SQL condition to filter the rows.} - -\item{\code{import_stations}}{A boolean indicating whether to import station metadata.} - -\item{\code{import_elements}}{A boolean indicating whether to import element metadata.} - -\item{\code{import_flags}}{A boolean indicating whether to import flag metadata.} - -\item{\code{tableName}}{The name of the Climsoft observation table.} - -\item{\code{station_filter_column}}{The column name used to filter stations.} - -\item{\code{stations}}{A vector of station identifiers to filter the data.} - -\item{\code{element_filter_column}}{The column name used to filter elements.} - -\item{\code{elements}}{A vector of element identifiers to filter the data.} - -\item{\code{qc_status}}{A numeric status for quality control filtering; default is -1 (no filter).} - -\item{\code{start_date}}{Optional; start date for filtering observations.} - -\item{\code{end_date}}{Optional; end date for filtering observations.} - -\item{\code{unstack_data}}{A boolean indicating whether to unstack the data.} - -\item{\code{include_element_id}}{A boolean indicating whether to include element IDs in the output.} - -\item{\code{include_element_name}}{A boolean indicating whether to include element names in the output.} - -\item{\code{include_acquisition_type}}{A boolean indicating whether to include acquisition type in the output.} - -\item{\code{include_level}}{A boolean indicating whether to include observation level in the output.} - -\item{\code{include_entry_form}}{A boolean indicating whether to include entry form in the output.} - -\item{\code{include_captured_by}}{A boolean indicating whether to include the name of the person who captured the data.} - -\item{\code{include_qc_status}}{A boolean indicating whether to include quality control status in the output.} - -\item{\code{include_qc_log}}{A boolean indicating whether to include the quality control log in the output.} - -\item{\code{include_flag}}{A boolean indicating whether to include flags in the output.} - -\item{\code{import_selected_stations_metadata}}{A boolean indicating whether to import metadata for selected stations.} - -\item{\code{import_selected_elements_metadata}}{A boolean indicating whether to import metadata for selected elements.} - -\item{\code{download_from}}{Source to download data from.} - -\item{\code{data_file}}{Name of the data file to import.} - -\item{\code{data_frame_name}}{Name for the data frame created from the imported data.} - -\item{\code{location_data_name}}{Name for the location data frame created from the imported data.} - -\item{\code{path}}{Path to save the imported data.} - -\item{\code{X1}}{The starting coordinate for the x-axis.} - -\item{\code{X2}}{The ending coordinate for the x-axis (optional).} - -\item{\code{Y1}}{The starting coordinate for the y-axis.} - -\item{\code{Y2}}{The ending coordinate for the y-axis (optional).} - -\item{\code{get_area_point}}{Method to determine area point (default is "area").} - -\item{\code{data_names}}{Names of the data frames to export.} - -\item{\code{file}}{Destination file to save the workspace.} - -\item{\code{include_graphs}}{Whether to include graphs (default is TRUE).} - -\item{\code{include_models}}{Whether to include models (default is TRUE).} - -\item{\code{include_metadata}}{Whether to include metadata (default is TRUE).} - -\item{\code{new_links}}{A list of new links to be set.} - -\item{\code{data_name}}{Name of the data frame containing the data.} - -\item{\code{date_col}}{Column name for the date.} - -\item{\code{station_col}}{Column name for the station (optional).} - -\item{\code{year_col}}{Column name for the year (optional).} - -\item{\code{doy_col}}{Column name for the day of the year (optional).} - -\item{\code{climatic_element}}{Name of the climatic element to display (optional).} - -\item{\code{upper_limit}}{Maximum value for the graph (default is 100).} - -\item{\code{bar_colour}}{Color for the bars in the graph (default is "blue").} - -\item{\code{rug_colour}}{Color for the rug plot (default is "red").} - -\item{\code{data_name}}{Name of the data frame.} - -\item{\code{set_name}}{Name for the new variable set.} - -\item{\code{columns}}{Vector of column names to include in the set.} - -\item{\code{data_name}}{Name of the data frame.} - -\item{\code{set_name}}{Name of the variable set to update.} - -\item{\code{columns}}{Vector of new column names to include.} - -\item{\code{new_set_name}}{New name for the updated variable set.} - -\item{\code{data_name}}{Name of the data frame.} - -\item{\code{set_names}}{Vector of names of variable sets to delete.} - -\item{\code{data_name}}{Name of the data frame.} - -\item{\code{include_overall}}{Whether to include overall set (default is TRUE).} - -\item{\code{include}}{Additional filters for inclusion.} - -\item{\code{exclude}}{Exclusion filters.} - -\item{\code{include_empty}}{Whether to include empty sets (default is FALSE).} - -\item{\code{as_list}}{Whether to return as a list (default is FALSE).} - -\item{\code{excluded_items}}{Items to exclude from the results.} - -\item{\code{data_name}}{Name of the data frame.} - -\item{\code{set_names}}{Names of the variable sets to retrieve.} - -\item{\code{force_as_list}}{Whether to force the result as a list (default is FALSE).} - -\item{\code{data_name}}{Name of the data frame containing the data.} - -\item{\code{year}}{Name of the column representing the year.} - -\item{\code{station}}{Name of the column for the station (optional).} - -\item{\code{rain}}{Name of the column containing rainfall data.} - -\item{\code{day}}{Name of the column containing day data.} - -\item{\code{rain_totals}}{Column name for rain totals.} - -\item{\code{plant_days}}{Column name for planting days.} - -\item{\code{plant_lengths}}{Column name for planting lengths.} - -\item{\code{start_check}}{Boolean indicating whether to check start day (default is TRUE).} - -\item{\code{season_data_name}}{Name of the season data frame (optional).} - -\item{\code{start_day}}{Column name for the start day.} - -\item{\code{end_day}}{Column name for the end day.} - -\item{\code{definition_props}}{Boolean indicating whether to calculate properties (default is TRUE).} - -\item{\code{print_table}}{Boolean indicating whether to print the table (default is TRUE).} - -\item{\code{x}}{The input data frame containing climatic data.} - -\item{\code{format}}{A character string indicating the format of the data; must be either 'days', 'months', or 'years'.} - -\item{\code{stack_cols}}{A vector of column names to be stacked.} - -\item{\code{day}}{Optional; the name of the day column.} - -\item{\code{month}}{Optional; the name of the month column.} - -\item{\code{year}}{Optional; the name of the year column.} - -\item{\code{stack_years}}{Optional; a vector of years corresponding to the stack columns.} - -\item{\code{station}}{Optional; the name of the station column.} - -\item{\code{element}}{Optional; the name of the element column.} - -\item{\code{element_name}}{The name to assign to the value column for the climatic element.} - -\item{\code{ignore_invalid}}{A boolean indicating whether to ignore invalid dates.} - -\item{\code{silent}}{A boolean indicating whether to suppress output messages.} - -\item{\code{unstack_elements}}{A boolean indicating whether to unstack multiple elements.} - -\item{\code{new_name}}{Optional; the name to assign to the resulting tidy data frame.} - -\item{\code{data}}{The data object from which to retrieve the geometry column.} - -\item{\code{package}}{The name of the package to check.} - -\item{\code{source}}{The source from which to download data.} - -\item{\code{data}}{The specific data to download.} - -\item{\code{path}}{The directory path for saving the downloaded file.} - -\item{\code{min_lon}}{Minimum longitude for area selection.} - -\item{\code{max_lon}}{Maximum longitude for area selection.} - -\item{\code{min_lat}}{Minimum latitude for area selection.} - -\item{\code{max_lat}}{Maximum latitude for area selection.} - -\item{\code{min_date}}{Minimum date for the data.} - -\item{\code{max_date}}{Maximum date for the data.} - -\item{\code{name}}{The name to assign to the imported data.} - -\item{\code{download_type}}{The type of download (Point or Area).} - -\item{\code{import}}{Boolean indicating whether to import the downloaded data.} - -\item{\code{data_name}}{The name of the data to patch.} - -\item{\code{date_col_name}}{The name of the date column.} - -\item{\code{var}}{The variable to patch.} - -\item{\code{vars}}{A vector of variables to patch.} - -\item{\code{max_mean_bias}}{Maximum allowable mean bias for the patching.} - -\item{\code{max_stdev_bias}}{Maximum allowable standard deviation bias for the patching.} - -\item{\code{time_interval}}{The time interval for the patching (default is "month").} - -\item{\code{column_name}}{The name of the column to patch.} - -\item{\code{station_col_name}}{The name of the station column.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{element_col_name}}{The name of the column containing the element of interest.} - -\item{\code{element_col_name_imputed}}{The name of the column for imputed values of the element.} - -\item{\code{station_col_name}}{The name of the column representing the station.} - -\item{\code{x_axis_labels_col_name}}{The name of the column for x-axis labels.} - -\item{\code{ncol}}{The number of columns for visualization layout.} - -\item{\code{type}}{The type of visualization (e.g., distribution).} - -\item{\code{xlab}}{Label for the x-axis.} - -\item{\code{ylab}}{Label for the y-axis.} - -\item{\code{legend}}{Logical indicating whether to include a legend.} - -\item{\code{orientation}}{Orientation of the plot (e.g., horizontal).} - -\item{\code{interval_size}}{Size of intervals for the visualization.} - -\item{\code{x_with_truth}}{Optional truth values for comparison.} - -\item{\code{measure}}{Measurement type (e.g., percent).} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{station}}{The station of interest.} - -\item{\code{date}}{The date of interest.} - -\item{\code{elements}}{The elements to retrieve.} - -\item{\code{view_variables}}{Variables to view in the output.} - -\item{\code{station_name}}{The name of the station.} - -\item{\code{type}}{The type of data to retrieve.} - -\item{\code{start_date}}{The start date of the data range.} - -\item{\code{end_date}}{The end date of the data range.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{new_data}}{The new data to save.} - -\item{\code{rows_changed}}{The rows that have been modified.} - -\item{\code{comments_list}}{A list of comments for changes made.} - -\item{\code{add_flags}}{Logical indicating whether to add flags.} - -\item{\code{user}}{The user credentials for accessing CDS.} - -\item{\code{dataset}}{The dataset to import.} - -\item{\code{elements}}{The elements to retrieve from the dataset.} - -\item{\code{start_date}}{The starting date for the data.} - -\item{\code{end_date}}{The ending date for the data.} - -\item{\code{lon}}{Longitude for area definition.} - -\item{\code{lat}}{Latitude for area definition.} - -\item{\code{path}}{The path to save the imported data.} - -\item{\code{import}}{Logical indicating whether to import the data.} - -\item{\code{new_name}}{Optional new name for the imported data.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_names}}{The names of the columns to flag.} - -\item{\code{key_column_names}}{The names of key columns.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{which}}{The option to remove either "rows" or "cols".} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{row_index}}{The index of the row to modify.} - -\item{\code{column_index}}{The index of the column to modify.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_names}}{The names of the columns to check.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{col_name}}{The name of the column to modify.} - -\item{\code{column_data}}{The data in the column.} - -\item{\code{width}}{The width for wrapping.} - -\item{\code{wrap}}{Logical indicating whether to wrap or unwrap data.} - -\item{\code{data_name}}{The name of the data table.} - -\item{\code{x_col_names}}{The names of the columns for the independent variables.} - -\item{\code{y_col_name}}{The name of the column for the dependent variable.} - -\item{\code{signif.stars}}{Logical indicating whether to show significance stars.} - -\item{\code{sign_level}}{Logical indicating whether to show significance level.} - -\item{\code{means}}{Logical indicating whether to include means in the output.} - -\item{\code{data_name}}{A character string representing the name of the dataset.} - -\item{\code{climatic_element}}{A vector specifying the climatic elements to be displayed (e.g., temperature, rainfall).} - -\item{\code{date_col}}{The name of the column containing date information. Default is \code{date_col}.} - -\item{\code{year_col}}{The name of the column containing year information. Default is \code{year_col}.} - -\item{\code{station_col}}{The name of the column containing station information. If missing, assigns the \code{Station} column from metadata.} - -\item{\code{Misscode}}{A value representing missing data in the dataset.} - -\item{\code{Tracecode}}{A value representing trace amounts of the climatic element.} - -\item{\code{Zerocode}}{A value representing zero values for the climatic element.} - -\item{\code{monstats}}{A vector of summary statistics to calculate for monthly data. Options include \code{"min"}, \code{"mean"}, \code{"median"}, \code{"max"}, \code{"IQR"}, and \code{"sum"}.} - -\item{\code{new_comment}}{An \code{instat_comment} object to be added to the data sheet.} - -\item{\code{comment_id}}{A character string representing the ID of the comment to be deleted.} - -\item{\code{dataset}}{The SST dataset.} - -\item{\code{data_from}}{The source of the data. Default is 5.} - -\item{\code{data_names}}{A vector of data table names.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -A vector of CRI component column names. -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-standardise_country_names}{}}} -\subsection{Method \code{standardise_country_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$standardise_country_names(data_name, country_columns = c())}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-define_as_climatic}{}}} -\subsection{Method \code{define_as_climatic()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$define_as_climatic(data_name, types, key_col_names, key_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-define_corruption_outputs}{}}} -\subsection{Method \code{define_corruption_outputs()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$define_corruption_outputs(data_name, output_columns = c())}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-define_red_flags}{}}} -\subsection{Method \code{define_red_flags()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$define_red_flags(data_name, red_flags = c())}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-define_as_procurement}{}}} -\subsection{Method \code{define_as_procurement()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$define_as_procurement( - data_name, - primary_types = c(), - calculated_types = c(), - country_data_name, - country_types, - auto_generate = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-define_as_procurement_country_level_data}{}}} -\subsection{Method \code{define_as_procurement_country_level_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$define_as_procurement_country_level_data( - data_name, - contract_level_data_name, - types = c(), - auto_generate = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_CRI_component_column_names}{}}} -\subsection{Method \code{get_CRI_component_column_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_CRI_component_column_names(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_red_flag_column_names}{}}} -\subsection{Method \code{get_red_flag_column_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_red_flag_column_names(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_CRI_column_names}{}}} -\subsection{Method \code{get_CRI_column_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_CRI_column_names(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_corruption_column_name}{}}} -\subsection{Method \code{get_corruption_column_name()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_corruption_column_name(data_name, type)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-import_data}{}}} -\subsection{Method \code{import_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$import_data( - data_tables = list(), - data_tables_variables_metadata = rep(list(data.frame()), length(data_tables)), - data_tables_metadata = rep(list(list()), length(data_tables)), - data_tables_filters = rep(list(list()), length(data_tables)), - data_tables_column_selections = rep(list(list()), length(data_tables)), - imported_from = as.list(rep("", length(data_tables))), - data_names = NULL, - messages = TRUE, - convert = TRUE, - create = TRUE, - prefix = TRUE, - add_to_graph_book = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-replace_instat_object}{}}} -\subsection{Method \code{replace_instat_object()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$replace_instat_object(new_instat_object)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_data_objects}{}}} -\subsection{Method \code{set_data_objects()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_data_objects(new_data_objects)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-copy_data_object}{}}} -\subsection{Method \code{copy_data_object()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$copy_data_object( - data_name, - new_name, - filter_name = "", - column_selection_name = "", - reset_row_names = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-import_RDS}{}}} -\subsection{Method \code{import_RDS()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$import_RDS( - data_RDS, - keep_existing = TRUE, - overwrite_existing = FALSE, - include_objects = TRUE, - include_metadata = TRUE, - include_logs = TRUE, - include_filters = TRUE, - include_column_selections = TRUE, - include_calculations = TRUE, - include_comments = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-clone_data_object}{}}} -\subsection{Method \code{clone_data_object()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$clone_data_object( - curr_data_object, - include_objects = TRUE, - include_metadata = TRUE, - include_logs = TRUE, - include_filters = TRUE, - include_column_selections = TRUE, - include_calculations = TRUE, - include_comments = TRUE, - include_scalars = TRUE, - ... -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-clone_instat_calculation}{}}} -\subsection{Method \code{clone_instat_calculation()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$clone_instat_calculation(curr_instat_calculation, ...)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-import_from_ODK}{}}} -\subsection{Method \code{import_from_ODK()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$import_from_ODK(username, form_name, platform)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_meta}{}}} -\subsection{Method \code{set_meta()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_meta(new_meta)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_objects}{}}} -\subsection{Method \code{set_objects()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_objects(new_objects)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_scalars}{}}} -\subsection{Method \code{set_scalars()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_scalars(new_scalars)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-append_data_object}{}}} -\subsection{Method \code{append_data_object()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$append_data_object(name, obj, add_to_graph_book = TRUE)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_data_objects}{}}} -\subsection{Method \code{get_data_objects()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_data_objects(data_name, as_list = FALSE, ...)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_data_frame}{}}} -\subsection{Method \code{get_data_frame()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_data_frame( - data_name, - convert_to_character = FALSE, - stack_data = FALSE, - include_hidden_columns = TRUE, - use_current_filter = TRUE, - ... -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_variables_metadata}{}}} -\subsection{Method \code{get_variables_metadata()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_variables_metadata( - data_name, - data_type = "all", - convert_to_character = FALSE, - property, - column, - ... -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_column_data_types}{}}} -\subsection{Method \code{get_column_data_types()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_column_data_types(data_name, columns)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_column_labels}{}}} -\subsection{Method \code{get_column_labels()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_column_labels(data_name, columns)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_data_frame_label}{}}} -\subsection{Method \code{get_data_frame_label()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_data_frame_label(data_name, use_current_filter = FALSE)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_data_frame_metadata}{}}} -\subsection{Method \code{get_data_frame_metadata()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_data_frame_metadata( - data_name, - label, - include_calculated = TRUE, - excluded_not_for_display = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_combined_metadata}{}}} -\subsection{Method \code{get_combined_metadata()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_combined_metadata(convert_to_character = FALSE)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_metadata}{}}} -\subsection{Method \code{get_metadata()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_metadata(name, ...)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_data_names}{}}} -\subsection{Method \code{get_data_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_data_names( - as_list = FALSE, - include, - exclude, - excluded_items, - include_hidden = TRUE, - ... -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_data_changed}{}}} -\subsection{Method \code{get_data_changed()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_data_changed(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_variables_metadata_changed}{}}} -\subsection{Method \code{get_variables_metadata_changed()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_variables_metadata_changed(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_metadata_changed}{}}} -\subsection{Method \code{get_metadata_changed()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_metadata_changed(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_calculations}{}}} -\subsection{Method \code{get_calculations()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_calculations(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_calculation_names}{}}} -\subsection{Method \code{get_calculation_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_calculation_names( - data_name, - as_list = FALSE, - excluded_items = c() -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_scalars}{}}} -\subsection{Method \code{get_scalars()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_scalars(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_scalar_names}{}}} -\subsection{Method \code{get_scalar_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_scalar_names( - data_name, - as_list = FALSE, - excluded_items = c(), - ... -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_scalar_value}{}}} -\subsection{Method \code{get_scalar_value()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_scalar_value(data_name, scalar_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-add_scalar}{}}} -\subsection{Method \code{add_scalar()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$add_scalar(data_name, scalar_name = "", scalar_value)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-dataframe_count}{}}} -\subsection{Method \code{dataframe_count()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$dataframe_count()}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_data_frames_changed}{}}} -\subsection{Method \code{set_data_frames_changed()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_data_frames_changed(data_name = "", new_val)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_variables_metadata_changed}{}}} -\subsection{Method \code{set_variables_metadata_changed()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_variables_metadata_changed(data_name = "", new_val)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_metadata_changed}{}}} -\subsection{Method \code{set_metadata_changed()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_metadata_changed(data_name = "", new_val)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-add_columns_to_data}{}}} -\subsection{Method \code{add_columns_to_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$add_columns_to_data( - data_name, - col_name = "", - col_data, - use_col_name_as_prefix = FALSE, - hidden = FALSE, - before, - adjacent_column = "", - num_cols, - require_correct_length = TRUE, - keep_existing_position = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_columns_from_data}{}}} -\subsection{Method \code{get_columns_from_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_columns_from_data( - data_name, - col_names, - from_stacked_data = FALSE, - force_as_data_frame = FALSE, - use_current_filter = TRUE, - remove_labels = FALSE, - drop_unused_filter_levels = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-create_graph_data_book}{}}} -\subsection{Method \code{create_graph_data_book()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$create_graph_data_book()}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-add_object}{}}} -\subsection{Method \code{add_object()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$add_object( - data_name = NULL, - object_name = NULL, - object_type_label, - object_format, - object -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_object_names}{}}} -\subsection{Method \code{get_object_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_object_names( - data_name = NULL, - object_type_label = NULL, - as_list = FALSE, - ... -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_objects}{}}} -\subsection{Method \code{get_objects()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_objects(data_name = NULL, object_type_label = NULL)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_object}{}}} -\subsection{Method \code{get_object()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_object(data_name = NULL, object_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_object_data}{}}} -\subsection{Method \code{get_object_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_object_data(data_name = NULL, object_name, as_file = FALSE)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_objects_data}{}}} -\subsection{Method \code{get_objects_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_objects_data( - data_name = NULL, - object_names = NULL, - as_files = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_last_object_data}{}}} -\subsection{Method \code{get_last_object_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_last_object_data(object_type_label, as_file = TRUE)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-rename_object}{}}} -\subsection{Method \code{rename_object()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$rename_object( - data_name, - object_name, - new_name, - object_type = "object" -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-delete_objects}{}}} -\subsection{Method \code{delete_objects()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$delete_objects(data_name, object_names, object_type = "object")}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-reorder_objects}{}}} -\subsection{Method \code{reorder_objects()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$reorder_objects(data_name, new_order)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_from_object}{}}} -\subsection{Method \code{get_from_object()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_from_object(data_name, object_name, value1, value2, value3)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-add_filter}{}}} -\subsection{Method \code{add_filter()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$add_filter( - data_name, - filter, - filter_name = "", - replace = TRUE, - set_as_current_filter = FALSE, - na.rm = TRUE, - is_no_filter = FALSE, - and_or = "&", - inner_not = FALSE, - outer_not = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-add_filter_as_levels}{}}} -\subsection{Method \code{add_filter_as_levels()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$add_filter_as_levels(data_name, filter_levels, column)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-current_filter}{}}} -\subsection{Method \code{current_filter()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$current_filter(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_current_filter}{}}} -\subsection{Method \code{set_current_filter()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_current_filter(data_name, filter_name = "")}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_filter}{}}} -\subsection{Method \code{get_filter()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_filter(data_name, filter_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_filter_as_logical}{}}} -\subsection{Method \code{get_filter_as_logical()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_filter_as_logical(data_name, filter_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_current_filter}{}}} -\subsection{Method \code{get_current_filter()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_current_filter(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_filter_row_names}{}}} -\subsection{Method \code{get_filter_row_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_filter_row_names(data_name, filter_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_current_filter_name}{}}} -\subsection{Method \code{get_current_filter_name()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_current_filter_name(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_filter_names}{}}} -\subsection{Method \code{get_filter_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_filter_names( - data_name, - as_list = FALSE, - include = list(), - exclude = list(), - excluded_items = c() -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-remove_current_filter}{}}} -\subsection{Method \code{remove_current_filter()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$remove_current_filter(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-filter_applied}{}}} -\subsection{Method \code{filter_applied()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$filter_applied(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-filter_string}{}}} -\subsection{Method \code{filter_string()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$filter_string(data_name, filter_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_filter_as_instat_calculation}{}}} -\subsection{Method \code{get_filter_as_instat_calculation()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_filter_as_instat_calculation(data_name, filter_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-add_column_selection}{}}} -\subsection{Method \code{add_column_selection()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$add_column_selection( - data_name, - column_selection, - name = "", - replace = TRUE, - set_as_current = FALSE, - is_everything = FALSE, - and_or = "|" -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-current_column_selection}{}}} -\subsection{Method \code{current_column_selection()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$current_column_selection(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_current_column_selection}{}}} -\subsection{Method \code{set_current_column_selection()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_current_column_selection(data_name, name = "")}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_column_selection}{}}} -\subsection{Method \code{get_column_selection()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_column_selection(data_name, name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_column_selection_column_names}{}}} -\subsection{Method \code{get_column_selection_column_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_column_selection_column_names(data_name, filter_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_column_selected_column_names}{}}} -\subsection{Method \code{get_column_selected_column_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_column_selected_column_names( - data_name, - column_selection_name = "" -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_current_column_selection}{}}} -\subsection{Method \code{get_current_column_selection()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_current_column_selection(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_current_column_selection_name}{}}} -\subsection{Method \code{get_current_column_selection_name()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_current_column_selection_name(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_column_selection_names}{}}} -\subsection{Method \code{get_column_selection_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_column_selection_names( - data_name, - as_list = FALSE, - include = list(), - exclude = list(), - excluded_items = c() -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-remove_current_column_selection}{}}} -\subsection{Method \code{remove_current_column_selection()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$remove_current_column_selection(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-column_selection_applied}{}}} -\subsection{Method \code{column_selection_applied()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$column_selection_applied(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-replace_value_in_data}{}}} -\subsection{Method \code{replace_value_in_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$replace_value_in_data( - data_name, - col_names, - rows, - old_value, - old_is_missing = FALSE, - start_value = NA, - end_value = NA, - new_value, - new_is_missing = FALSE, - closed_start_value = TRUE, - closed_end_value = TRUE, - locf = FALSE, - from_last = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-paste_from_clipboard}{}}} -\subsection{Method \code{paste_from_clipboard()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$paste_from_clipboard( - data_name, - col_names, - start_row_pos = 1, - first_clip_row_is_header = TRUE, - clip_board_text -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-rename_column_in_data}{}}} -\subsection{Method \code{rename_column_in_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$rename_column_in_data( - data_name, - column_name = NULL, - new_val = NULL, - label = "", - type = "single", - .fn, - .cols = everything(), - new_column_names_df, - new_labels_df, - ... -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-frequency_tables}{}}} -\subsection{Method \code{frequency_tables()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$frequency_tables( - data_name, - x_col_names, - y_col_name, - n_column_factors = 1, - store_results = TRUE, - drop = TRUE, - na.rm = FALSE, - summary_name = NA, - include_margins = FALSE, - return_output = TRUE, - treat_columns_as_factor = FALSE, - page_by = "default", - as_html = TRUE, - signif_fig = 2, - na_display = "", - na_level_display = "NA", - weights = NULL, - caption = NULL, - result_names = NULL, - percentage_type = "none", - perc_total_columns = NULL, - perc_total_factors = c(), - perc_total_filter = NULL, - perc_decimal = FALSE, - margin_name = "(All)", - additional_filter, - ... -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-anova_tables}{}}} -\subsection{Method \code{anova_tables()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$anova_tables( - data_name, - x_col_names, - y_col_name, - signif.stars = FALSE, - sign_level = FALSE, - means = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-cor}{}}} -\subsection{Method \code{cor()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$cor( - data_name, - x_col_names, - y_col_name, - use = "everything", - method = c("pearson", "kendall", "spearman") -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-remove_columns_in_data}{}}} -\subsection{Method \code{remove_columns_in_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$remove_columns_in_data(data_name, cols, allow_delete_all = FALSE)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-remove_rows_in_data}{}}} -\subsection{Method \code{remove_rows_in_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$remove_rows_in_data(data_name, row_names)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_next_default_column_name}{}}} -\subsection{Method \code{get_next_default_column_name()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_next_default_column_name(data_name, prefix)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_column_names}{}}} -\subsection{Method \code{get_column_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_column_names( - data_name, - as_list = FALSE, - include = list(), - exclude = list(), - excluded_items = c(), - max_no, - use_current_column_selection = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-reorder_columns_in_data}{}}} -\subsection{Method \code{reorder_columns_in_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$reorder_columns_in_data(data_name, col_order)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-insert_row_in_data}{}}} -\subsection{Method \code{insert_row_in_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$insert_row_in_data( - data_name, - start_row, - row_data = c(), - number_rows = 1, - before = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_data_frame_length}{}}} -\subsection{Method \code{get_data_frame_length()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_data_frame_length(data_name, use_current_filter = FALSE)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_next_default_dataframe_name}{}}} -\subsection{Method \code{get_next_default_dataframe_name()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_next_default_dataframe_name( - prefix, - include_index = TRUE, - start_index = 1 -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-delete_dataframes}{}}} -\subsection{Method \code{delete_dataframes()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$delete_dataframes(data_names, delete_graph_book = TRUE)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-remove_link}{}}} -\subsection{Method \code{remove_link()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$remove_link(link_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_column_factor_levels}{}}} -\subsection{Method \code{get_column_factor_levels()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_column_factor_levels(data_name, col_name = "")}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_factor_data_frame}{}}} -\subsection{Method \code{get_factor_data_frame()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_factor_data_frame( - data_name, - col_name = "", - include_levels = TRUE, - include_NA_level = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-sort_dataframe}{}}} -\subsection{Method \code{sort_dataframe()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$sort_dataframe( - data_name, - col_names = c(), - decreasing = FALSE, - na.last = TRUE, - by_row_names = FALSE, - row_names_as_numeric = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-rename_dataframe}{}}} -\subsection{Method \code{rename_dataframe()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$rename_dataframe(data_name, new_value = "", label = "")}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-convert_column_to_type}{}}} -\subsection{Method \code{convert_column_to_type()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$convert_column_to_type( - data_name, - col_names = c(), - to_type, - factor_values = NULL, - set_digits, - set_decimals = FALSE, - keep_attr = TRUE, - ignore_labels = FALSE, - keep.labels = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-append_to_variables_metadata}{}}} -\subsection{Method \code{append_to_variables_metadata()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$append_to_variables_metadata( - data_name, - col_names, - property, - new_val = "" -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-append_to_dataframe_metadata}{}}} -\subsection{Method \code{append_to_dataframe_metadata()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$append_to_dataframe_metadata(data_name, property, new_val = "")}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-append_to_metadata}{}}} -\subsection{Method \code{append_to_metadata()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$append_to_metadata( - property, - new_val = "", - allow_override_special = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-add_metadata_field}{}}} -\subsection{Method \code{add_metadata_field()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$add_metadata_field(data_name, property, new_val = "")}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-reorder_dataframes}{}}} -\subsection{Method \code{reorder_dataframes()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$reorder_dataframes(data_frames_order)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-copy_columns}{}}} -\subsection{Method \code{copy_columns()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$copy_columns(data_name, col_names = "", copy_to_clipboard = FALSE)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-drop_unused_factor_levels}{}}} -\subsection{Method \code{drop_unused_factor_levels()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$drop_unused_factor_levels(data_name, col_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_factor_levels}{}}} -\subsection{Method \code{set_factor_levels()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_factor_levels( - data_name, - col_name, - new_labels, - new_levels, - set_new_labels = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-edit_factor_level}{}}} -\subsection{Method \code{edit_factor_level()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$edit_factor_level(data_name, col_name, old_level, new_level)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_factor_reference_level}{}}} -\subsection{Method \code{set_factor_reference_level()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_factor_reference_level(data_name, col_name, new_ref_level)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_column_count}{}}} -\subsection{Method \code{get_column_count()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_column_count(data_name, use_column_selection = FALSE)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-reorder_factor_levels}{}}} -\subsection{Method \code{reorder_factor_levels()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$reorder_factor_levels(data_name, col_name, new_level_names)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_data_type}{}}} -\subsection{Method \code{get_data_type()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_data_type(data_name, col_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-copy_data_frame}{}}} -\subsection{Method \code{copy_data_frame()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$copy_data_frame( - data_name, - new_name, - label = "", - copy_to_clipboard = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-copy_col_metadata_to_clipboard}{}}} -\subsection{Method \code{copy_col_metadata_to_clipboard()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$copy_col_metadata_to_clipboard(data_name, property_names)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-copy_data_frame_metadata_to_clipboard}{}}} -\subsection{Method \code{copy_data_frame_metadata_to_clipboard()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$copy_data_frame_metadata_to_clipboard(data_name, property_names)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-copy_to_clipboard}{}}} -\subsection{Method \code{copy_to_clipboard()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$copy_to_clipboard(content)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_hidden_columns}{}}} -\subsection{Method \code{set_hidden_columns()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_hidden_columns(data_name, col_names = c())}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-unhide_all_columns}{}}} -\subsection{Method \code{unhide_all_columns()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$unhide_all_columns(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_hidden_data_frames}{}}} -\subsection{Method \code{set_hidden_data_frames()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_hidden_data_frames(data_names = c())}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_hidden_data_frames}{}}} -\subsection{Method \code{get_hidden_data_frames()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_hidden_data_frames()}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_row_names}{}}} -\subsection{Method \code{set_row_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_row_names(data_name, row_names)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_row_names}{}}} -\subsection{Method \code{get_row_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_row_names(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_protected_columns}{}}} -\subsection{Method \code{set_protected_columns()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_protected_columns(data_name, col_names)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_metadata_fields}{}}} -\subsection{Method \code{get_metadata_fields()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_metadata_fields( - data_name, - include_overall, - as_list = FALSE, - include, - exclude, - excluded_items = c() -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-freeze_columns}{}}} -\subsection{Method \code{freeze_columns()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$freeze_columns(data_name, column)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-unfreeze_columns}{}}} -\subsection{Method \code{unfreeze_columns()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$unfreeze_columns(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-is_variables_metadata}{}}} -\subsection{Method \code{is_variables_metadata()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$is_variables_metadata( - data_name, - property, - column, - return_vector = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-data_frame_exists}{}}} -\subsection{Method \code{data_frame_exists()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$data_frame_exists(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-add_key}{}}} -\subsection{Method \code{add_key()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$add_key(data_name, col_names, key_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-is_key}{}}} -\subsection{Method \code{is_key()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$is_key(data_name, col_names)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-has_key}{}}} -\subsection{Method \code{has_key()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$has_key(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_keys}{}}} -\subsection{Method \code{get_keys()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_keys(data_name, key_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-add_new_comment}{}}} -\subsection{Method \code{add_new_comment()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$add_new_comment(data_name, row = "", column = "", comment)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_comments}{}}} -\subsection{Method \code{get_comments()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_comments(data_name, comment_id)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_links}{}}} -\subsection{Method \code{get_links()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_links(link_name, ...)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_structure_columns}{}}} -\subsection{Method \code{set_structure_columns()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_structure_columns( - data_name, - struc_type_1 = c(), - struc_type_2 = c(), - struc_type_3 = c() -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-add_dependent_columns}{}}} -\subsection{Method \code{add_dependent_columns()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$add_dependent_columns(data_name, columns, dependent_cols)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_column_colours}{}}} -\subsection{Method \code{set_column_colours()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_column_colours(data_name, columns, colours)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-has_colours}{}}} -\subsection{Method \code{has_colours()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$has_colours(data_name, columns)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-remove_column_colours}{}}} -\subsection{Method \code{remove_column_colours()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$remove_column_colours(data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_column_colours_by_metadata}{}}} -\subsection{Method \code{set_column_colours_by_metadata()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_column_colours_by_metadata(data_name, columns, property)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-graph_one_variable}{}}} -\subsection{Method \code{graph_one_variable()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$graph_one_variable( - data_name, - columns, - numeric = "geom_boxplot", - categorical = "geom_bar", - character = "geom_bar", - output = "facets", - free_scale_axis = FALSE, - ncol = NULL, - coord_flip = FALSE, - ... -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-make_date_yearmonthday}{}}} -\subsection{Method \code{make_date_yearmonthday()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$make_date_yearmonthday( - data_name, - year, - month, - day, - f_year, - f_month, - f_day, - year_format = "\%Y", - month_format = "\%m" -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-make_date_yeardoy}{}}} -\subsection{Method \code{make_date_yeardoy()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$make_date_yeardoy( - data_name, - year, - doy, - base, - doy_typical_length = "366" -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_contrasts_of_factor}{}}} -\subsection{Method \code{set_contrasts_of_factor()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_contrasts_of_factor( - data_name, - col_name, - new_contrasts, - defined_contr_matrix -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-create_factor_data_frame}{}}} -\subsection{Method \code{create_factor_data_frame()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$create_factor_data_frame( - data_name, - factor, - factor_data_frame_name, - include_contrasts = FALSE, - replace = FALSE, - summary_count = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-split_date}{}}} -\subsection{Method \code{split_date()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$split_date( - data_name, - col_name = "", - year_val = FALSE, - year_name = FALSE, - leap_year = FALSE, - month_val = FALSE, - month_abbr = FALSE, - month_name = FALSE, - week_val = FALSE, - week_abbr = FALSE, - week_name = FALSE, - weekday_val = FALSE, - weekday_abbr = FALSE, - weekday_name = FALSE, - day = FALSE, - day_in_month = FALSE, - day_in_year = FALSE, - day_in_year_366 = FALSE, - pentad_val = FALSE, - pentad_abbr = FALSE, - dekad_val = FALSE, - dekad_abbr = FALSE, - quarter_val = FALSE, - quarter_abbr = FALSE, - with_year = FALSE, - s_start_month = 1, - s_start_day_in_month = 1, - days_in_month = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-make_inventory_plot}{}}} -\subsection{Method \code{make_inventory_plot()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$make_inventory_plot( - data_name, - date_col, - station_col = NULL, - year_col = NULL, - doy_col = NULL, - element_cols = NULL, - add_to_data = FALSE, - year_doy_plot = FALSE, - coord_flip = FALSE, - facet_by = NULL, - graph_title = "Inventory Plot", - graph_subtitle = NULL, - graph_caption = NULL, - title_size = NULL, - subtitle_size = NULL, - caption_size = NULL, - labelXAxis, - labelYAxis, - xSize = NULL, - ySize = NULL, - Xangle = NULL, - Yangle = NULL, - scale_xdate, - fromXAxis = NULL, - toXAxis = NULL, - byXaxis = NULL, - date_ylabels, - legend_position = NULL, - xlabelsize = NULL, - ylabelsize = NULL, - scale = NULL, - dir = "", - row_col_number, - nrow = NULL, - ncol = NULL, - key_colours = c("red", "grey"), - display_rain_days = FALSE, - facet_xsize = 9, - facet_ysize = 9, - facet_xangle = 90, - facet_yangle = 90, - scale_ydate = FALSE, - date_ybreaks, - step = 1, - rain_cats = list(breaks = c(0, 0.85, Inf), labels = c("Dry", "Rain"), key_colours = - c("tan3", "blue")) -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-import_NetCDF}{}}} -\subsection{Method \code{import_NetCDF()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$import_NetCDF( - nc, - path, - name, - only_data_vars = TRUE, - keep_raw_time = TRUE, - include_metadata = TRUE, - boundary, - lon_points = NULL, - lat_points = NULL, - id_points = NULL, - show_requested_points = TRUE, - great_circle_dist = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-infill_missing_dates}{}}} -\subsection{Method \code{infill_missing_dates()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$infill_missing_dates( - data_name, - date_name, - factors, - start_month, - start_date, - end_date, - resort = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_key_names}{}}} -\subsection{Method \code{get_key_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_key_names( - data_name, - include_overall = TRUE, - include, - exclude, - include_empty = FALSE, - as_list = FALSE, - excluded_items = c() -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-remove_key}{}}} -\subsection{Method \code{remove_key()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$remove_key(data_name, key_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-add_climdex_indices}{}}} -\subsection{Method \code{add_climdex_indices()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$add_climdex_indices( - data_name, - climdex_output, - freq = "annual", - station, - year, - month -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-is_metadata}{}}} -\subsection{Method \code{is_metadata()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$is_metadata(data_name, str)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_climatic_column_name}{}}} -\subsection{Method \code{get_climatic_column_name()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_climatic_column_name(data_name, col_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-merge_data}{}}} -\subsection{Method \code{merge_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$merge_data( - data_name, - new_data, - by = NULL, - type = "left", - match = "all" -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_corruption_data_names}{}}} -\subsection{Method \code{get_corruption_data_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_corruption_data_names()}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_corruption_contract_data_names}{}}} -\subsection{Method \code{get_corruption_contract_data_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_corruption_contract_data_names()}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_database_variable_names}{}}} -\subsection{Method \code{get_database_variable_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_database_variable_names( - query, - data_name, - include_overall = TRUE, - include, - exclude, - include_empty = FALSE, - as_list = FALSE, - excluded_items = c() -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_nc_variable_names}{}}} -\subsection{Method \code{get_nc_variable_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_nc_variable_names(file = "", as_list = FALSE, ...)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-has_database_connection}{}}} -\subsection{Method \code{has_database_connection()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$has_database_connection()}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-database_connect}{}}} -\subsection{Method \code{database_connect()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$database_connect(dbname, user, host, port, drv = RMySQL::MySQL())}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_database_connection}{}}} -\subsection{Method \code{get_database_connection()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_database_connection()}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_database_connection}{}}} -\subsection{Method \code{set_database_connection()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_database_connection(dbi_connection)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-database_disconnect}{}}} -\subsection{Method \code{database_disconnect()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$database_disconnect()}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_db_table_row_count}{}}} -\subsection{Method \code{get_db_table_row_count()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_db_table_row_count(tableName, query_condition = NULL)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-import_climsoft_metadata}{}}} -\subsection{Method \code{import_climsoft_metadata()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$import_climsoft_metadata( - import_stations = FALSE, - import_elements = FALSE, - import_flags = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-import_climsoft_data}{}}} -\subsection{Method \code{import_climsoft_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$import_climsoft_data( - tableName, - station_filter_column, - stations = c(), - element_filter_column, - elements = c(), - qc_status = -1, - start_date = NULL, - end_date = NULL, - unstack_data = FALSE, - include_element_id = FALSE, - include_element_name = FALSE, - include_acquisition_type = FALSE, - include_level = FALSE, - include_entry_form = FALSE, - include_captured_by = FALSE, - include_qc_status = FALSE, - include_qc_log = FALSE, - include_flag = FALSE, - import_selected_stations_metadata = FALSE, - import_selected_elements_metadata = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-import_from_iri}{}}} -\subsection{Method \code{import_from_iri()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$import_from_iri( - download_from, - data_file, - data_frame_name, - location_data_name, - path, - X1, - X2 = NA, - Y1, - Y2 = NA, - get_area_point = "area" -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-export_workspace}{}}} -\subsection{Method \code{export_workspace()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$export_workspace( - data_names, - file, - include_graphs = TRUE, - include_models = TRUE, - include_metadata = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-set_links}{}}} -\subsection{Method \code{set_links()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$set_links(new_links)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-display_daily_graph}{}}} -\subsection{Method \code{display_daily_graph()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$display_daily_graph( - data_name, - date_col = NULL, - station_col = NULL, - year_col = NULL, - doy_col = NULL, - climatic_element = NULL, - upper_limit = 100, - bar_colour = "blue", - rug_colour = "red" -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-create_variable_set}{}}} -\subsection{Method \code{create_variable_set()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$create_variable_set(data_name, set_name, columns)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-update_variable_set}{}}} -\subsection{Method \code{update_variable_set()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$update_variable_set(data_name, set_name, columns, new_set_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-delete_variable_sets}{}}} -\subsection{Method \code{delete_variable_sets()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$delete_variable_sets(data_name, set_names)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_variable_sets_names}{}}} -\subsection{Method \code{get_variable_sets_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_variable_sets_names( - data_name, - include_overall = TRUE, - include, - exclude, - include_empty = FALSE, - as_list = FALSE, - excluded_items = c() -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_variable_sets}{}}} -\subsection{Method \code{get_variable_sets()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_variable_sets(data_name, set_names, force_as_list = FALSE)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-crops_definitions}{}}} -\subsection{Method \code{crops_definitions()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$crops_definitions( - data_name, - year, - station, - rain, - day, - rain_totals, - plant_days, - plant_lengths, - start_check = TRUE, - season_data_name, - start_day, - end_day, - definition_props = TRUE, - print_table = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-tidy_climatic_data}{}}} -\subsection{Method \code{tidy_climatic_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$tidy_climatic_data( - x, - format, - stack_cols, - day, - month, - year, - stack_years, - station, - element, - element_name = "value", - ignore_invalid = FALSE, - silent = FALSE, - unstack_elements = TRUE, - new_name -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_geometry}{}}} -\subsection{Method \code{get_geometry()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_geometry(data)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-package_check}{}}} -\subsection{Method \code{package_check()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$package_check(package)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-download_from_IRI}{}}} -\subsection{Method \code{download_from_IRI()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$download_from_IRI( - source, - data, - path = tempdir(), - min_lon, - max_lon, - min_lat, - max_lat, - min_date, - max_date, - name, - download_type = "Point", - import = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-patch_climate_element}{}}} -\subsection{Method \code{patch_climate_element()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$patch_climate_element( - data_name, - date_col_name = "", - var = "", - vars = c(), - max_mean_bias = NA, - max_stdev_bias = NA, - time_interval = "month", - column_name, - station_col_name = station_col_name -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-visualize_element_na}{}}} -\subsection{Method \code{visualize_element_na()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$visualize_element_na( - data_name, - element_col_name, - element_col_name_imputed, - station_col_name, - x_axis_labels_col_name, - ncol = 2, - type = "distribution", - xlab = NULL, - ylab = NULL, - legend = TRUE, - orientation = "horizontal", - interval_size = interval_size, - x_with_truth = NULL, - measure = "percent" -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_data_entry_data}{}}} -\subsection{Method \code{get_data_entry_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_data_entry_data( - data_name, - station, - date, - elements, - view_variables, - station_name, - type, - start_date, - end_date -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-save_data_entry_data}{}}} -\subsection{Method \code{save_data_entry_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$save_data_entry_data( - data_name, - new_data, - rows_changed, - comments_list = list(), - add_flags = FALSE, - ... -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-import_from_cds}{}}} -\subsection{Method \code{import_from_cds()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$import_from_cds( - user, - dataset, - elements, - start_date, - end_date, - lon, - lat, - path, - import = FALSE, - new_name -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-add_flag_fields}{}}} -\subsection{Method \code{add_flag_fields()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$add_flag_fields(data_name, col_names, key_column_names)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-remove_empty}{}}} -\subsection{Method \code{remove_empty()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$remove_empty(data_name, which = c("rows", "cols"))}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-replace_values_with_NA}{}}} -\subsection{Method \code{replace_values_with_NA()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$replace_values_with_NA(data_name, row_index, column_index)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-has_labels}{}}} -\subsection{Method \code{has_labels()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$has_labels(data_name, col_names)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-wrap_or_unwrap_data}{}}} -\subsection{Method \code{wrap_or_unwrap_data()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$wrap_or_unwrap_data( - data_name, - col_name, - column_data, - width, - wrap = TRUE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-anova_tables2}{}}} -\subsection{Method \code{anova_tables2()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$anova_tables2( - data_name, - x_col_names, - y_col_name, - signif.stars = FALSE, - sign_level = FALSE, - means = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-define_as_options_by_context}{}}} -\subsection{Method \code{define_as_options_by_context()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$define_as_options_by_context( - data_name, - obyc_types = NULL, - key_columns = NULL -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-update_links_rename_data_frame}{}}} -\subsection{Method \code{update_links_rename_data_frame()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$update_links_rename_data_frame(old_data_name, new_data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-update_links_rename_column}{}}} -\subsection{Method \code{update_links_rename_column()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$update_links_rename_column( - data_name, - old_column_name, - new_column_name -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-add_link}{}}} -\subsection{Method \code{add_link()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$add_link(from_data_frame, to_data_frame, link_pairs, type, link_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_link_names}{}}} -\subsection{Method \code{get_link_names()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_link_names( - data_name, - include_overall = TRUE, - include, - exclude, - include_empty = FALSE, - as_list = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-link_exists_from}{}}} -\subsection{Method \code{link_exists_from()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$link_exists_from(curr_data_frame, link_pairs)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-link_exists_between}{}}} -\subsection{Method \code{link_exists_between()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$link_exists_between(from_data_frame, to_data_frame, ordered = FALSE)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_link_between}{}}} -\subsection{Method \code{get_link_between()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_link_between(from_data_frame, to_data_frame, ordered = FALSE)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-link_exists_from_by_to}{}}} -\subsection{Method \code{link_exists_from_by_to()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$link_exists_from_by_to( - first_data_frame, - link_pairs, - second_data_frame -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_linked_to_data_name}{}}} -\subsection{Method \code{get_linked_to_data_name()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_linked_to_data_name( - from_data_frame, - link_cols = c(), - include_self = FALSE -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_linked_to_definition}{}}} -\subsection{Method \code{get_linked_to_definition()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_linked_to_definition(from_data_frame, link_pairs)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_possible_linked_to_definition}{}}} -\subsection{Method \code{get_possible_linked_to_definition()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_possible_linked_to_definition(from_data_frame, link_pairs)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-get_equivalent_columns}{}}} -\subsection{Method \code{get_equivalent_columns()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$get_equivalent_columns(from_data_name, columns, to_data_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-link_between_containing}{}}} -\subsection{Method \code{link_between_containing()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$link_between_containing( - from_data_frame, - containing_columns, - to_data_frame -)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-view_link}{}}} -\subsection{Method \code{view_link()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$view_link(link_name)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-import_SST}{}}} -\subsection{Method \code{import_SST()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$import_SST(dataset, data_from = 5, data_names = c())}\if{html}{\out{
}} -} +\item{\code{copy_col_metadata_to_clipboard(data_name, property_names)}}{Copies the specified column metadata properties from the given data table to the clipboard.} +\item{\code{copy_data_frame_metadata_to_clipboard(data_name, property_names)}}{Copies the specified data frame metadata properties from the given data table to the clipboard.} +\item{\code{copy_to_clipboard(content)}}{Copies the given content to the clipboard.} +\item{\code{set_hidden_columns(data_name, col_names = c())}}{Sets the specified columns in the given data table to be hidden.} +\item{\code{unhide_all_columns(data_name)}}{Unhides all columns in the specified data table.} +\item{\code{set_hidden_data_frames(data_names = c())}}{Sets the specified data frames to be hidden.} +\item{\code{get_hidden_data_frames()}}{Returns the names of all hidden data frames.} +\item{\code{set_row_names(data_name, row_names)}}{Sets new row names for the specified data table.} +\item{\code{get_row_names(data_name)}}{Returns the row names of the specified data table.} +\item{\code{set_protected_columns(data_name, col_names)}}{Sets the specified columns in the given data table to be protected.} +\item{\code{get_metadata_fields(data_name, include_overall, as_list = FALSE, include, exclude, excluded_items = c())}}{Returns the metadata fields for the specified data table and overall metadata, with options to include or exclude specific fields.} +\item{\code{freeze_columns(data_name, column)}}{Freezes the specified columns in the given data table.} +\item{\code{unfreeze_columns(data_name)}}{Unfreezes all columns in the specified data table.} +\item{\code{is_variables_metadata(data_name, property, column, return_vector = FALSE)}}{Checks if the specified property is part of the variables metadata for the given column in the specified data table.} +\item{\code{data_frame_exists(data_name)}}{Checks if the specified data table exists in the object.} +\item{\code{add_key(data_name, col_names, key_name)}}{Adds a key to the specified data table using the given columns and key name.} +\item{\code{is_key(data_name, col_names)}}{Checks if the specified columns form a key in the given data table.} +\item{\code{has_key(data_name)}}{Checks if the specified data table has a key.} +\item{\code{get_keys(data_name, key_name)}}{Returns the keys for the specified data table and key name.} +\item{\code{add_new_comment(data_name, row = "", column = "", comment)}}{Adds a new comment to the specified data table, optionally specifying the row and column.} +\item{\code{get_comments(data_name, comment_id)}}{Returns the comments for the specified data table and comment ID.} +\item{\code{get_links(link_name, ...)}}{Returns the links for the specified link name or all links if no name is provided.} +\item{\code{set_structure_columns(data_name, struc_type_1 = c(), struc_type_2 = c(), struc_type_3 = c())}}{Sets the structure columns for the specified data table.} +\item{\code{add_dependent_columns(data_name, columns, dependent_cols)}}{Adds dependent columns to the specified columns in the given data table.} +\item{\code{set_column_colours(data_name, columns, colours)}}{Sets the colors for the specified columns in the given data table.} +\item{\code{has_colours(data_name, columns)}}{Checks if the specified columns in the given data table have colors.} +\item{\code{remove_column_colours(data_name)}}{Removes colors from all columns in the specified data table.} +\item{\code{set_column_colours_by_metadata(data_name, columns, property)}}{Sets the colors for the specified columns in the given data table based on the specified metadata property.} +\item{\code{graph_one_variable(data_name, columns, numeric = "geom_boxplot", categorical = "geom_bar", character = "geom_bar", output = "facets", free_scale_axis = FALSE, ncol = NULL, coord_flip = FALSE, ... = ...)}}{Creates a graph for one variable in the specified data table with options for the type of graph, axis scaling, and other parameters.} +\item{\code{make_date_yearmonthday(data_name, year, month, day, f_year, f_month, f_day, year_format = "\%Y", month_format = "\%m")}}{Creates a date column from the specified year, month, and day columns in the given data table, with options for formatting.} +\item{\code{make_date_yeardoy(data_name, year, doy, base, doy_typical_length = "366")}}{Creates a date column from the specified year and day of year columns in the given data table.} +\item{\code{set_contrasts_of_factor(data_name, col_name, new_contrasts, defined_contr_matrix)}}{Sets the contrasts for the specified factor column in the given data table.} +\item{\code{create_factor_data_frame(data_name, factor, factor_data_frame_name, include_contrasts = FALSE, replace = FALSE, summary_count = TRUE)}}{Creates a new data frame for the specified factor column in the given data table, with options to include contrasts and summary counts.} +\item{\code{split_date(data_name, col_name = "", year_val = FALSE, year_name = FALSE, leap_year = FALSE, month_val = FALSE, month_abbr = FALSE, month_name = FALSE, week_val = FALSE, week_abbr = FALSE, week_name = FALSE, weekday_val = FALSE, weekday_abbr = FALSE, weekday_name = FALSE, day = FALSE, day_in_month = FALSE, day_in_year = FALSE, day_in_year_366 = FALSE, pentad_val = FALSE, pentad_abbr = FALSE, dekad_val = FALSE, dekad_abbr = FALSE, quarter_val = FALSE, quarter_abbr = FALSE, with_year = FALSE, s_start_month = 1, s_start_day_in_month = 1, days_in_month = FALSE)}}{Splits the specified date column into multiple components such as year, month, day, etc. in the given data table.} +\item{\code{import_SST(dataset, data_from = 5, data_names = c())}}{Imports SST data from the specified dataset and data source, creating data tables with the specified names.} +\item{\code{make_inventory_plot(data_name, date_col, station_col = NULL, year_col = NULL, doy_col = NULL, element_cols = NULL, add_to_data = FALSE, year_doy_plot = FALSE, coord_flip = FALSE, facet_by = NULL, graph_title = "Inventory Plot", graph_subtitle = NULL, graph_caption = NULL, title_size = NULL, subtitle_size = NULL, caption_size = NULL, labelXAxis, labelYAxis, xSize = NULL, ySize = NULL, Xangle = NULL, Yangle = NULL, scale_xdate, fromXAxis = NULL, toXAxis = NULL, byXaxis = NULL, date_ylabels, legend_position = NULL, xlabelsize = NULL, ylabelsize = NULL, scale = NULL, dir = "", row_col_number, nrow = NULL, ncol = NULL, key_colours = c("red", "grey"), display_rain_days = FALSE, facet_xsize = 9, facet_ysize = 9, facet_xangle = 90, facet_yangle = 90, scale_ydate = FALSE, date_ybreaks, step = 1, rain_cats = list(breaks = c(0, 0.85, Inf), labels = c("Dry", "Rain"), key_colours = c("tan3", "blue")))}}{Creates an inventory plot for the specified data table with various customisation options.} +\item{\code{import_NetCDF(nc, path, name, only_data_vars = TRUE, keep_raw_time = TRUE, include_metadata = TRUE, boundary, lon_points = NULL, lat_points = NULL, id_points = NULL, show_requested_points = TRUE, great_circle_dist = FALSE)}}{Imports data from a NetCDF file, with options to specify the data variables, time format, metadata inclusion, and boundaries.} +\item{\code{infill_missing_dates(data_name, date_name, factors, start_month, start_date, end_date, resort = TRUE)}}{Infills missing dates in the specified data table using the provided date column and factors.} +\item{\code{get_key_names(data_name, include_overall = TRUE, include, exclude, include_empty = FALSE, as_list = FALSE, excluded_items = c())}}{Returns the key names for the specified data table, with options to include overall keys, exclude specific keys, and return as a list.} +\item{\code{remove_key(data_name, key_name)}}{Removes the specified key from the given data table.} +\item{\code{add_climdex_indices(data_name, climdex_output, freq = "annual", station, year, month)}}{Adds climdex indices to the specified data table, with options for frequency, station, year, and month.} +\item{\code{is_metadata(data_name, str)}}{Checks if the specified string is part of the metadata for the given data table.} +\item{\code{get_climatic_column_name(data_name, col_name)}}{Returns the climatic column name for the specified column in the given data table.} +\item{\code{merge_data(data_name, new_data, by = NULL, type = "left", match = "all")}}{Merges new data into the specified data table using the provided columns and merge type.} +\item{\code{get_corruption_data_names()}}{Returns the names of all data tables with corruption data.} +\item{\code{get_corruption_contract_data_names()}}{Returns the names of all data tables with corruption contract data.} +\item{\code{get_database_variable_names(query, data_name, include_overall = TRUE, include, exclude, include_empty = FALSE, as_list = FALSE, excluded_items = c())}}{Returns the database variable names for the specified query and data table, with options to include overall variables, exclude specific variables, and return as a list.} +\item{\code{get_nc_variable_names(file = "", as_list = FALSE, ...)}}{Returns the variable names from the specified NetCDF file, with an option to return as a list.} +\item{\code{has_database_connection()}}{Checks if there is a database connection.} +\item{\code{database_connect(dbname, user, host, port, drv = RMySQL::MySQL())}}{Connects to a database using the provided credentials and driver.} +\item{\code{get_database_connection()}}{Returns the current database connection.} +\item{\code{set_database_connection(dbi_connection)}}{Sets the database connection to the specified DBI connection object.} +\item{\code{database_disconnect()}}{Disconnects from the current database.} +\item{\code{import_from_climsoft(stationfiltercolumn = "stationId", stations = c(), elementfiltercolumn = "elementId", elements = c(), include_observation_data = FALSE, include_observation_flags = FALSE, unstack_data = FALSE, include_elements_info = FALSE, start_date = NULL, end_date = NULL)}}{Imports data from CLIMSOFT using the specified filters and options for observation data, flags, and unstacking.} +\item{\code{import_from_iri(download_from, data_file, data_frame_name, location_data_name, path, X1, X2 = NA, Y1, Y2 = NA, get_area_point = "area")}}{Imports data from IRI using the specified parameters for download, file path, coordinates, and area type.} +\item{\code{export_workspace(data_names, file, include_graphs = TRUE, include_models = TRUE, include_metadata = TRUE)}}{Exports the workspace to a file, including the specified data tables, graphs, models, and metadata.} +\item{\code{set_links(new_links)}}{Sets the links in the object to the specified new links.} +\item{\code{display_daily_graph(data_name, date_col = NULL, station_col = NULL, year_col = NULL, doy_col = NULL, climatic_element = NULL, upper_limit = 100, bar_colour = "blue", rug_colour = "red")}}{Displays a daily graph for the specified data table with options for columns, element, colors, and limits.} +\item{\code{create_variable_set(data_name, set_name, columns)}}{Creates a variable set with the specified name and columns in the given data table.} +\item{\code{update_variable_set(data_name, set_name, columns, new_set_name)}}{Updates the specified variable set with new columns and optionally a new name in the given data table.} +\item{\code{delete_variable_sets(data_name, set_names)}}{Deletes the specified variable sets from the given data table.} +\item{\code{get_variable_sets_names(data_name, include_overall = TRUE, include, exclude, include_empty = FALSE, as_list = FALSE, excluded_items = c())}}{Returns the names of variable sets for the specified data table, with options to include overall sets, exclude specific sets, and return as a list.} +\item{\code{get_variable_sets(data_name, set_names, force_as_list = FALSE)}}{Returns the specified variable sets from the given data table, with an option to force the result as a list.} +\item{\code{crops_definitions(data_name, year, station, rain, day, rain_totals, plant_days, plant_lengths, start_check = TRUE, season_data_name, start_day, end_day, definition_props = TRUE, print_table = TRUE)}}{Defines crop parameters for the specified data table using the provided columns and options for seasons, days, and properties.} +\item{\code{tidy_climatic_data(x, format, stack_cols, day, month, year, stack_years, station, element, element_name="value", ignore_invalid = FALSE, silent = FALSE, unstack_elements = TRUE, new_name)}}{Converts wide-format daily climatic data to long format using the specified columns and options for format, elements, and validation.} +\item{\code{get_geometry(data)}}{Returns the geometry column for the specified data table.} +\item{\code{package_check(package)}}{Checks if the specified package is installed and returns information about its version and availability.} +\item{\code{download_from_IRI(source, data, path = tempdir(), min_lon, max_lon, min_lat, max_lat, min_date, max_date, name, download_type = "Point", import = TRUE)}}{Downloads data from IRI using the specified source, data, coordinates, date range, and options for download type and import.} +\item{\code{patch_climate_element(data_name, date_col_name = "", var = "", vars = c(), max_mean_bias = NA, max_stdev_bias = NA, time_interval = "month", column_name, station_col_name = station_col_name)}}{Patches the specified climate element in the given data table using the provided columns and options for bias, time interval, and station.} +\item{\code{visualize_element_na(data_name, element_col_name, element_col_name_imputed, station_col_name, x_axis_labels_col_name, ncol = 2, type = "distribution", xlab = NULL, ylab = NULL, legend = TRUE, orientation = "horizontal", interval_size = interval_size, x_with_truth = NULL, measure = "percent")}}{Visualizes missing data for the specified element in the given data table using the provided columns and options for labels, legend, orientation, and measure.} +\item{\code{get_data_entry_data(data_name, station, date, elements, view_variables, station_name, type, start_date, end_date)}}{Returns data entry data for the specified data table using the provided columns and options for date range, variables, and type.} +\item{\code{save_data_entry_data(data_name, new_data, rows_changed, comments_list = list(), add_flags = FALSE, ...)}}{Saves data entry data to the specified data table with options for adding comments, flags, and rows changed.} +\item{\code{import_from_cds(user, dataset, elements, start_date, end_date, lon, lat, path, import = FALSE, new_name)}}{Imports data from CDS using the specified user, dataset, elements, date range, coordinates, and options for file path and import.} +\item{\code{add_flag_fields(data_name, col_names, key_column_names)}}{Adds flag fields to the specified columns in the given data table, using the provided key columns.} +\item{\code{remove_empty(data_name, which = c("rows","cols"))}}{Removes empty rows or columns from the specified data table.} +\item{\code{replace_values_with_NA(data_name, row_index, column_index)}}{Replaces values with NA in the specified rows and columns of the given data table.} +\item{\code{has_labels(data_name, col_names)}}{Checks if the specified columns in the given data table have labels.} +\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.} +\item{\code{add_comment(new_comment)}}{Adds a new \code{instat_comment} object to the data sheet if the key is defined and valid.} +\item{\code{delete_comment(comment_id)}}{Deletes a comment from the data sheet based on the comment ID.} +\item{\code{get_comment_ids()}}{Retrieves all comment IDs currently stored in the data sheet.} +\item{\code{get_comments_as_data_frame()}}{Converts all comments in the data sheet to a data frame format for easier inspection and analysis.} +\item{\code{update_links_rename_data_frame(old_data_name, new_data_name)}}{This function updates all links that reference a data frame with a specified old name, renaming it to a new name.} +\item{\code{update_links_rename_column(data_name, old_column_name, new_column_name)}}{This function updates all links referencing a column in a data frame with a specified old column name, renaming it to a new column name.} +\item{\code{add_link(from_data_frame, to_data_frame, link_pairs, type, link_name)}}{This function adds a new link between two data frames with the specified link pairs and type. It will check if the link already exists or if the link columns are keys.} +\item{\code{get_link_names(data_name, include_overall = TRUE, include, exclude, include_empty = FALSE, as_list = FALSE)}}{Retrieves the names of all links involving a specified data frame, with options to include or exclude specific types.} +\item{\code{link_exists_from(curr_data_frame, link_pairs)}}{Verifies if a link exists from a specific data frame with given link pairs.} +\item{\code{link_exists_between(from_data_frame, to_data_frame, ordered = FALSE)}}{This function checks if there is an ordered or unordered link between two specified data frames.} +\item{\code{get_link_between(from_data_frame, to_data_frame, ordered = FALSE)}}{Retrieves the link definition between two specified data frames.} +\item{\code{link_exists_from_by_to(first_data_frame, link_pairs, second_data_frame)}}{This function checks if a link exists from \code{first_data_frame} to \code{second_data_frame} using the specified \code{link_pairs} columns.} +\item{\code{get_linked_to_data_name(from_data_frame, link_cols = c(), include_self = FALSE)}}{This function returns the names of data frames linked to \code{from_data_frame}. Optionally, includes \code{from_data_frame} itself in the output if \code{include_self} is TRUE. Filters results by \code{link_cols}, if provided.} +\item{\code{get_linked_to_definition(from_data_frame, link_pairs)}}{This function returns a list of the target data frame and matched columns.} +\item{\code{get_possible_linked_to_definition(from_data_frame, link_pairs)}}{This function attempts to find a linked data frame that matches \code{link_pairs}. Recursively explores links between multiple data frames.} +\item{\code{get_equivalent_columns(from_data_name, columns, to_data_name)}}{This function returns columns in \code{to_data_name} equivalent to \code{columns} in \code{from_data_name}. Recursively searches links between multiple data frames.} +\item{\code{link_between_containing(from_data_frame, containing_columns, to_data_frame)}}{This function returns columns in \code{to_data_frame} corresponding to \code{containing_columns} in \code{from_data_frame} if a link exists between them.} +\item{\code{view_link(link_name)}}{Displays the details of a specified link.} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-DataBook-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{DataBook$clone(deep = FALSE)}\if{html}{\out{
}} +@export +Initialise for Public List } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} -} \section{Active bindings}{ \if{html}{\out{
}} \describe{ @@ -6026,6 +453,11 @@ The objects of this class are cloneable with this method. \item \href{#method-DataBook-has_labels}{\code{DataBook$has_labels()}} \item \href{#method-DataBook-wrap_or_unwrap_data}{\code{DataBook$wrap_or_unwrap_data()}} \item \href{#method-DataBook-anova_tables2}{\code{DataBook$anova_tables2()}} +\item \href{#method-DataBook-display_daily_table}{\code{DataBook$display_daily_table()}} +\item \href{#method-DataBook-add_comment}{\code{DataBook$add_comment()}} +\item \href{#method-DataBook-delete_comment}{\code{DataBook$delete_comment()}} +\item \href{#method-DataBook-get_comment_ids}{\code{DataBook$get_comment_ids()}} +\item \href{#method-DataBook-get_comments_as_data_frame}{\code{DataBook$get_comments_as_data_frame()}} \item \href{#method-DataBook-define_as_options_by_context}{\code{DataBook$define_as_options_by_context()}} \item \href{#method-DataBook-update_links_rename_data_frame}{\code{DataBook$update_links_rename_data_frame()}} \item \href{#method-DataBook-update_links_rename_column}{\code{DataBook$update_links_rename_column()}} @@ -8720,7 +3152,8 @@ Convert specified columns to a different type. \item{\code{ignore_labels}}{A boolean indicating whether to ignore labels.} -\item{\code{keep.labels}}{A boolean indicating whether to keep labels.} +\item{\code{keep.labels}}{A boolean indicating whether to keep labels. +Append Property to Variables Metadata} } \if{html}{\out{
}} } @@ -8754,6 +3187,7 @@ Appends a new property and its value to the metadata of specified columns in a d } \subsection{Returns}{ None +Append Property to Dataframe Metadata } } \if{html}{\out{
}} @@ -8778,6 +3212,7 @@ Appends a new property and its value to the metadata of a data table. } \subsection{Returns}{ None +Append Property to Metadata } } \if{html}{\out{
}} @@ -8806,6 +3241,7 @@ Appends a new property and its value to the metadata of the current object. } \subsection{Returns}{ None +Add Metadata Field } } \if{html}{\out{
}} @@ -8830,6 +3266,7 @@ Adds a new metadata field and its value to the specified data table or all data } \subsection{Returns}{ None +Reorder Dataframes } } \if{html}{\out{
}} @@ -8850,6 +3287,7 @@ Reorders the dataframes in the object according to the specified order. } \subsection{Returns}{ None +Copy Columns } } \if{html}{\out{
}} @@ -8874,6 +3312,7 @@ Copies specified columns from a data table to another location or clipboard. } \subsection{Returns}{ None +Drop Unused Factor Levels } } \if{html}{\out{
}} @@ -8896,6 +3335,7 @@ Drops unused levels from a factor column in the specified data table. } \subsection{Returns}{ None +Set Factor Levels } } \if{html}{\out{
}} @@ -8930,6 +3370,7 @@ Sets new levels for a factor column in the specified data table. } \subsection{Returns}{ None +Edit Factor Level } } \if{html}{\out{
}} @@ -8956,6 +3397,7 @@ Edits a level in a factor column in the specified data table. } \subsection{Returns}{ None +Set Factor Reference Level } } \if{html}{\out{
}} @@ -8980,6 +3422,7 @@ Sets the reference level for a factor column in the specified data table. } \subsection{Returns}{ None +Get Column Count } } \if{html}{\out{
}} @@ -9002,6 +3445,7 @@ Returns the number of columns in the specified data table. } \subsection{Returns}{ The number of columns. +Reorder Factor Levels } } \if{html}{\out{
}} @@ -9026,6 +3470,7 @@ Reorders the levels of a factor column in the specified data table. } \subsection{Returns}{ None +Get Data Type } } \if{html}{\out{
}} @@ -9048,6 +3493,7 @@ Returns the data type of the specified column in the given data table. } \subsection{Returns}{ The data type of the column. +Copy Data Frame } } \if{html}{\out{
}} @@ -9079,6 +3525,7 @@ Copies a data frame to a new name or clipboard. } \subsection{Returns}{ None +Copy Column Metadata to Clipboard } } \if{html}{\out{
}} @@ -9101,6 +3548,7 @@ Copies the metadata of specified columns to the clipboard. } \subsection{Returns}{ None +Copy Data Frame Metadata to Clipboard } } \if{html}{\out{
}} @@ -9123,6 +3571,7 @@ Copies the metadata of the specified data table to the clipboard. } \subsection{Returns}{ None +Copy to Clipboard } } \if{html}{\out{
}} @@ -9143,6 +3592,7 @@ Copies the specified content to the clipboard. } \subsection{Returns}{ None +Set Hidden Columns } } \if{html}{\out{
}} @@ -9165,6 +3615,7 @@ Sets the specified columns as hidden in the given data table. } \subsection{Returns}{ None +Unhide All Columns } } \if{html}{\out{
}} @@ -9185,6 +3636,7 @@ Unhides all columns in the specified data table or all data tables if data_name } \subsection{Returns}{ None +Set Hidden Data Frames } } \if{html}{\out{
}} @@ -9205,6 +3657,7 @@ Sets the specified data tables as hidden. } \subsection{Returns}{ None +Get Hidden Data Frames } } \if{html}{\out{
}} @@ -9218,6 +3671,7 @@ Returns a list of hidden data tables. \subsection{Returns}{ A vector of hidden data table names. +Set Row Names } } \if{html}{\out{
}} @@ -9240,6 +3694,7 @@ Sets the row names for the specified data table. } \subsection{Returns}{ None +Get Row Names } } \if{html}{\out{
}} @@ -9260,6 +3715,7 @@ Returns the row names of the specified data table. } \subsection{Returns}{ A vector of row names. +Set Protected Columns } } \if{html}{\out{
}} @@ -9282,6 +3738,7 @@ Sets the specified columns as protected in the given data table. } \subsection{Returns}{ None +Get Metadata Fields } } \if{html}{\out{
}} @@ -9319,6 +3776,7 @@ Returns the metadata fields of the specified data table. } \subsection{Returns}{ A vector or list of metadata fields. +Freeze Columns } } \if{html}{\out{
}} @@ -9341,6 +3799,7 @@ Freezes the specified columns in the given data table. } \subsection{Returns}{ None +Unfreeze Columns } } \if{html}{\out{
}} @@ -9361,6 +3820,7 @@ Unfreezes all columns in the specified data table. } \subsection{Returns}{ None +Is Variables Metadata } } \if{html}{\out{
}} @@ -9392,6 +3852,7 @@ Checks if the specified property is metadata for the given columns in the data t } \subsection{Returns}{ A boolean value indicating if the property is metadata for the columns. +Data Frame Exists } } \if{html}{\out{
}} @@ -9412,6 +3873,7 @@ Checks if the specified data table exists. } \subsection{Returns}{ A boolean value indicating if the data table exists. +Add Key } } \if{html}{\out{
}} @@ -9436,6 +3898,7 @@ Adds a key to the specified columns in the given data table. } \subsection{Returns}{ None +Is Key } } \if{html}{\out{
}} @@ -9458,6 +3921,7 @@ Checks if the specified columns are keys in the given data table. } \subsection{Returns}{ A boolean value indicating if the columns are keys. +Has Key } } \if{html}{\out{
}} @@ -9478,6 +3942,7 @@ Checks if the specified data table has a key. } \subsection{Returns}{ A boolean value indicating if the data table has a key. +Get Keys } } \if{html}{\out{
}} @@ -9500,6 +3965,7 @@ Returns the keys of the specified data table. } \subsection{Returns}{ A list of keys. +Add New Comment } } \if{html}{\out{
}} @@ -9526,6 +3992,7 @@ Adds a new comment to the specified row and column in the given data table. } \subsection{Returns}{ None +Get Comments } } \if{html}{\out{
}} @@ -9548,6 +4015,7 @@ Returns the comments for the specified data table and comment ID. } \subsection{Returns}{ A data frame of comments. +Get Links } } \if{html}{\out{
}} @@ -9568,6 +4036,7 @@ Returns the links for the specified link name or all links. } \subsection{Returns}{ A list of links. +Set Structure Columns } } \if{html}{\out{
}} @@ -9599,6 +4068,7 @@ Sets the structure columns for the specified data table. } \subsection{Returns}{ None +Add Dependent Columns } } \if{html}{\out{
}} @@ -9623,6 +4093,7 @@ Adds dependent columns to the specified columns in the given data table. } \subsection{Returns}{ None +Set Column Colours } } \if{html}{\out{
}} @@ -9647,6 +4118,7 @@ Sets the colours for the specified columns in the given data table. } \subsection{Returns}{ None +Has Colours } } \if{html}{\out{
}} @@ -9669,6 +4141,7 @@ Checks if the specified columns have colours in the given data table. } \subsection{Returns}{ A boolean value indicating if the columns have colours. +Remove Column Colours } } \if{html}{\out{
}} @@ -9689,6 +4162,7 @@ Removes the colours from all columns in the specified data table. } \subsection{Returns}{ None +Set Column Colours by Metadata } } \if{html}{\out{
}} @@ -9713,6 +4187,7 @@ Sets the colours for the specified columns based on metadata in the given data t } \subsection{Returns}{ None +Graph One Variable } } \if{html}{\out{
}} @@ -9762,6 +4237,7 @@ Creates a graph for a single variable in the specified data table. } \subsection{Returns}{ None +Make Date YearMonthDay } } \if{html}{\out{
}} @@ -9808,6 +4284,7 @@ Creates a date column from year, month, and day columns in the specified data ta } \subsection{Returns}{ None +Make Date YearDoY } } \if{html}{\out{
}} @@ -9842,6 +4319,7 @@ Creates a date column from year and day of year columns in the specified data ta } \subsection{Returns}{ None +Set Contrasts of Factor } } \if{html}{\out{
}} @@ -9873,6 +4351,7 @@ Sets the contrasts for a factor column in the specified data table. } \subsection{Returns}{ None +Create Factor Data Frame } } \if{html}{\out{
}} @@ -9910,6 +4389,7 @@ Creates a new data frame for a factor column in the specified data table. } \subsection{Returns}{ None +Split Date } } \if{html}{\out{
}} @@ -11544,6 +6024,138 @@ Generate ANOVA tables for specified columns in a dataset. } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DataBook-display_daily_table}{}}} +\subsection{Method \code{display_daily_table()}}{ +Display a daily summary table for a specified climatic data element. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{DataBook$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") +)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{data_name}}{A character string representing the name of the dataset.} + +\item{\code{climatic_element}}{A vector specifying the climatic elements to be displayed (e.g., temperature, rainfall).} + +\item{\code{date_col}}{The name of the column containing date information. Default is \code{date_col}.} + +\item{\code{year_col}}{The name of the column containing year information. Default is \code{year_col}.} + +\item{\code{station_col}}{The name of the column containing station information. If missing, assigns the \code{Station} column from metadata.} + +\item{\code{Misscode}}{A value representing missing data in the dataset.} + +\item{\code{Tracecode}}{A value representing trace amounts of the climatic element.} + +\item{\code{Zerocode}}{A value representing zero values for the climatic element.} + +\item{\code{monstats}}{A vector of summary statistics to calculate for monthly data. Options include \code{"min"}, \code{"mean"}, \code{"median"}, \code{"max"}, \code{"IQR"}, and \code{"sum"}.} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +A data frame displaying the daily summary table for the specified climatic element. +Add a Comment to Data Sheet +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DataBook-add_comment}{}}} +\subsection{Method \code{add_comment()}}{ +Adds a new \code{instat_comment} object to the data sheet if the key is defined and valid. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{DataBook$add_comment(new_comment)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{new_comment}}{An \code{instat_comment} object to be added to the data sheet.} +} +\if{html}{\out{
}} +} +\subsection{Details}{ +This function first checks if a key is defined and valid for the data sheet. +It also verifies that \code{new_comment} is an \code{instat_comment} object and that the key columns in \code{new_comment} are valid keys in the data frame. +If the comment ID already exists, a warning is issued and the existing comment is replaced. +} + +\subsection{Returns}{ +None. This function modifies the data sheet by adding or replacing a comment. +Delete a Comment from Data Sheet +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DataBook-delete_comment}{}}} +\subsection{Method \code{delete_comment()}}{ +Deletes a comment from the data sheet based on the comment ID. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{DataBook$delete_comment(comment_id)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{comment_id}}{A character string representing the ID of the comment to be deleted.} +} +\if{html}{\out{
}} +} +\subsection{Details}{ +If the specified comment ID does not exist in the data sheet, an error is thrown. +} + +\subsection{Returns}{ +None. This function modifies the data sheet by removing the specified comment. +Get All Comment IDs +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DataBook-get_comment_ids}{}}} +\subsection{Method \code{get_comment_ids()}}{ +Retrieves all comment IDs currently stored in the data sheet. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{DataBook$get_comment_ids()}\if{html}{\out{
}} +} + +\subsection{Returns}{ +A character vector containing the IDs of all comments in the data sheet. +Get Comments as Data Frame +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DataBook-get_comments_as_data_frame}{}}} +\subsection{Method \code{get_comments_as_data_frame()}}{ +Converts all comments in the data sheet to a data frame format for easier inspection and analysis. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{DataBook$get_comments_as_data_frame()}\if{html}{\out{
}} +} + +\subsection{Details}{ +This function collects various fields from each comment and returns them in a data frame. +The number of replies and attributes for each comment is also included. +Currently, nested comments (replies) and additional attributes are not displayed in detail. +} + +\subsection{Returns}{ +A data frame with columns representing comment ID, key values, column, value, type, comment text, label, calculation, timestamp, number of replies, resolved status, active status, and number of attributes. +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-DataBook-define_as_options_by_context}{}}} \subsection{Method \code{define_as_options_by_context()}}{ @@ -11919,7 +6531,8 @@ Displays the details of a specified link. \subsection{Arguments}{ \if{html}{\out{
}} \describe{ -\item{\code{link_name}}{The name of the link to view} +\item{\code{link_name}}{The name of the link to view +Import SST} } \if{html}{\out{
}} } From 3a419292bd478b24ba342357f3528ff8745ff2b2 Mon Sep 17 00:00:00 2001 From: lilyclements Date: Fri, 1 Nov 2024 17:22:26 +0000 Subject: [PATCH 2/4] adding parms --- R/data_book.R | 18 +++++++++++++++--- man/DataBook.Rd | 10 +++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/R/data_book.R b/R/data_book.R index 76aeab7..4100788 100644 --- a/R/data_book.R +++ b/R/data_book.R @@ -6,6 +6,7 @@ #' @docType class #' @format An R6 class object. #' @aliases DataBook DataBook$new DataBook$ +#' #' @usage DataBook$new(data_tables = list(), instat_obj_metadata = list(), #' data_tables_variables_metadata = rep(list(data.frame()), length(data_tables)), #' data_tables_metadata = rep(list(list()), length(data_tables)), @@ -14,6 +15,17 @@ #' imported_from = as.list(rep("", length(data_tables))), #' messages = TRUE, convert = TRUE, create = TRUE) #' +#' @param data_tables A list of data frames to be included in the DataBook. +#' @param instat_obj_metadata Metadata for the instat object. +#' @param data_tables_variables_metadata A list of data frames, each containing metadata for the corresponding data table. +#' @param data_tables_metadata A list of lists, each containing metadata for the corresponding data table. +#' @param data_tables_filters A list of lists, each containing filter information for the corresponding data table. +#' @param data_tables_column_selections A list of lists, each containing column selection information for the corresponding data table. +#' @param imported_from A list of strings indicating the source from which each data table was imported. +#' @param messages A boolean indicating whether to display messages. +#' @param convert A boolean indicating whether to perform data conversion. +#' @param create A boolean indicating whether to create new data objects. +#' #' @section Methods: #' \describe{ #' \item{\code{set_data(new_data, messages, check_names)}}{Sets the data for the DataSheet object.} @@ -234,9 +246,8 @@ #' @export DataBook <- R6::R6Class("DataBook", public = list( - #' Initialise for Public List - #' @description - #' Initialize a new DataBook object. + #' @field initialize Initialise for Public List + #' @description Initialize a new DataBook object. #' @param data_tables A list of data frames to be included in the DataBook. #' @param instat_obj_metadata Metadata for the instat object. #' @param data_tables_variables_metadata A list of data frames, each containing metadata for the corresponding data table. @@ -247,6 +258,7 @@ DataBook <- R6::R6Class("DataBook", #' @param messages A boolean indicating whether to display messages. #' @param convert A boolean indicating whether to perform data conversion. #' @param create A boolean indicating whether to create new data objects. + initialize = function(data_tables = list(), instat_obj_metadata = list(), data_tables_variables_metadata = rep(list(data.frame()), length(data_tables)), data_tables_metadata = rep(list(list()), length(data_tables)), diff --git a/man/DataBook.Rd b/man/DataBook.Rd index f1a5a17..9128684 100644 --- a/man/DataBook.Rd +++ b/man/DataBook.Rd @@ -240,12 +240,20 @@ An R6 class to manage a collection of data tables along with their metadata and \item{\code{view_link(link_name)}}{Displays the details of a specified link.} @export -Initialise for Public List } +\section{Public fields}{ +\if{html}{\out{
}} +\describe{ +\item{\code{initialize}}{Initialise for Public List} +} +\if{html}{\out{
}} +} \section{Active bindings}{ \if{html}{\out{
}} \describe{ +\item{\code{initialize}}{Initialise for Public List} + \item{\code{data_objects_changed}}{Logical indicating whether the data objects have changed.} } \if{html}{\out{
}} From ee97c8576f0e155cea80b6d74ea88f89e65e778b Mon Sep 17 00:00:00 2001 From: lilyclements Date: Tue, 19 Nov 2024 20:24:23 +0000 Subject: [PATCH 3/4] adding from calculations.R file --- DESCRIPTION | 4 +- R/data_sheet.R | 141 ++++++++++++++++++++++++++++------------------- man/DataSheet.Rd | 48 +++++++++++++++- 3 files changed, 133 insertions(+), 60 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4a9bc28..74dc5bd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -8,7 +8,7 @@ Description: This package provides tools for managing and manipulating data fram License: LGPL (>= 3) Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 Imports: chillR, clipr, @@ -31,4 +31,4 @@ Imports: stringr, tibble, tidyselect, - zoo \ No newline at end of file + zoo diff --git a/R/data_sheet.R b/R/data_sheet.R index debb7c0..fcbd6ac 100644 --- a/R/data_sheet.R +++ b/R/data_sheet.R @@ -179,10 +179,15 @@ #' \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.} +#' +#' # related to instat_comments.R file in R-Instat #' \item{\code{add_comment(new_comment)}}{Adds a new `instat_comment` object to the data sheet if the key is defined and valid.} #' \item{\code{delete_comment(comment_id)}}{Deletes a comment from the data sheet based on the comment ID.} #' \item{\code{get_comment_ids()}}{Retrieves all comment IDs currently stored in the data sheet.} #' \item{\code{get_comments_as_data_frame()}}{Converts all comments in the data sheet to a data frame format for easier inspection and analysis.} +#' +#' # related to calculation.R file in R-Instat +#' \item{\code{save_calculation(calc)}}{Save a Calculation to the DataSheet.} #' } #' #' @section Active bindings: @@ -1482,7 +1487,7 @@ DataSheet <- R6::R6Class( #' #' @return Character, the next default column name. get_next_default_column_name = function(prefix) { - return(next_default_item(prefix = prefix, existing_names = self$get_column_names(use_current_column_selection = FALSE))) + return(instatExtras::next_default_item(prefix = prefix, existing_names = self$get_column_names(use_current_column_selection = FALSE))) }, #' @description @@ -2107,7 +2112,7 @@ DataSheet <- R6::R6Class( #' @param outer_not Logical, if TRUE, applies negation to the outer condition. add_filter = function(filter, filter_name = "", replace = TRUE, set_as_current = FALSE, na.rm = TRUE, is_no_filter = FALSE, and_or = "&", inner_not = FALSE, outer_not = FALSE) { if(missing(filter)) stop("filter is required") - if(filter_name == "") filter_name = next_default_item("Filter", names(private$filters)) + if(filter_name == "") filter_name = instatExtras::next_default_item("Filter", names(private$filters)) for(condition in filter) { if(length(condition) < 2 || length(condition) > 3 || !all(names(condition) %in% c("column", "operation", "value"))) { @@ -2369,7 +2374,7 @@ DataSheet <- R6::R6Class( #' @param and_or Character, specifies the logical operator for combining conditions. add_column_selection = function(column_selection, name = "", replace = TRUE, set_as_current = FALSE, is_everything = FALSE, and_or = "|") { if(missing(column_selection)) stop("column_selection is required") - if(name == "") name <- next_default_item("sel", names(private$column_selections)) + if(name == "") name <- instatExtras::next_default_item("sel", names(private$column_selections)) if(name %in% names(private$column_selections) && !replace) { warning("The column selection was not added. A column selection named ", name, " already exists. Specify replace = TRUE to overwrite it.") return() @@ -2573,7 +2578,7 @@ DataSheet <- R6::R6Class( #' @param object Any, the object to add. add_object = function(object_name, object_type_label, object_format, object) { if(missing(object_name)){ - object_name <- next_default_item("object", names(private$objects)) + object_name <- instatExtras::next_default_item("object", names(private$objects)) } if(object_name %in% names(private$objects)){ @@ -2781,7 +2786,7 @@ DataSheet <- R6::R6Class( warning("A key with these columns already exists. No action will be taken.") } else { - if(missing(key_name)) key_name <- next_default_item("key", names(private$keys)) + if(missing(key_name)) key_name <- instatExtras::next_default_item("key", names(private$keys)) if(key_name %in% names(private$keys)) warning("A key called", key_name, "already exists. It will be replaced.") private$keys[[key_name]] <- col_names self$append_to_variables_metadata(col_names, is_key_label, TRUE) @@ -3270,22 +3275,22 @@ DataSheet <- R6::R6Class( if(weekday_name) { weekday_name_vector <- lubridate::wday(col_data, label = TRUE, abbr = FALSE) - col_name <- next_default_item(prefix = "weekday_name", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "weekday_name", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = weekday_name_vector, adjacent_column = adjacent_column, before = FALSE) } if(weekday_abbr) { weekday_abbr_vector <- lubridate::wday(col_data, label = TRUE) - col_name <- next_default_item(prefix = "weekday_abbr", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "weekday_abbr", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = weekday_abbr_vector, adjacent_column = adjacent_column, before = FALSE) } if(weekday_val) { weekday_val_vector <- lubridate::wday(col_data) - col_name <- next_default_item(prefix = "weekday_val", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "weekday_val", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = weekday_val_vector, adjacent_column = adjacent_column, before = FALSE) } if(week_val) { week_Val_vector <- lubridate::week(col_data) - col_name <- next_default_item(prefix = "week_val", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "week_val", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = week_Val_vector, adjacent_column = adjacent_column, before = FALSE) } if(pentad_abbr) { @@ -3296,13 +3301,13 @@ DataSheet <- R6::R6Class( month_levels <- if (s_start_month == 1) month.list else c(tail(month.list, -s_start_month + 1), head(month.list, s_start_month - 1)) pentad_levels <- paste0(rep(month_levels, each = 6), 1:6) pentad_abbr_vector <- factor(paste(month_abbr_vector, pentad_val_vector, sep = ""), levels = pentad_levels) - col_name <- next_default_item(prefix = "pentad_abbr", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "pentad_abbr", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = pentad_abbr_vector, adjacent_column = adjacent_column, before = FALSE) } if(pentad_val) { pentad_val_vector <- ((as.integer(pentad(col_data))) - (s_start_month - 1)*6) %% 72 pentad_val_vector <- ifelse(pentad_val_vector == 0, 72, pentad_val_vector) - col_name <- next_default_item(prefix = "pentad", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "pentad", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = pentad_val_vector, adjacent_column = adjacent_column, before = FALSE) } if(dekad_abbr) { @@ -3313,27 +3318,27 @@ DataSheet <- R6::R6Class( month_levels <- if (s_start_month == 1) month.list else c(tail(month.list, -s_start_month + 1), head(month.list, s_start_month - 1)) dekad_levels <- paste0(rep(month_levels, each = 3), 1:3) dekad_abbr_vector <- factor(paste(month_abbr_vector, dekad_val_vector, sep = ""), levels = dekad_levels) - col_name <- next_default_item(prefix = "dekad_abbr", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "dekad_abbr", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = dekad_abbr_vector, adjacent_column = adjacent_column, before = FALSE) } if(dekad_val) { dekad_val_vector <- ((as.numeric(dekade(col_data))) - (s_start_month - 1)*3) %% 36 dekad_val_vector <- ifelse(dekad_val_vector == 0, 36, dekad_val_vector) - col_name <- next_default_item(prefix = "dekad", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "dekad", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = dekad_val_vector, adjacent_column = adjacent_column, before = FALSE) } if(quarter_abbr){ if(s_shift) { s_quarter_val_vector <- lubridate::quarter(col_data, with_year = with_year, fiscal_start = s_start_month) quarter_labels <- get_quarter_label(s_quarter_val_vector, s_start_month) - col_name <- next_default_item(prefix = "s_quarter", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "s_quarter", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = quarter_labels, adjacent_column = adjacent_column, before = FALSE) self$append_to_variables_metadata(col_names = col_name, property = label_label, new_val = paste("Shifted quarter starting on day", s_start_day)) } else { quarter_val_vector <- lubridate::quarter(col_data, with_year = with_year) quarter_labels <- get_quarter_label(quarter_val_vector, s_start_month) - col_name <- next_default_item(prefix = "quarter_abbr", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "quarter_abbr", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = quarter_labels, adjacent_column = adjacent_column, before = FALSE) } self$append_to_variables_metadata(col_names = col_name, property = doy_start_label, new_val = s_start_day) @@ -3341,13 +3346,13 @@ DataSheet <- R6::R6Class( if(quarter_val) { if(s_shift) { s_quarter_val_vector <- lubridate::quarter(col_data, with_year = with_year, fiscal_start = s_start_month) - col_name <- next_default_item(prefix = "s_quarter", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "s_quarter", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = s_quarter_val_vector, adjacent_column = adjacent_column, before = FALSE) self$append_to_variables_metadata(col_names = col_name, property = label_label, new_val = paste("Shifted quarter starting on day", s_start_day)) } else { quarter_val_vector <- lubridate::quarter(col_data, with_year = with_year) - col_name <- next_default_item(prefix = "quarter", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "quarter", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = quarter_val_vector, adjacent_column = adjacent_column, before = FALSE) } self$append_to_variables_metadata(col_names = col_name, property = doy_start_label, new_val = s_start_day) @@ -3356,20 +3361,20 @@ DataSheet <- R6::R6Class( day_in_year_vector <- lubridate::yday(col_data) - s_start_day + 1 + (!lubridate::leap_year(col_data) & s_start_day > 59) day_in_year_vector <- dplyr::if_else(lubridate::leap_year(col_data), day_in_year_vector %% 366, day_in_year_vector %% 365) day_in_year_vector <- dplyr::if_else(day_in_year_vector == 0, dplyr::if_else(lubridate::leap_year(col_data), 366, 365), day_in_year_vector) - col_name <- next_default_item(prefix = "doy_365", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "doy_365", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = day_in_year_vector, adjacent_column = adjacent_column, before = FALSE) self$append_to_variables_metadata(col_names = col_name, property = doy_start_label, new_val = s_start_day) if(s_shift) self$append_to_variables_metadata(col_names = col_name, property = label_label, new_val = paste("Shifted year starting on day", s_start_day)) } if(day_in_year_366) { if(s_shift) { - col_name <- next_default_item(prefix = "s_doy", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "s_doy", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = temp_s_doy, adjacent_column = adjacent_column, before = FALSE) self$append_to_variables_metadata(col_names = col_name, property = label_label, new_val = paste("Shifted day of year starting on day", s_start_day)) } else { day_in_year_366_vector <- as.integer(yday_366(col_data)) - col_name <- next_default_item(prefix = "doy", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "doy", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = day_in_year_366_vector, adjacent_column = adjacent_column, before = FALSE) } if(is_climatic && is.null(self$get_climatic_column_name(doy_label))) { @@ -3379,12 +3384,12 @@ DataSheet <- R6::R6Class( } if(days_in_month) { days_in_month_vector <- as.numeric(lubridate::days_in_month(col_data)) - col_name <- next_default_item(prefix = "days_in_month", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "days_in_month", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = days_in_month_vector, adjacent_column = adjacent_column, before = FALSE) } if(day_in_month) { day_in_month_vector <- as.numeric(lubridate::mday(col_data)) - col_name <- next_default_item(prefix = "day_in_month", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "day_in_month", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = day_in_month_vector, adjacent_column = adjacent_column, before = FALSE) if(is_climatic && is.null(self$get_climatic_column_name(day_label))) { self$append_climatic_types(types = c(day = col_name)) @@ -3393,7 +3398,7 @@ DataSheet <- R6::R6Class( if(month_val) { month_val_vector <- (lubridate::month(col_data) - (s_start_month - 1)) %% 12 month_val_vector <- ifelse(month_val_vector == 0, 12, month_val_vector) - col_name <- next_default_item(prefix = "month_val", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "month_val", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = month_val_vector, adjacent_column = adjacent_column, before = FALSE) if(s_shift) self$append_to_variables_metadata(col_names = col_name, property = label_label, new_val = paste("Shifted month starting on day", s_start_day)) if(is_climatic && is.null(self$get_climatic_column_name(month_label))) { @@ -3403,7 +3408,7 @@ DataSheet <- R6::R6Class( } if(month_abbr) { month_abbr_vector <- make_factor(forcats::fct_shift(f = lubridate::month(col_data, label = TRUE), n = s_start_month - 1), ordered = FALSE) - col_name <- next_default_item(prefix = "month_abbr", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "month_abbr", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = month_abbr_vector, adjacent_column = adjacent_column, before = FALSE) if(s_shift) self$append_to_variables_metadata(col_names = col_name, property = label_label, new_val = paste("Shifted month starting on day", s_start_day)) if(is_climatic && is.null(self$get_climatic_column_name(month_label))) { @@ -3413,7 +3418,7 @@ DataSheet <- R6::R6Class( } if(month_name) { month_name_vector <- forcats::fct_shift(f = lubridate::month(col_data, label = TRUE, abbr = FALSE), n = s_start_month - 1) - col_name <- next_default_item(prefix = "month_name", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "month_name", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = month_name_vector, adjacent_column = adjacent_column, before = FALSE) if(s_shift) self$append_to_variables_metadata(col_names = col_name, property = label_label, new_val = paste("Shifted month starting on day", s_start_day)) if(is_climatic && is.null(self$get_climatic_column_name(month_label))) { @@ -3423,7 +3428,7 @@ DataSheet <- R6::R6Class( } if(year_name) { if(s_shift) { - col_name <- next_default_item(prefix = "s_year", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "s_year", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = temp_s_year, adjacent_column = adjacent_column, before = FALSE) self$append_to_variables_metadata(col_names = col_name, property = label_label, new_val = paste("Shifted year starting on day", s_start_day)) new_labels <- sort(unique(temp_s_year_num)) @@ -3432,7 +3437,7 @@ DataSheet <- R6::R6Class( } else { year_vector <- lubridate::year(col_data) - col_name <- next_default_item(prefix = "year", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "year", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = make_factor(year_vector), adjacent_column = adjacent_column, before = FALSE) } if(is_climatic && is.null(self$get_climatic_column_name(year_label))) { @@ -3442,13 +3447,13 @@ DataSheet <- R6::R6Class( } if(year_val) { if(s_shift) { - col_name <- next_default_item(prefix = "s_year", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "s_year", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = temp_s_year_num, adjacent_column = adjacent_column, before = FALSE) self$append_to_variables_metadata(col_names = col_name, property = label_label, new_val = paste("Shifted year starting on day", s_start_day)) } else { year_vector <- lubridate::year(col_data) - col_name <- next_default_item(prefix = "year", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "year", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = year_vector, adjacent_column = adjacent_column, before = FALSE) } if(is_climatic && is.null(self$get_climatic_column_name(year_label))) { @@ -3458,7 +3463,7 @@ DataSheet <- R6::R6Class( } if(leap_year) { leap_year_vector <- lubridate::leap_year(col_data) - col_name <- next_default_item(prefix = "leap_year", existing_names = self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(prefix = "leap_year", existing_names = self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name = col_name, col_data = leap_year_vector, adjacent_column = adjacent_column, before = FALSE) } }, @@ -3622,7 +3627,7 @@ DataSheet <- R6::R6Class( elements <- curr_data[["value"]] } - key_name <- next_default_item(prefix = "key", existing_names = names(curr_data), include_index = FALSE) + key_name <- instatExtras::next_default_item(prefix = "key", existing_names = names(curr_data), include_index = FALSE) curr_data[[key_name]] <- factor(ifelse(is.na(elements), "Missing", "Present"), levels = c("Present", "Missing")) key <- c(key_colours) @@ -4049,7 +4054,7 @@ DataSheet <- R6::R6Class( award_date <- self$get_columns_from_data(self$get_corruption_column_name(corruption_award_date_label)) if(!lubridate::is.Date(award_date)) message(message("Cannot auto generate ", corruption_award_year_label, " because ", corruption_award_date_label, " column is not of type Date.")) else { - col_name <- next_default_item(corruption_award_year_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_award_year_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, year(award_date)) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_award_year_label) self$append_to_variables_metadata(col_name, "label", "Award year") @@ -4071,7 +4076,7 @@ DataSheet <- R6::R6Class( procedure_type[procedure_type == "SHOP"] <- "International Shopping" procedure_type <- factor(procedure_type, levels = c("Commercial Practices", "Direct Contracting", "Force Account", "INDB", "Individual", "International Competitive Bidding", "International Shopping", "Least Cost Selection", "Limited International Bidding", "National Competitive Bidding", "National Shopping", "Quality And Cost-Based Selection", "Quality Based Selection", "Selection Based On Consultant's Qualification", "Selection Under a Fixed Budget", "Service Delivery Contracts", "Single Source Selection")) - col_name <- next_default_item(corruption_procedure_type_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_procedure_type_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, procedure_type) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_procedure_type_label) self$append_to_variables_metadata(col_name, "label", "Procedure type") @@ -4089,7 +4094,7 @@ DataSheet <- R6::R6Class( else { id <- as.numeric(factor(paste0(self$get_columns_from_data(self$get_corruption_column_name(corruption_country_label)), self$get_columns_from_data(self$get_corruption_column_name(corruption_procuring_authority_label))), levels = unique(paste0(self$get_columns_from_data(self$get_corruption_column_name(corruption_country_label)), self$get_columns_from_data(self$get_corruption_column_name(corruption_procuring_authority_label)))))) - col_name <- next_default_item(corruption_procuring_authority_id_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_procuring_authority_id_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, id) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_procuring_authority_id_label) self$append_to_variables_metadata(col_name, "label", "Procurement Auth. ID") @@ -4107,7 +4112,7 @@ DataSheet <- R6::R6Class( else { id <- as.numeric(factor(self$get_columns_from_data(self$get_corruption_column_name(corruption_winner_name_label)), levels = unique(self$get_columns_from_data(self$get_corruption_column_name(corruption_winner_name_label))))) - col_name <- next_default_item(corruption_winner_id_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_winner_id_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, id) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_winner_id_label) self$append_to_variables_metadata(col_name, "label", "w_name ID") @@ -4125,7 +4130,7 @@ DataSheet <- R6::R6Class( else { f_winner <- (self$get_columns_from_data(self$get_corruption_column_name(corruption_country_label)) != self$get_columns_from_data(self$get_corruption_column_name(corruption_winner_country_label))) - col_name <- next_default_item(corruption_foreign_winner_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_foreign_winner_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, f_winner) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_foreign_winner_label) self$append_to_variables_metadata(col_name, "label", "Foreign w_name dummy") @@ -4151,7 +4156,7 @@ DataSheet <- R6::R6Class( procurement_type[procedure_type == "Least Cost Selection" | procedure_type == "Selection Based On Consultant's Qualification"] <- "consultancy,cost" procurement_type <- factor(procurement_type, levels = c("open", "restricted", "single source", "consultancy,quality", "consultancy,cost", "own provision", "other, missing")) - col_name <- next_default_item(corruption_procurement_type_cats_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_procurement_type_cats_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, procurement_type) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_procurement_type_cats_label) self$append_to_variables_metadata(col_name, "label", "Main procurement type category") @@ -4172,7 +4177,7 @@ DataSheet <- R6::R6Class( procurement_type2[procurement_type_cats == "open"] <- FALSE procurement_type2[procurement_type_cats == "restricted" | procurement_type_cats == "single source" | procurement_type_cats == "consultancy,quality" | procurement_type_cats == "consultancy,cost"] <- TRUE - col_name <- next_default_item(corruption_procurement_type_2_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_procurement_type_2_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, procurement_type2) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_procurement_type_2_label) self$append_to_variables_metadata(col_name, "label", "Proc. type is restricted, single source, consultancy") @@ -4195,7 +4200,7 @@ DataSheet <- R6::R6Class( procurement_type3[procurement_type_cats == "consultancy,quality" | procurement_type_cats == "consultancy,cost"] <- "consultancy spending risk" procurement_type3 <- factor(procurement_type3, levels = c("open procedure", "closed procedure risk", "consultancy spending risk")) - col_name <- next_default_item(corruption_procurement_type_3_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_procurement_type_3_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, procurement_type3) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_procurement_type_3_label) self$append_to_variables_metadata(col_name, "label", "Procedure type (open, closed, consultancy)") @@ -4215,7 +4220,7 @@ DataSheet <- R6::R6Class( if(!lubridate::is.Date(award_date) || !lubridate::is.Date(sign_date)) message("Cannot auto generate ", corruption_signature_period_label, " because ", corruption_award_date_label, " or ", corruption_signature_date_label, " are not of type Date.") else { signature_period <- self$get_columns_from_data(self$get_corruption_column_name(corruption_signature_date_label)) - self$get_columns_from_data(self$get_corruption_column_name(corruption_award_date_label)) - col_name <- next_default_item(corruption_signature_period_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_signature_period_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, signature_period) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_signature_period_label) self$append_to_variables_metadata(col_name, "label", "Signature period") @@ -4235,7 +4240,7 @@ DataSheet <- R6::R6Class( signature_period_corrected <- self$get_columns_from_data(self$get_corruption_column_name(corruption_signature_period_label)) signature_period_corrected[signature_period_corrected < 0 | signature_period_corrected > 730] <- NA - col_name <- next_default_item(corruption_signature_period_corrected_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_signature_period_corrected_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, signature_period_corrected) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_signature_period_corrected_label) self$append_to_variables_metadata(col_name, "label", "Signature period - corrected") @@ -4254,7 +4259,7 @@ DataSheet <- R6::R6Class( else { signature_period_5Q <- .bincode(self$get_columns_from_data(self$get_corruption_column_name(corruption_signature_period_label)), quantile(self$get_columns_from_data(self$get_corruption_column_name(corruption_signature_period_label)), seq(0, 1, length.out = 5 + 1), type = 2, na.rm = TRUE), include.lowest = TRUE) - col_name <- next_default_item(corruption_signature_period_5Q_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_signature_period_5Q_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, signature_period_5Q) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_signature_period_5Q_label) } @@ -4272,7 +4277,7 @@ DataSheet <- R6::R6Class( else { signature_period_25Q <- .bincode(self$get_columns_from_data(self$get_corruption_column_name(corruption_signature_period_label)), quantile(self$get_columns_from_data(self$get_corruption_column_name(corruption_signature_period_label)), seq(0, 1, length.out = 25 + 1), type = 2, na.rm = TRUE), include.lowest = TRUE) - col_name <- next_default_item(corruption_signature_period_25Q_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_signature_period_25Q_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, signature_period_25Q) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_signature_period_25Q_label) } @@ -4295,7 +4300,7 @@ DataSheet <- R6::R6Class( authority_id_label <- self$get_corruption_column_name(corruption_procuring_authority_id_label) winner_id_label <- self$get_corruption_column_name(corruption_winner_id_label) award_date_label <- self$get_corruption_column_name(corruption_award_date_label) - col_name <- next_default_item(corruption_roll_num_winner_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_roll_num_winner_label, self$get_column_names(), include_index = FALSE) exp <- lazyeval::interp(~ sum(temp[[authority_id1]] == authority_id2 & temp[[winner_id1]] == winner_id2 & temp[[award_date1]] <= award_date2 & temp[[award_date1]] > award_date2 - 365), authority_id1 = authority_id_label, authority_id2 = as.name(authority_id_label), winner_id1 = winner_id_label, winner_id2 = as.name(winner_id_label), award_date1 = award_date_label, award_date2 = as.name(award_date_label)) temp <- self$get_data_frame(use_current_filter = FALSE) temp <- temp %>% dplyr::rowwise() %>% dplyr::mutate_(.dots = setNames(list(exp), col_name)) @@ -4320,7 +4325,7 @@ DataSheet <- R6::R6Class( temp <- self$get_data_frame(use_current_filter = FALSE) authority_id_label <- self$get_corruption_column_name(corruption_procuring_authority_id_label) award_date_label <- self$get_corruption_column_name(corruption_award_date_label) - col_name <- next_default_item(corruption_roll_num_issuer_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_roll_num_issuer_label, self$get_column_names(), include_index = FALSE) exp <- lazyeval::interp(~ sum(temp[[authority_id1]] == authority_id2 & temp[[award_date1]] <= award_date2 & temp[[award_date1]] > award_date2 - 365), authority_id1 = authority_id_label, authority_id2 = as.name(authority_id_label), award_date1 = award_date_label, award_date2 = as.name(award_date_label)) temp <- self$get_data_frame(use_current_filter = FALSE) temp <- temp %>% dplyr::rowwise() %>% dplyr::mutate_(.dots = setNames(list(exp), col_name)) @@ -4356,7 +4361,7 @@ DataSheet <- R6::R6Class( else { contract_value_label <- self$get_corruption_column_name(corruption_original_contract_value_label) } - col_name <- next_default_item(corruption_roll_sum_issuer_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_roll_sum_issuer_label, self$get_column_names(), include_index = FALSE) exp <- lazyeval::interp(~ sum(temp[[contract_value]][temp[[authority_id1]] == authority_id2 & temp[[award_date1]] <= award_date2 & temp[[award_date1]] > award_date2 - 365]), authority_id1 = authority_id_label, authority_id2 = as.name(authority_id_label), award_date1 = award_date_label, award_date2 = as.name(award_date_label), contract_value = contract_value_label) temp <- self$get_data_frame(use_current_filter = FALSE) temp <- temp %>% dplyr::rowwise() %>% dplyr::mutate_(.dots = setNames(list(exp), col_name)) @@ -4394,7 +4399,7 @@ DataSheet <- R6::R6Class( else { contract_value_label <- self$get_corruption_column_name(corruption_original_contract_value_label) } - col_name <- next_default_item(corruption_roll_sum_winner_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_roll_sum_winner_label, self$get_column_names(), include_index = FALSE) exp <- lazyeval::interp(~ sum(temp[[contract_value]][temp[[authority_id1]] == authority_id2 & temp[[winner_id1]] == winner_id2 & temp[[award_date1]] <= award_date2 & temp[[award_date1]] > award_date2 - 365]), authority_id1 = authority_id_label, authority_id2 = as.name(authority_id_label), winner_id1 = winner_id_label, winner_id2 = as.name(winner_id_label), award_date1 = award_date_label, award_date2 = as.name(award_date_label), contract_value = contract_value_label) temp <- self$get_data_frame(use_current_filter = FALSE) temp <- temp %>% dplyr::rowwise() %>% dplyr::mutate_(.dots = setNames(list(exp), col_name)) @@ -4421,7 +4426,7 @@ DataSheet <- R6::R6Class( } else { share <- self$get_columns_from_data(self$get_corruption_column_name(corruption_roll_sum_winner_label)) / self$get_columns_from_data(self$get_corruption_column_name(corruption_roll_sum_issuer_label)) - col_name <- next_default_item(corruption_roll_share_winner_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_roll_share_winner_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, share) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_roll_share_winner_label) self$append_to_variables_metadata(col_name, "label", "12 month rolling contract share of winner for each contract awarded") @@ -4441,7 +4446,7 @@ DataSheet <- R6::R6Class( } else { single_bidder <- (self$get_columns_from_data(self$get_corruption_column_name(corruption_all_bids_trimmed_label)) == 1) - col_name <- next_default_item(corruption_single_bidder_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_single_bidder_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, single_bidder) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_single_bidder_label) self$append_to_variables_metadata(col_name, "label", "Single bidder dummy") @@ -4465,7 +4470,7 @@ DataSheet <- R6::R6Class( contr_share_over_threshold[(self$get_columns_from_data(self$get_corruption_column_name(corruption_roll_num_issuer_label)) >= 3) & (self$get_columns_from_data(self$get_corruption_column_name(corruption_roll_share_winner_label)) >= 0.5)] <- TRUE contr_share_over_threshold[(self$get_columns_from_data(self$get_corruption_column_name(corruption_roll_num_issuer_label)) >= 3) & (self$get_columns_from_data(self$get_corruption_column_name(corruption_roll_share_winner_label)) < 0.5)] <- FALSE - col_name <- next_default_item(corruption_contract_value_share_over_threshold_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_contract_value_share_over_threshold_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, contr_share_over_threshold) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_contract_value_share_over_threshold_label) self$append_to_variables_metadata(col_name, "label", "Winner share at least 50% where issuers awarded at least 3 contracts") @@ -4488,7 +4493,7 @@ DataSheet <- R6::R6Class( all_bids[is.na(all_bids)] <- self$get_columns_from_data(self$get_corruption_column_name(corruption_no_bids_received_label))[is.na(all_bids)] } - col_name <- next_default_item(corruption_all_bids_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_all_bids_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, all_bids) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_all_bids_label) self$append_to_variables_metadata(col_name, "label", "# Bids (all)") @@ -4510,7 +4515,7 @@ DataSheet <- R6::R6Class( all_bids_trimmed <- self$get_columns_from_data(self$get_corruption_column_name(corruption_all_bids_label)) all_bids_trimmed[all_bids_trimmed > 50] <- 50 - col_name <- next_default_item(corruption_all_bids_trimmed_label, self$get_column_names(), include_index = FALSE) + col_name <- instatExtras::next_default_item(corruption_all_bids_trimmed_label, self$get_column_names(), include_index = FALSE) self$add_columns_to_data(col_name, all_bids_trimmed) self$append_to_variables_metadata(col_name, corruption_type_label, corruption_all_bids_trimmed_label) self$append_to_variables_metadata(col_name, "label", "# Bids (trimmed at 50)") @@ -4526,7 +4531,7 @@ DataSheet <- R6::R6Class( standardise_country_names = function(country_columns = c()) { for(col_name in country_columns) { corrected_col <- standardise_country_names(self$get_columns_from_data(col_name)) - new_col_name <- next_default_item(paste(col_name, "standardised", sep = "_"), self$get_column_names(), include_index = FALSE) + new_col_name <- instatExtras::next_default_item(paste(col_name, "standardised", sep = "_"), self$get_column_names(), include_index = FALSE) self$add_columns_to_data(new_col_name, corrected_col) type <- self$get_variables_metadata(column = col_name, property = corruption_type_label) if(!is.na(type)) { @@ -5144,9 +5149,33 @@ DataSheet <- R6::R6Class( return(data.frame(id = id, key_values = key_values, column = column, value = value, type = type, comment = comment, label = label, calculation = calculation, time_stamp = time_stamp, no_replies = no_replies, resolved = resolved, active = active, no_attributes = no_attributes)) }, - #' @description - #' Display a daily summary table for a specified climatic data element. - #' + #' Save a Calculation to the DataSheet + #' @description This method adds or updates a calculation in the `DataSheet` object. If a calculation + #' with the same name already exists, it will be replaced, with a warning issued to the user. + #' @param calc A list or object representing the calculation to be saved. This object must + #' contain a `name` field. If the `name` field is empty, a default name will be + #' generated using the `instatExtras::next_default_item()` function. + #' @details + #' - If the `calc$name` field is empty, a default name is generated using the + #' `instatExtras::next_default_item()` function, based on the prefix "calc" and the existing + #' calculation names in the `private$calculations` environment. + #' - If a calculation with the same name already exists in `private$calculations`, it + #' will be replaced, and a warning will be issued to inform the user. + #' - The calculation is saved in the `private$calculations` list, keyed by its `name`. + #' @return The name of the saved calculation (a character string). + #' @seealso \code{\link{instatExtras::next_default_item}} + #' + #' @note Be cautious when replacing existing calculations, as the new calculation will + #' overwrite the previous one without confirmation. + save_calculation = function(calc) { + if(calc$name == "") calc$name <- instatExtras::next_default_item("calc", names(private$calculations)) + if(calc$name %in% names(private$calculations)) warning("There is already a calculation called ", calc$name, ". It will be replaced.") + private$calculations[[calc$name]] <- calc + return(calc$name) + }, + + #' Display Daily Summary Table + #' @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`. diff --git a/man/DataSheet.Rd b/man/DataSheet.Rd index 510797c..737c6c0 100644 --- a/man/DataSheet.Rd +++ b/man/DataSheet.Rd @@ -20,9 +20,22 @@ If the specified comment ID does not exist in the data sheet, an error is thrown This function collects various fields from each comment and returns them in a data frame. The number of replies and attributes for each comment is also included. Currently, nested comments (replies) and additional attributes are not displayed in detail. +\itemize{ +\item If the \code{calc$name} field is empty, a default name is generated using the +\code{instatExtras::next_default_item()} function, based on the prefix "calc" and the existing +calculation names in the \code{private$calculations} environment. +\item If a calculation with the same name already exists in \code{private$calculations}, it +will be replaced, and a warning will be issued to inform the user. +\item The calculation is saved in the \code{private$calculations} list, keyed by its \code{name}. +} This function retrieves the data frame associated with the specified dataset and renames columns to standardise \code{Date}, \code{Year}, and \code{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 \code{monstats} argument. } +\note{ +Be cautious when replacing existing calculations, as the new calculation will +overwrite the previous one without confirmation. +Display Daily Summary Table +} \section{Methods}{ \describe{ @@ -200,11 +213,14 @@ This function retrieves the data frame associated with the specified dataset and \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.} +\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.}related to instat_comments.R file in R-Instat + \item{\code{add_comment(new_comment)}}{Adds a new \code{instat_comment} object to the data sheet if the key is defined and valid.} \item{\code{delete_comment(comment_id)}}{Deletes a comment from the data sheet based on the comment ID.} \item{\code{get_comment_ids()}}{Retrieves all comment IDs currently stored in the data sheet.} -\item{\code{get_comments_as_data_frame()}}{Converts all comments in the data sheet to a data frame format for easier inspection and analysis.} +\item{\code{get_comments_as_data_frame()}}{Converts all comments in the data sheet to a data frame format for easier inspection and analysis.}related to calculation.R file in R-Instat + +\item{\code{save_calculation(calc)}}{Save a Calculation to the DataSheet.} } } @@ -219,6 +235,9 @@ This function retrieves the data frame associated with the specified dataset and } } +\seealso{ +\code{\link{instatExtras::next_default_item}} +} \section{Active bindings}{ \if{html}{\out{
}} \describe{ @@ -416,6 +435,7 @@ If setting a value, column_selection must be a list.} \item \href{#method-DataSheet-delete_comment}{\code{DataSheet$delete_comment()}} \item \href{#method-DataSheet-get_comment_ids}{\code{DataSheet$get_comment_ids()}} \item \href{#method-DataSheet-get_comments_as_data_frame}{\code{DataSheet$get_comments_as_data_frame()}} +\item \href{#method-DataSheet-save_calculation}{\code{DataSheet$save_calculation()}} \item \href{#method-DataSheet-display_daily_table}{\code{DataSheet$display_daily_table()}} \item \href{#method-DataSheet-clone}{\code{DataSheet$clone()}} } @@ -4370,6 +4390,30 @@ Converts all comments in the data sheet to a data frame format for easier inspec \subsection{Returns}{ A data frame with columns representing comment ID, key values, column, value, type, comment text, label, calculation, timestamp, number of replies, resolved status, active status, and number of attributes. +Save a Calculation to the DataSheet +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DataSheet-save_calculation}{}}} +\subsection{Method \code{save_calculation()}}{ +This method adds or updates a calculation in the \code{DataSheet} object. If a calculation +with the same name already exists, it will be replaced, with a warning issued to the user. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{DataSheet$save_calculation(calc)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{calc}}{A list or object representing the calculation to be saved. This object must +contain a \code{name} field. If the \code{name} field is empty, a default name will be +generated using the \code{instatExtras::next_default_item()} function.} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +The name of the saved calculation (a character string). } } \if{html}{\out{
}} From 57e8c9c7faf4673a60ce105ef2df4d75a21e7eeb Mon Sep 17 00:00:00 2001 From: lilyclements Date: Tue, 19 Nov 2024 21:41:32 +0000 Subject: [PATCH 4/4] add from calculations.R --- R/data_book.R | 801 +++++++++++++++++++++++++++++++++++++++++++++++- man/DataBook.Rd | 311 ++++++++++++++++++- 2 files changed, 1106 insertions(+), 6 deletions(-) diff --git a/R/data_book.R b/R/data_book.R index 4100788..fd33399 100644 --- a/R/data_book.R +++ b/R/data_book.R @@ -224,10 +224,14 @@ #' \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.} +#' +#' # from instat_comment.R in R-Instat #' \item{\code{add_comment(new_comment)}}{Adds a new `instat_comment` object to the data sheet if the key is defined and valid.} #' \item{\code{delete_comment(comment_id)}}{Deletes a comment from the data sheet based on the comment ID.} #' \item{\code{get_comment_ids()}}{Retrieves all comment IDs currently stored in the data sheet.} #' \item{\code{get_comments_as_data_frame()}}{Converts all comments in the data sheet to a data frame format for easier inspection and analysis.} +#' +#' # from link.R in R-Instat #' \item{\code{update_links_rename_data_frame(old_data_name, new_data_name)}}{This function updates all links that reference a data frame with a specified old name, renaming it to a new name.} #' \item{\code{update_links_rename_column(data_name, old_column_name, new_column_name)}}{This function updates all links referencing a column in a data frame with a specified old column name, renaming it to a new column name.} #' \item{\code{add_link(from_data_frame, to_data_frame, link_pairs, type, link_name)}}{This function adds a new link between two data frames with the specified link pairs and type. It will check if the link already exists or if the link columns are keys.} @@ -243,6 +247,16 @@ #' \item{\code{link_between_containing(from_data_frame, containing_columns, to_data_frame)}}{This function returns columns in `to_data_frame` corresponding to `containing_columns` in `from_data_frame` if a link exists between them.} #' \item{\code{view_link(link_name)}}{Displays the details of a specified link.} #' +#' # from calculations.R in R-Instat +#' \item{\code{apply_calculation(calc)}{Apply a Calculation to Data in the DataBook}} +#' \item{\code{save_calculation(end_data_frame, calc)}{Save a Calculation to a Data Frame}} +#' \item{\code{apply_instat_calculation(calc, curr_data_list, previous_manipulations = list(), param_list = list())}{Apply an Instat Calculation}} +#' \item{\code{run_instat_calculation(calc, display = TRUE, param_list = list())}{Run an Instat Calculation and Display Results}} +#' \item{\code{get_corresponding_link_columns(first_data_frame_name, first_data_frame_columns, second_data_frame_name)}{Get Corresponding Link Columns}} +#' \item{\code{get_link_columns_from_data_frames(first_data_frame_name, first_data_frame_columns, second_data_frame_name, second_data_frame_columns)}{Get Link Columns Between Data Frames}} +#' \item{\code{save_calc_output(calc, curr_data_list, previous_manipulations)}{Save the Output of a Calculation}} + + #' @export DataBook <- R6::R6Class("DataBook", public = list( @@ -258,7 +272,7 @@ DataBook <- R6::R6Class("DataBook", #' @param messages A boolean indicating whether to display messages. #' @param convert A boolean indicating whether to perform data conversion. #' @param create A boolean indicating whether to create new data objects. - + initialize = function(data_tables = list(), instat_obj_metadata = list(), data_tables_variables_metadata = rep(list(data.frame()), length(data_tables)), data_tables_metadata = rep(list(list()), length(data_tables)), @@ -4772,6 +4786,791 @@ DataBook <- R6::R6Class("DataBook", } }, + #' Apply a Calculation to Data in the DataBook + #' @description This method applies a given calculation to the data stored in the `DataBook` object. + #' It supports various calculation types (e.g., "summary") and includes options for storing + #' and returning results. + #' + #' @param calc A calculation object specifying the type of calculation and its parameters. + #' For a "summary" calculation, parameters should include: + #' - `data_name`: The name of the data object to apply the calculation to. + #' - `columns_to_summarise`: Columns to include in the summary. + #' - `summaries`: The summary operations to perform. + #' - `store_results`: Whether to store the results in the `DataBook`. + #' - `return_output`: Whether to return the summary output. + #' + #' @return If `return_output = TRUE`, returns the calculation results as a data frame; otherwise, + #' returns `NULL`. + apply_calculation = function(calc) { + if(calc$type == "summary") { + out <- self$get_data_objects(calc[["parameters"]][["data_name"]])$calculate_summary(calc = calc, ... = calc[["parameters"]][["..."]]) + if(calc[["parameters"]][["store_results"]]) self$append_summaries_to_data_object(out, calc[["parameters"]][["data_name"]], calc[["parameters"]][["columns_to_summarise"]], calc[["parameters"]][["summaries"]], calc[["parameters"]][["factors"]], calc[["parameters"]][["summary_name"]], calc) + if(calc[["parameters"]][["return_output"]]) return(out) + else return(NULL) + } + }, + + #' Save a Calculation to a Data Frame + #' + #' @description This method saves a calculation to a specific data frame within the `DataBook` object. + #' The calculation is stored in the designated data frame's calculation registry for + #' future reference and reuse. + #' + #' @param end_data_frame A string specifying the name of the data frame where the calculation + #' should be saved. + #' @param calc A calculation object or list that defines the calculation to be saved. + #' This object should include relevant parameters and metadata for the calculation. + #' + #' @return None. The method performs the operation in-place, saving the calculation to the + #' specified data frame. + #' + #' @details + #' - This method retrieves the `end_data_frame` from the `DataBook` object and invokes its + #' `save_calculation` method to store the calculation. + #' - The `calc` object typically includes details such as its `name`, `type`, and any parameters + #' or dependencies required to perform the calculation. + #' + #' @seealso \code{\link{DataSheet$save_calculation}} + #' + #' @note This method delegates the actual saving of the calculation to the respective + #' data frame's `save_calculation` method, ensuring modularity and separation of concerns. + save_calculation = function(end_data_frame, calc) { + self$get_data_objects(end_data_frame)$save_calculation(calc) + }, + + + #' Apply an Instat Calculation + #' + #' This method performs a calculation or series of calculations (including sub-calculations) on data + #' within the `DataBook` object. It supports recursive calls for managing dependencies between + #' manipulations and sub-calculations. + #' This method is called recursively, and it would not be called by a user, another function would always handle the output and display + #' results to the user (usually only the $data part of the list) + #' + #' @param calc A calculation object + #' @param curr_data_list A list of data objects currently being used. Optional. + #' @param previous_manipulations A list of previously applied manipulations, used recursively. Default is `list()`. + #' @param param_list A list of additional parameters for the calculation. Default is `list()`. + #' + #' @return A list with four elements: + #' - `$data`: A data frame containing the output from the calculation, usually not just the output but also other columns at the same "level" + #' - `$link`: A link used to determine which data frame the output should be saved in. + #' - `$has_summary`: Logical, whether a summary was performed. + #' - `$has_filter`: Logical, whether a filter was applied. + #' + #' @details + #' - **Manipulations**: Applied sequentially, with the output of one manipulation passed to the next. + #' - **Sub-Calculations**: Performed independently, with their outputs combined or merged as needed. + #' - **Recursive Behavior**: The method is called recursively for handling dependencies and grouping. + #' + apply_instat_calculation = function(calc, curr_data_list, previous_manipulations = list(), param_list = list()) { + # for our by calculation, read our drop parameter which is stored in param_list. This is read in + drop_value <- ifelse("drop" %in% names(param_list), param_list$drop, FALSE) + preserve_value <- ifelse("preserve" %in% names(param_list), param_list$preserve, FALSE) + + # apply each manipulation first, and recursively store the output and pass to the next manipulation + # because of this, manipulations are dependant on each other + for(manipulation in calc$manipulations) { + curr_data_list <- self$apply_instat_calculation(manipulation, curr_data_list, previous_manipulations, param_list = param_list) + previous_manipulations[[length(previous_manipulations) + 1]] <- manipulation + } + # If curr_data_list is not empty, (either an argument or from manipulations) + # then this is passed in to apply_instat_calculation for each sub_calculation + # sub_calculations are independant of each other (the order does not affect the output) + if(!missing(curr_data_list)) { + sub_calc_results <- curr_data_list + curr_groups <- groups(curr_data_list[[c_data_label]]) + } + else curr_groups <- c() + first_sub_calc <- TRUE + + for(sub_calc in calc$sub_calculations) { + curr_sub_calc <- self$apply_instat_calculation(sub_calc, curr_data_list, previous_manipulations, param_list = param_list) + if(first_sub_calc) { + sub_calc_results <- curr_sub_calc + first_sub_calc <- FALSE + } + else { + #### Set the require_merge logical + # Defined as variables as these are needed later + #overall_merge_required <- sub_calc_results[[c_require_merge_label]] + #current_calc_merge_required <- curr_sub_calc[[c_require_merge_label]] + overall_has_summary <- sub_calc_results[[c_has_summary_label]] + overall_has_filter <- sub_calc_results[[c_has_filter_label]] + current_calc_has_summary <- curr_sub_calc[[c_has_summary_label]] + current_calc_has_filter <- curr_sub_calc[[c_has_filter_label]] + + # A merge is required if a merge was already required, or if the current sub_calculation requires a merge + #sub_calc_results[[c_require_merge_label]] <- overall_merge_required || current_calc_merge_required + # TODO how to set new values for has summary/filter + + #### Set the data and link + # Defined as variables as these are used throughout + curr_calc_link_cols <- curr_sub_calc[[c_link_label]][["link_cols"]] + overall_calc_link_cols <- sub_calc_results[[c_link_label]][["link_cols"]] + curr_calc_from <- curr_sub_calc[[c_link_label]][["from_data_frame"]] + overall_calc_from <- sub_calc_results[[c_link_label]][["from_data_frame"]] + + # Warning if current sub calc result is already in the data + if(sub_calc$result_name %in% names(sub_calc_results[[c_data_label]])) warning(sub_calc$result_name, " is already a column in the existing data. The column will be replaced. This may have unintended consequences for the calculation") + + # If either calc is a single value summary we don't do a merge. + if((current_calc_has_summary && length(curr_calc_link_cols) == 0) || (overall_has_summary && length(overall_calc_link_cols) == 0)) { + # Don't think this needs to be done separately now + # If both calcs are single value summaries + # if(current_calc_has_summary && length(curr_calc_link_cols) == 0 && overall_has_summary && length(overall_calc_link_cols) == 0) { + # sub_calc_results[[c_data_label]] <- mutate(sub_calc_results[[c_data_label]], curr_sub_calc[[c_data_label]]) + # } + + # If curr_calc is a single value, add this on to overall data as new column + # QUESTION: Should there be checks here? This "works" with any two data frames + # because it's just adding a single value as a new column + if(current_calc_has_summary && length(curr_calc_link_cols) == 0) { + sub_calc_results[[c_data_label]][[sub_calc$result_name]] <- curr_sub_calc[[c_data_label]][[1]] + } + # If only overall is a single value, add this on to the current sub calc output + # QUESTION: Should there be checks here? This "works" with any two data frames + # because it's just adding a single value as a new column + else if(overall_has_summary && length(overall_calc_link_cols) == 0 && !(current_calc_has_summary && length(curr_calc_link_cols) == 0)) { + temp_data <- curr_sub_calc[[c_data_label]] + temp_data[[names(sub_calc_results[[c_data_label]])[1]]] <- sub_calc_results[[c_data_label]][[1]] + sub_calc_results[[c_data_label]] <- temp_data + sub_calc_results[[c_has_summary_label]] <- curr_sub_calc[[c_has_summary_label]] + sub_calc_results[[c_has_filter_label]] <- curr_sub_calc[[c_has_filter_label]] + sub_calc_results[[c_link_label]] <- curr_sub_calc[[c_link_label]] + #TODO Multiple links needed + # Above changes the from_data_frame. Is that what we want? + } + } + # In this case, both are simple calculations on the same data frame without filters + # So we just add a column instead of a merge. + else if(curr_calc_from == overall_calc_from && !overall_has_summary && !overall_has_filter && !current_calc_has_summary && !current_calc_has_filter) { + sub_calc_results[[c_data_label]][[sub_calc$result_name]] <- curr_sub_calc[[c_data_label]][[sub_calc$result_name]] + } + # Otherwise we must do a merge. + # If we can't do a merge, we stop here. + else { + # To be able to do a merge, a key in one of the DFs must be "equivalent" to a subset of a key in the other + # If the DF is a summary, then the link columns define the only key + if(overall_has_summary) { + overall_links <- list() + overall_links[[1]] <- overall_calc_link_cols + } + # Otherwise, there must be existing keys defined in the data frame + else { + if(!self$has_key(overall_calc_from)) stop("Cannot merge sub calculations as there is no key defined in ", overall_calc_from) + overall_links <- self$get_keys(overall_calc_from) + } + if(current_calc_has_summary) { + curr_calc_links <- list() + curr_calc_links[[1]] <- curr_calc_link_cols + } + else { + if(!self$has_key(curr_calc_from)) stop("Cannot merge sub calculations as there is no key defined in ", curr_calc_from) + curr_calc_links <- self$get_keys(curr_calc_from) + } + by <- NULL + for(temp_overall_link in overall_links) { + for(temp_curr_link in curr_calc_links) { + equ_overall_cols <- self$get_equivalent_columns(curr_calc_from, temp_curr_link, overall_calc_from) + if(length(equ_overall_cols) > 0 && all(equ_overall_cols %in% temp_overall_link)) { + by <- temp_curr_link + names(by) <- equ_overall_cols + join_into_overall <- TRUE + break + } + equ_curr_cols <- self$get_equivalent_columns(overall_calc_from, temp_overall_link, curr_calc_from) + if(length(equ_curr_cols) > 0 && all(equ_curr_cols %in% temp_curr_link)) { + by <- temp_overall_link + names(by) <- equ_curr_cols + join_into_overall <- FALSE + break + } + } + if(length(by) > 0) break + } + if(length(by) == 0) { + stop("Cannot find linking columns to merge output from sub calculations.") + } + + # If the data frames are the same and filters have been used then need to subset before the join + # so that we don't get duplicate columns + joined <- FALSE + if(curr_calc_from == overall_calc_from) { + if(overall_has_filter && current_calc_has_filter) { + # If both sub calcs have filter then the order of the rows in the output may not be sensible + # if filters are different but this case should be rare + # To avoid possibly losing data by subsetting columns we don't subset here and instead add to by columns + additional_cols <- intersect(names(sub_calc_results[[c_data_label]]), names(curr_sub_calc[[c_data_label]])) + additional_cols <- additional_cols[!additional_cols %in% by] + if(length(additional_cols) > 0) by <- c(by, additional_cols) + sub_calc_results[[c_data_label]] <- dplyr::full_join(curr_sub_calc[[c_data_label]], sub_calc_results[[c_data_label]], by = by) + joined <- TRUE + } + else if(overall_has_filter) { + # If the overall data has a filter and current does not, then we should merge the overall into the current + # We subset the current data to only have by and the output columns so that merge doesn't produce duplicate columns + # Overall sub data should be full data so we don't lose any data by subsetting the current sub calc + sub_calc_results[[c_data_label]] <- dplyr::full_join(curr_sub_calc[[c_data_label]][c(as.vector(by), sub_calc$result_name)], sub_calc_results[[c_data_label]], by = by) + # Current data has no filter so output now does not + sub_calc_results[[c_has_filter_label]] <- FALSE + joined <- TRUE + } + else if(current_calc_has_filter) { + # If the current data has a filter and overall does not, then we should merge the current into the overall + # We subset the current data to only have by and output columns so that merge doesn't produce duplicate columns + # Overall sub data should be full data so we don't lose any data by subsetting the current sub calc + sub_calc_cols <- as.vector(by) + if(sub_calc$result_name != "") sub_calc_cols <- c(sub_calc_cols, sub_calc$result_name) + sub_calc_results[[c_data_label]] <- dplyr::full_join(sub_calc_results[[c_data_label]], curr_sub_calc[[c_data_label]][sub_calc_cols], by = by) + # Overall data has no filter so output does even though current does + joined <- TRUE + } + } + if(!joined) { + if(join_into_overall) sub_calc_results[[c_data_label]] <- dplyr::full_join(sub_calc_results[[c_data_label]], curr_sub_calc[[c_data_label]], by = by) + else { + sub_calc_results[[c_data_label]] <- dplyr::full_join(curr_sub_calc[[c_data_label]], sub_calc_results[[c_data_label]], by = by) + # The overall data will be joined into the current sub calc, so this becomes the new link + sub_calc_results[[c_link_label]] <- curr_sub_calc[[c_link_label]] + } + } + } + } + } + + # If there were any sub_calculations then the input for the main calculation should be the output from the last sub_calculation + # Otherwise it is the output from the mainipulations + if(!first_sub_calc) curr_data_list <- sub_calc_results + + #TODO investigate better way to do this + # Any case where we don't want this? + # we want param_list to read into them all, not just "by", otherwise we lose our parameters here. + for(var in curr_groups) { + curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% group_by(dplyr::across({{ var }}), .add = TRUE, .drop = drop_value) + } + + # Names of the data frames required for the calculation + data_names <- unique(as.vector(names(calc$calculated_from))) + # If argument was missing and there were no manipulations or sub_calculations then it should be created. + if(missing(curr_data_list)) { + if(length(data_names) == 0) stop("No data specified for calculation.") + #else if(length(data_names) > 1) stop("Calculations from multiple data frame not yet implemented") + else { + curr_data_list <- list() + #TODO Add current filter as manipulation in calc definition if needed. + # The data is the data from the instat object based on data_names + curr_data_list[[c_data_label]] <- self$get_data_frame(data_names[[1]], use_current_filter = FALSE) + # The link has from_data_frame based on data_names and no current linking columns + link_list <- list(data_names[[1]], c()) + names(link_list) <- c("from_data_frame", "link_cols") + curr_data_list[[c_link_label]] <- link_list + # By default, a summary or filter has not been done + #curr_data_list[[c_require_merge_label]] <- FALSE + curr_data_list[[c_has_summary_label]] <- FALSE + curr_data_list[[c_has_filter_label]] <- FALSE + } + } + + col_names_exp = c() + col_names_exp_2 <- c() + i = 1 + # This checks that the columns specified in calculated_from appear in the current data + for(i in seq_along(calc$calculated_from)) { + col_name <- calc$calculated_from[[i]] + data_frame_name <- names(calc$calculated_from)[i] + overall_calc_from <- curr_data_list[[c_link_label]][["from_data_frame"]] + # TODO Is this a good check? + if(!(col_name %in% names(curr_data_list[[c_data_label]]))) { + if(curr_data_list[[c_has_summary_label]]) { + overall_links <- list() + overall_links[[1]] <- curr_data_list[[c_link_label]][["link_cols"]] + } + # Otherwise, there use the keys if they exist + else { + if(self$has_key(overall_calc_from)) { + overall_links <- self$get_keys(overall_calc_from) + } + else overall_links <- NULL + } + if(self$has_key(data_frame_name)) { + new_data_links <- self$get_keys(data_frame_name) + } + else new_data_links <- NULL + #TODO Make this it's own method? + by <- NULL + # Search for linking columns from overall_links + for(temp_overall_link in overall_links) { + equ_curr_cols <- self$get_equivalent_columns(overall_calc_from, temp_overall_link, data_frame_name) + if(length(equ_curr_cols) > 0) { # && all(equ_curr_cols %in% temp_curr_link)) { + by <- temp_overall_link + names(by) <- equ_curr_cols + join_into_overall <- FALSE + break + } + } + # If not found, search for linking columns from new_data_links + if(length(by) == 0) { + for(temp_curr_link in new_data_links) { + equ_overall_cols <- self$get_equivalent_columns(data_frame_name, temp_curr_link, overall_calc_from) + if(length(equ_overall_cols) > 0) { #&& all(equ_overall_cols %in% temp_overall_link)) { + by <- temp_curr_link + names(by) <- equ_overall_cols + join_into_overall <- TRUE + break + } + } + } + if(length(by) == 0) { + stop("Cannot find linking columns to merge output from sub calculations with data for calculated_from.") + } + if(join_into_overall){ + new_data_list <- self$get_data_frame(data_frame_name, use_current_filter = FALSE) + by_col_attributes <- list() + for(i in seq_along(by)) { + # Collect column attributes + by_col_attributes[[by[[i]]]] <- get_column_attributes(new_data_list[[by[[i]]]]) + + # Check and align the data types for each "by" column + if (class(new_data_list[[by[[i]]]]) != class(curr_data_list[[c_data_label]][[by[[i]]]])) { + warning(paste0("Type is different for ", by[[i]], " in the two data frames. Setting as numeric in both data frames.")) + + # Convert factors to numeric if necessary + if (class(new_data_list[[by[[i]]]]) == "factor") { + new_data_list[[by[[i]]]] <- as.numeric(as.character(new_data_list[[by[[i]]]])) + } else if (class(curr_data_list[[c_data_label]][[by[[i]]]]) == "factor") { + curr_data_list[[c_data_label]][[by[[i]]]] <- as.numeric(as.character(curr_data_list[[c_data_label]][[by[[i]]]])) + } else { + stop(paste0("Type is different for ", by[[i]], " in the two data frames and cannot be coerced.")) + } + } + } + curr_data_list[[c_data_label]] <- dplyr::full_join(curr_data_list[[c_data_label]], self$get_data_frame(data_frame_name, use_current_filter = FALSE), by = by) + } else { + curr_groups <- dplyr::groups(curr_data_list[[c_data_label]]) + curr_data_list[[c_data_label]] <- dplyr::full_join(self$get_data_frame(data_frame_name, use_current_filter = FALSE), curr_data_list[[c_data_label]], by = by) + #TODO investigate better way to do this + # Any case where we don't want this? + for(var in curr_groups) { + curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% dplyr::group_by(dplyr::across({{ var }}), .add = TRUE, .drop = drop_value) + } + # The overall data is joined into the current sub calc, so the curr_data_list is "reset" to default values + curr_data_list[[c_link_label]] <- list(from_data_frame = data_frame_name, link_cols = c()) + curr_data_list[[c_has_summary_label]] <- FALSE + curr_data_list[[c_has_filter_label]] <- FALSE + } + } + # This is a character vector containing the column names in a format that can be passed to dplyr functions using Standard Evalulation + col_names_exp[[i]] <- lazyeval::interp(~ var, var = as.name(col_name)) + col_names_exp_2[i] <- col_name + i = i + 1 + } + + # this type is adding a column to the data + # the data is at the same "level" so the link is unchanged + if(calc$type == "calculation") { + if(calc$result_name %in% names(curr_data_list[[c_data_label]])) warning(calc$result_name, " is already a column in the existing data. The column will be replaced. This may have unintended consequences for the calculation") + curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% + #dplyr::mutate_(.dots = setNames(list(as.formula(paste0("~", calc$function_exp))), calc$result_name)) + dplyr::mutate(!!as.name(calc$result_name) := !!rlang::parse_expr(calc$function_exp)) + + } + # this type performs a summary + # the data is not at a different "level" so the link is changed and link columns are the groups of the data before summarising + # A merge is now required because the data is at a different "level" + else if(calc$type == "summary") { + curr_data_list[[c_link_label]][["link_cols"]] <- as.character(dplyr::groups(curr_data_list[[c_data_label]])) + calc_from_data_name <- curr_data_list[[c_link_label]][["from_data_frame"]] + formula_fn_exp <- as.formula(paste0("~", calc$function_exp)) + # note: important that there is *no* space between | for grepl function + # and important there IS a psace in str_detect..! + + if (exists("col_name")){ + # get the data type of the column + col_data_type <- self$get_variables_metadata(data_name = calc_from_data_name, column = col_name, property = "class") + # if it is a ordered factor... + if (any(stringr::str_detect("ordered", col_data_type))){ + # put in here the ones that DO work for ordered factor + if (any(grepl("summary_count_non_missing|summary_count_missing|summary_n_distinct|summary_count|summary_min|summary_max|summary_range|summary_median|summary_quantile|p10|p20|p25|p30|p33|p40|p60|p67|p70|p75|p80|p90", formula_fn_exp))){ + curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% + dplyr::summarise(!!calc$result_name := !!rlang::parse_expr(calc$function_exp)) + } else { + curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% + #dplyr::summarise_(.dots = setNames(list(NA), calc$result_name)) + dplyr::summarise(!!calc$result_name := NA) + } + # if it is a factor or character, do not work for anything except... + } else if (any(stringr::str_detect("factor | character", col_data_type))){ + # put in here the ones that DO work for factor or character + if (any(grepl("summary_count_non_missing|summary_count_missing|summary_n_distinct|summary_count", formula_fn_exp))){ + curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% + dplyr::summarise(!!calc$result_name := !!rlang::parse_expr(calc$function_exp)) + } else { + curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% + dplyr::summarise(!!calc$result_name := NA) + } + } else if (any(stringr::str_detect("Date | POSIXct | POSIXt", col_data_type))){ + # put in here the ones that DO NOT work for date + if (any(grepl("summary_sum", formula_fn_exp))){ + curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% + dplyr::summarise(!!calc$result_name := NA) + } else { + curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% + dplyr::summarise(!!calc$result_name := !!rlang::parse_expr(calc$function_exp)) + } + } else { + curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% dplyr::summarise(!!calc$result_name := !!rlang::parse_expr(calc$function_exp)) + #curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% dplyr::summarise_(.dots = setNames(list(as.formula(paste0("~", calc$function_exp))), calc$result_name)) + } + } else{ + curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% dplyr::summarise(!!calc$result_name := !!rlang::parse_expr(calc$function_exp)) + } + curr_data_list[[c_has_summary_label]] <- TRUE + } + # This type is grouping the data + # The data remains unchanged so link and require merge remain unchanged + else if(calc$type == "by") { + curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% dplyr::group_by(dplyr::across({{ col_names_exp_2 }}), .add = TRUE, .drop = drop_value) + + #curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% dplyr::group_by_(.dots = col_names_exp, add = TRUE, .drop = FALSE) + } + # This type is sorting the data + # The rows are now in a different order so a merge is required + else if(calc$type == "sort") { + curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% dplyr::arrange(across({{ col_names_exp_2 }})) + #curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% dplyr::arrange_(.dots = col_names_exp) + curr_data_list[[c_has_filter_label]] <- TRUE + } + # This type is filtering the data + # The data is at the same "level" so the link is unchanged + # The rows are now different so a merge is required + else if(calc$type == "filter") { + curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% dplyr::filter(!!rlang::parse_expr(calc$function_exp), .preserve = preserve_value) + #curr_data_list[[c_data_label]] <- curr_data_list[[c_data_label]] %>% dplyr::filter_(.dots = as.formula(paste0("~", calc$function_exp))) + curr_data_list[[c_has_filter_label]] <- TRUE + } + # This type is when there is no main calculation but some sub_calculations + # There is no change to the data + else if(calc$type == "combination") {} + else stop("Cannot detect calculation type: ", calc$type) + + # This is done to clear the column attributes which are carried from the calculated columns + # TODO test this to check for any unintended side effects + # Seems only safe way to do this, as.vector can't be used on factor, Date etc. + if(calc$type == "calculation" || calc$type == "summary") { + result_col <- curr_data_list[[c_data_label]][[calc$result_name]] + for(att in names(attributes(result_col))[!names(attributes(result_col)) %in% c("levels", "class")]) { + attr(curr_data_list[[c_data_label]][[calc$result_name]], att) <- NULL + } + } + # if calc$save == 2 then column generated by calculation is saved into instat object and calc saved in to_data_frame + if(calc$save == 2) self$save_calc_output(calc, curr_data_list, previous_manipulations) + # if output is not saved the calculation can still be saved but now it is saved with the from_data_frame + # (to_data_frame may not exist) + else if(calc$save == 1) self$save_calculation(data_names, calc) + # list is returned so it can be used recursively for manipulations, sub_calculations etc. + return(curr_data_list) + }, + + + #' Run an Instat Calculation and Display Results + #' @description This method runs a specified calculation using `apply_instat_calculation` and + #' displays the results if required. It serves as the primary interface for + #' triggering calculations within the `DataBook`. + #' + #' @param calc A calculation object to be applied. + #' @param display Logical, whether to display the calculation output. Default is `TRUE`. + #' @param param_list A list of parameters to pass to the calculation. Default is `list()`. + #' + #' @return The `data` component of the calculation result if `display = TRUE`, otherwise `NULL`. + run_instat_calculation = function(calc, display = TRUE, param_list = list()) { + # param list has to be read in separately because of recursive nature of apply_instat_function. We want to ensure our param_list are in all calc()'s. + out <- self$apply_instat_calculation(calc, param_list = param_list) + if(display) return(out$data) + }, + + #' Get Corresponding Link Columns + #' + #' This function identifies corresponding link columns between two data frames + #' within the `DataBook` object. It checks for existing links and maps column + #' names between the two data frames based on their relationship. + #' + #' @param first_data_frame_name A string specifying the name of the first data frame. + #' @param first_data_frame_columns A vector of column names from the first data frame + #' to be mapped. + #' @param second_data_frame_name A string specifying the name of the second data frame. + #' + #' @return A named vector where the names represent the columns in the first data frame + #' and the values represent the corresponding columns in the second data frame. + #' + #' @details + #' - If a direct link exists between the two data frames, the corresponding columns + #' are determined based on the `link_columns` of the existing link. + #' - If no direct link exists, it defaults to a one-to-one mapping of the input columns + #' (`first_data_frame_columns`) in the first data frame. + #' + #' @note If the two data frames are not directly linked, the function assumes the columns + #' in the first data frame map directly to columns with the same names in the second data frame. + get_corresponding_link_columns = function(first_data_frame_name, first_data_frame_columns, second_data_frame_name) { + # TODO: Needs to update to not just look at direct links + by <- c() + if(self$link_exists_between(first_data_frame_name, second_data_frame_name)) { + existing_link <- self$get_link_between(first_data_frame_name, second_data_frame_name) + link_pairs <- unlist(existing_link$link_columns) + for(link_column in first_data_frame_columns) { + if(existing_link$from_data_frame == first_data_frame_name && existing_link$to_data_frame == second_data_frame_name) { + if(link_column %in% names(link_pairs)) { + by[link_column] <- link_pairs[which(names(link_pairs) == link_column)][1] + } + else by[link_column] <- link_column + } + else if(existing_link$from_data_frame == second_data_frame_name && existing_link$to_data_frame == first_data_frame_name) { + if(link_column %in% link_pairs) { + by[link_column] <- names(link_pairs)[which(link_pairs == link_column)][1] + } + else by[link_column] <- link_column + } + } + } + # If no link then do by by columns in first data frame + else { + by <- first_data_frame_columns + names(by) <- first_data_frame_columns + } + return(by) + }, + + #' Get Link Columns Between Data Frames + #' + #' @description This function finds a link between two data frames within the `DataBook` object and + #' returns the corresponding columns to use for linking. It ensures the link is valid + #' by checking that the columns exist in both data frames. + #' + #' @param first_data_frame_name A string specifying the name of the first data frame. + #' @param first_data_frame_columns A vector of column names from the first data frame to + #' be linked. + #' @param second_data_frame_name A string specifying the name of the second data frame. + #' @param second_data_frame_columns A vector of column names from the second data frame to + #' be linked. + #' + #' @return A named vector where the names represent the columns in the first data frame + #' and the values represent the corresponding columns in the second data frame. + #' + #' @details + #' - If a direct link exists between the data frames, the function checks for valid `link_columns` + #' in the `existing_link` object. + #' - A link is established if all columns in the specified `link_columns` exist in their + #' respective data frames. + #' - If no valid link is found, an empty vector is returned. + #' + #' @note This function ensures that the linking columns are valid by verifying + #' their existence in both data frames. + get_link_columns_from_data_frames = function(first_data_frame_name, first_data_frame_columns, second_data_frame_name, second_data_frame_columns) { + # finds a link between two data frames and returns named list used for by + # also checks link columns still are in both data frames + by = c() + if(self$link_exists_between(first_data_frame_name, second_data_frame_name)) { + existing_link <- self$get_link_between(first_data_frame_name, second_data_frame_name) + found <- FALSE + for(curr_link_set in existing_link$link_columns) { + if(existing_link$from_data_frame == first_data_frame_name && existing_link$to_data_frame == second_data_frame_name) { + if(all(curr_link_set %in% first_data_frame_columns) && all(names(curr_link_set) %in% second_data_frame_columns)) { + by <- curr_link_set + break + } + } + else if(existing_link$from_data_frame == second_data_frame_name && existing_link$to_data_frame == first_data_frame_name) { + if(all(curr_link_set %in% second_data_frame_columns) && all(names(curr_link_set) %in% first_data_frame_columns)) { + by <- names(curr_link_set) + names(by) <- curr_link_set + break + } + } + } + } + return(by) + }, + + #' Save the Output of a Calculation + #' + #' @description This method saves the output of a calculation to the appropriate data frame + #' within the `DataBook` object. It manages links and metadata associated with + #' the calculation. + #' + #' @param calc The calculation object. + #' @param curr_data_list The list of data objects containing the calculation output. + #' @param previous_manipulations A list of previous manipulations applied to the data. + #' + #' @details + #' - If the output data has a summary or filter applied, appropriate links are created or updated. + #' - Metadata is added to indicate that the column or data frame is the result of a calculation. + #' - Dependencies between columns are updated based on the calculation. + #' + #' @return None. + #' + save_calc_output = function(calc, curr_data_list, previous_manipulations) { + # Called from apply_instat_calculation if calc$save_calc == TRUE + + # Add previous manipulations to calc so that it can be rerun on its own (it may have been a sub calculation) + calc$manipulations <- c(previous_manipulations, calc$manipulations) + calc_dependencies <- calc$get_dependencies() + # Variables used throughout method + calc_from_data_name <- curr_data_list[[c_link_label]][["from_data_frame"]] + calc_link_cols <- curr_data_list[[c_link_label]][["link_cols"]] + + # Not sure this is correct. What if result is going into a differennt data frame? + if(calc$result_name %in% names(self$get_data_frame(calc_from_data_name))) warning(calc$result_name, " is already a column in the existing data. The column will be replaced by the output from the calculation. This may have unintended consequences for the calculation") + if(calc$result_data_frame != "") { + to_data_name <- calc$result_data_frame + if(to_data_name %in% names(self$get_data_names())) { + #TODO + } + else { + to_data_list <- list() + # Ensures that the to_data_name is a valid name + to_data_name <- calc$result_data_frame + to_data_name <- make.names(to_data_name) + to_data_name <- next_default_item(to_data_name, self$get_data_names(), include_index = FALSE) + # Subset to only get linking columns and result (don't want sub calcs as well, saved separately) + to_data_list[[to_data_name]] <- curr_data_list[[c_data_label]] + self$import_data(to_data_list) + to_data_exists <- TRUE + if(length(calc_link_cols) > 0) { + # Add the link to the new to_data_name + new_key <- calc_link_cols + names(new_key) <- calc_link_cols + self$add_link(calc_from_data_name, to_data_name, new_key, keyed_link_label) + # Add metadata to the linking columns + # This adds metadata: is_calculated = TRUE to the linking columns, which indicates that the column has been created by a calculation + self$append_to_variables_metadata(to_data_name, calc_link_cols, is_calculated_label, TRUE) + } + + # Adds metadata at data frame level to indicate that the data frame is calculated + # Note: all columns do not have to be calculated for data frame to be set as calculated + self$append_to_dataframe_metadata(to_data_name, is_calculated_label, TRUE) + } + } + else { + if(curr_data_list[[c_has_summary_label]]) { + # If there has been a summary, we look for an existing data frame that this could be linked to + link_def <- self$get_possible_linked_to_defintion(calc_from_data_name, calc_link_cols) + # If this is not empty then it is a list of two items: 1. the data frame to link to 2. the columns to link to + if(length(link_def) > 0) { + to_data_exists <- TRUE + to_data_name <- link_def[[1]] + # The check above only confirms it is possible to have a direct link to link_def[[1]] + # If there is not already a direct link between the data frames, we add one + if(!self$link_exists_from(calc_from_data_name, calc_link_cols)) { + link_pairs <- link_def[[2]] + names(link_pairs) <- calc_link_cols + self$add_link(calc_from_data_name, to_data_name, link_pairs, keyed_link_label) + } + # This is done so that calc$name can be used later and we know it won't be changed + # We can only do this check once we know the to_data_frame as this is where the calc is stored + if(calc$name %in% self$get_calculation_names(to_data_name)) { + calc$name <- next_default_item(calc$name, self$get_calculation_names(to_data_name)) + } + if(calc$result_name %in% self$get_column_names(to_data_name)) { + # Delete is needed because merge will not replace + # If not wanting to replace, this should be checked when calculation is defined. + warning("A column named ", calc$result_name, " already exists in ", to_data_name, ". It will be replaced by the output from the calculation.") + suppressWarnings(self$remove_columns_in_data(to_data_name, calc$result_name, TRUE)) + } + if(length(calc_link_cols) > 0) { + # merge_data merges into to_data_frame in instat object + # method takes care of data frame attributes correctly + # need to subset so that only the new column from this calc is added (not sub_calc columns as well as they have already been added if saved) + # type = "full" so that we do not lose any data from either part of the merge + by <- calc_link_cols + names(by) <- link_def[[2]] + self$get_data_objects(to_data_name)$merge_data(curr_data_list[[c_data_label]][c(calc_link_cols, calc$result_name)], by = by, type = "full") + } + else { + self$get_data_objects(to_data_name)$add_columns_to_data(calc$result_name, curr_data_list[[c_data_label]][calc$result_name], before = calc$before, adjacent_column = calc$adjacent_column) + } + } + else { + # If no link exists then the to_data_frame doesn't exist so output from calc becomes new to_data_frame + # and a link will be added to new to_data_frame + to_data_list <- list() + # Ensures that the to_data_name is a valid name that doesn't exist in list of current data frame names + to_data_name <- paste(calc_from_data_name, "by", paste(calc_link_cols, collapse = "_"), sep="_") + to_data_name <- make.names(to_data_name) + to_data_name <- next_default_item(to_data_name, self$get_data_names(), include_index = FALSE) + # Subset to only get linking columns and result (don't want sub calcs as well, saved separately) + to_data_list[[to_data_name]] <- curr_data_list[[c_data_label]][c(calc_link_cols, calc$result_name)] + self$import_data(to_data_list) + to_data_exists <- TRUE + # Add the link to the new to_data_frame + new_key <- calc_link_cols + names(new_key) <- calc_link_cols + self$add_link(calc_from_data_name, to_data_name, new_key, keyed_link_label) + + if(length(calc_link_cols) > 0) { + # Add metadata to the linking columns + # This adds metadata: is_calculated = TRUE to the linking columns, which indicates that the column has been created by a calculation + self$append_to_variables_metadata(to_data_name, calc_link_cols, is_calculated_label, TRUE) + } + + # Adds metadata at data frame level to indicate that the data frame is calculated + # Note: all columns do not have to be calculated for data frame to be set as calculated + self$append_to_dataframe_metadata(to_data_name, is_calculated_label, TRUE) + } + } + else if(curr_data_list[[c_has_filter_label]]) { + # If filter done and no summary done then to_data_frame == from_data_frame + # to do the join there must be a key defined in from dataframe because output may have a subset of rows of original data + # TODO should we still add a link in this case? + to_data_name <- calc_from_data_name + # If the data frame has keys defined then we use get_link_columns_from_data_frames to find the by + if(self$has_key(calc_from_data_name)) { + by <- self$get_link_columns_from_data_frames(calc_from_data_name, names(curr_data_list[[c_data_label]]), calc_from_data_name, self$get_column_names(calc_from_data_name)) + # subset to only get output and key columns, do not want sub_calculation or extra columns to be merged as well + #TODO If by = NULL should we try the merge with a warning or just stop? + if(length(by) == 0) stop("Cannot save output because the key columns are not present in the calculation output") + self$get_data_objects(calc_from_data_name)$merge_data(curr_data_list[[c_data_label]][c(as.vector(by), calc$result_name)], by = by, type = "full") + } + # Cannot do merge if the data frame has no keys defined + else { + #TODO Should we try the merge? + stop("Cannot save output from this calculation because the data frame does not have any defined keys.") + } + } + else { + # If no summary or join, then simply add result as new column + # Because no join was required, the rows should match 1-1 in both data frames + self$add_columns_to_data(data_name = calc_from_data_name, col_name = calc$result_name, col_data = curr_data_list[[c_data_label]][[calc$result_name]], before = calc$before, adjacent_column = calc$adjacent_column) + to_data_name <- calc_from_data_name + if(calc$name %in% self$get_calculation_names(to_data_name)) { + calc$name <- next_default_item(calc$name, self$get_calculation_names(to_data_name)) + } + } + } + + # Add metadata for the new column + output_column <- calc$result_name + names(output_column) <- to_data_name + # Add metadata to calculated_from columns + # for example, calculated_from may include sub_calculation columns which were not saved and so don't appear in the instat object data + for(i in seq_along(calc_dependencies)) { + # This adds metadata: has_dependants = TRUE which indicates that the calculated_from columns have columns that depend on them + self$append_to_variables_metadata(names(calc_dependencies[i]), calc_dependencies[[i]], has_dependants_label, TRUE) + # This adds the output_column to the calculated_from columns' list of dependent columns + self$add_dependent_columns(names(calc_dependencies[i]), calc_dependencies[[i]], output_column) + } + # This adds metadata: is_calculated = TRUE to the output column, which indicates that the column has been created by a calculation + if(calc$result_name != "") { + self$append_to_variables_metadata(to_data_name, calc$result_name, is_calculated_label, TRUE) + + # This adds metadata: dependencies to the output column with value, a list of the calculated_from columns + if(length(calc_dependencies) > 0) self$append_to_variables_metadata(to_data_name, calc$result_name, dependencies_label, calc_dependencies) + # This adds metadata: calculated_by to the output column, with value as the name of the calculation + self$append_to_variables_metadata(to_data_name, calc$result_name, calculated_by_label, calc$name) + } + self$save_calculation(to_data_name, calc) + }, + + #' Import SST #' @description Imports SST data and adds keys and links to the specified data tables. #' @param dataset The SST dataset. diff --git a/man/DataBook.Rd b/man/DataBook.Rd index 9128684..fa0a491 100644 --- a/man/DataBook.Rd +++ b/man/DataBook.Rd @@ -21,6 +21,25 @@ DataBook$new(data_tables = list(), instat_obj_metadata = list(), \description{ An R6 class to manage a collection of data tables along with their metadata and other associated properties. } +\note{ +This method delegates the actual saving of the calculation to the respective +data frame's \code{save_calculation} method, ensuring modularity and separation of concerns. +Apply an Instat Calculation + +This method performs a calculation or series of calculations (including sub-calculations) on data +within the \code{DataBook} object. It supports recursive calls for managing dependencies between +manipulations and sub-calculations. +This method is called recursively, and it would not be called by a user, another function would always handle the output and display +results to the user (usually only the $data part of the list) + +If the two data frames are not directly linked, the function assumes the columns +in the first data frame map directly to columns with the same names in the second data frame. +Get Link Columns Between Data Frames + +This function ensures that the linking columns are valid by verifying +their existence in both data frames. +Save the Output of a Calculation +} \section{Methods}{ \describe{ @@ -219,11 +238,13 @@ An R6 class to manage a collection of data tables along with their metadata and \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.} +\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.}from instat_comment.R in R-Instat + \item{\code{add_comment(new_comment)}}{Adds a new \code{instat_comment} object to the data sheet if the key is defined and valid.} \item{\code{delete_comment(comment_id)}}{Deletes a comment from the data sheet based on the comment ID.} \item{\code{get_comment_ids()}}{Retrieves all comment IDs currently stored in the data sheet.} -\item{\code{get_comments_as_data_frame()}}{Converts all comments in the data sheet to a data frame format for easier inspection and analysis.} +\item{\code{get_comments_as_data_frame()}}{Converts all comments in the data sheet to a data frame format for easier inspection and analysis.}from link.R in R-Instat + \item{\code{update_links_rename_data_frame(old_data_name, new_data_name)}}{This function updates all links that reference a data frame with a specified old name, renaming it to a new name.} \item{\code{update_links_rename_column(data_name, old_column_name, new_column_name)}}{This function updates all links referencing a column in a data frame with a specified old column name, renaming it to a new column name.} \item{\code{add_link(from_data_frame, to_data_frame, link_pairs, type, link_name)}}{This function adds a new link between two data frames with the specified link pairs and type. It will check if the link already exists or if the link columns are keys.} @@ -237,11 +258,21 @@ An R6 class to manage a collection of data tables along with their metadata and \item{\code{get_possible_linked_to_definition(from_data_frame, link_pairs)}}{This function attempts to find a linked data frame that matches \code{link_pairs}. Recursively explores links between multiple data frames.} \item{\code{get_equivalent_columns(from_data_name, columns, to_data_name)}}{This function returns columns in \code{to_data_name} equivalent to \code{columns} in \code{from_data_name}. Recursively searches links between multiple data frames.} \item{\code{link_between_containing(from_data_frame, containing_columns, to_data_frame)}}{This function returns columns in \code{to_data_frame} corresponding to \code{containing_columns} in \code{from_data_frame} if a link exists between them.} -\item{\code{view_link(link_name)}}{Displays the details of a specified link.} - +\item{\code{view_link(link_name)}}{Displays the details of a specified link.}from calculations.R in R-Instat + +\item{\code{apply_calculation(calc)}{Apply a Calculation to Data in the DataBook}} +\item{\code{save_calculation(end_data_frame, calc)}{Save a Calculation to a Data Frame}} +\item{\code{apply_instat_calculation(calc, curr_data_list, previous_manipulations = list(), param_list = list())}{Apply an Instat Calculation}} +\item{\code{run_instat_calculation(calc, display = TRUE, param_list = list())}{Run an Instat Calculation and Display Results}} +\item{\code{get_corresponding_link_columns(first_data_frame_name, first_data_frame_columns, second_data_frame_name)}{Get Corresponding Link Columns}} +\item{\code{get_link_columns_from_data_frames(first_data_frame_name, first_data_frame_columns, second_data_frame_name, second_data_frame_columns)}{Get Link Columns Between Data Frames}} +\item{\code{save_calc_output(calc, curr_data_list, previous_manipulations)}{Save the Output of a Calculation}} @export } +\seealso{ +\code{\link{DataSheet$save_calculation}} +} \section{Public fields}{ \if{html}{\out{
}} \describe{ @@ -481,6 +512,13 @@ An R6 class to manage a collection of data tables along with their metadata and \item \href{#method-DataBook-get_equivalent_columns}{\code{DataBook$get_equivalent_columns()}} \item \href{#method-DataBook-link_between_containing}{\code{DataBook$link_between_containing()}} \item \href{#method-DataBook-view_link}{\code{DataBook$view_link()}} +\item \href{#method-DataBook-apply_calculation}{\code{DataBook$apply_calculation()}} +\item \href{#method-DataBook-save_calculation}{\code{DataBook$save_calculation()}} +\item \href{#method-DataBook-apply_instat_calculation}{\code{DataBook$apply_instat_calculation()}} +\item \href{#method-DataBook-run_instat_calculation}{\code{DataBook$run_instat_calculation()}} +\item \href{#method-DataBook-get_corresponding_link_columns}{\code{DataBook$get_corresponding_link_columns()}} +\item \href{#method-DataBook-get_link_columns_from_data_frames}{\code{DataBook$get_link_columns_from_data_frames()}} +\item \href{#method-DataBook-save_calc_output}{\code{DataBook$save_calc_output()}} \item \href{#method-DataBook-import_SST}{\code{DataBook$import_SST()}} \item \href{#method-DataBook-clone}{\code{DataBook$clone()}} } @@ -6540,10 +6578,273 @@ Displays the details of a specified link. \if{html}{\out{
}} \describe{ \item{\code{link_name}}{The name of the link to view -Import SST} +Apply a Calculation to Data in the DataBook} +} +\if{html}{\out{
}} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DataBook-apply_calculation}{}}} +\subsection{Method \code{apply_calculation()}}{ +This method applies a given calculation to the data stored in the \code{DataBook} object. +It supports various calculation types (e.g., "summary") and includes options for storing +and returning results. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{DataBook$apply_calculation(calc)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{calc}}{A calculation object specifying the type of calculation and its parameters. +For a "summary" calculation, parameters should include: +- \code{data_name}: The name of the data object to apply the calculation to. +- \code{columns_to_summarise}: Columns to include in the summary. +- \code{summaries}: The summary operations to perform. +- \code{store_results}: Whether to store the results in the \code{DataBook}. +- \code{return_output}: Whether to return the summary output.} } \if{html}{\out{
}} } +\subsection{Returns}{ +If \code{return_output = TRUE}, returns the calculation results as a data frame; otherwise, +returns \code{NULL}. +Save a Calculation to a Data Frame +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DataBook-save_calculation}{}}} +\subsection{Method \code{save_calculation()}}{ +This method saves a calculation to a specific data frame within the \code{DataBook} object. +The calculation is stored in the designated data frame's calculation registry for +future reference and reuse. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{DataBook$save_calculation(end_data_frame, calc)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{end_data_frame}}{A string specifying the name of the data frame where the calculation +should be saved.} + +\item{\code{calc}}{A calculation object or list that defines the calculation to be saved. +This object should include relevant parameters and metadata for the calculation.} +} +\if{html}{\out{
}} +} +\subsection{Details}{ +\itemize{ +\item This method retrieves the \code{end_data_frame} from the \code{DataBook} object and invokes its +\code{save_calculation} method to store the calculation. +\item The \code{calc} object typically includes details such as its \code{name}, \code{type}, and any parameters +or dependencies required to perform the calculation. +} +} + +\subsection{Returns}{ +None. The method performs the operation in-place, saving the calculation to the +specified data frame. +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DataBook-apply_instat_calculation}{}}} +\subsection{Method \code{apply_instat_calculation()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{DataBook$apply_instat_calculation( + calc, + curr_data_list, + previous_manipulations = list(), + param_list = list() +)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{calc}}{A calculation object} + +\item{\code{curr_data_list}}{A list of data objects currently being used. Optional.} + +\item{\code{previous_manipulations}}{A list of previously applied manipulations, used recursively. Default is \code{list()}.} + +\item{\code{param_list}}{A list of additional parameters for the calculation. Default is \code{list()}.} +} +\if{html}{\out{
}} +} +\subsection{Details}{ +\itemize{ +\item \strong{Manipulations}: Applied sequentially, with the output of one manipulation passed to the next. +\item \strong{Sub-Calculations}: Performed independently, with their outputs combined or merged as needed. +\item \strong{Recursive Behavior}: The method is called recursively for handling dependencies and grouping. +} + +Run an Instat Calculation and Display Results +} + +\subsection{Returns}{ +A list with four elements: +\itemize{ +\item \verb{$data}: A data frame containing the output from the calculation, usually not just the output but also other columns at the same "level" +\item \verb{$link}: A link used to determine which data frame the output should be saved in. +\item \verb{$has_summary}: Logical, whether a summary was performed. +\item \verb{$has_filter}: Logical, whether a filter was applied. +} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DataBook-run_instat_calculation}{}}} +\subsection{Method \code{run_instat_calculation()}}{ +This method runs a specified calculation using \code{apply_instat_calculation} and +displays the results if required. It serves as the primary interface for +triggering calculations within the \code{DataBook}. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{DataBook$run_instat_calculation(calc, display = TRUE, param_list = list())}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{calc}}{A calculation object to be applied.} + +\item{\code{display}}{Logical, whether to display the calculation output. Default is \code{TRUE}.} + +\item{\code{param_list}}{A list of parameters to pass to the calculation. Default is \code{list()}.} +} +\if{html}{\out{
}} +} +\subsection{Returns}{ +The \code{data} component of the calculation result if \code{display = TRUE}, otherwise \code{NULL}. +Get Corresponding Link Columns + +This function identifies corresponding link columns between two data frames +within the \code{DataBook} object. It checks for existing links and maps column +names between the two data frames based on their relationship. +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DataBook-get_corresponding_link_columns}{}}} +\subsection{Method \code{get_corresponding_link_columns()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{DataBook$get_corresponding_link_columns( + first_data_frame_name, + first_data_frame_columns, + second_data_frame_name +)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{first_data_frame_name}}{A string specifying the name of the first data frame.} + +\item{\code{first_data_frame_columns}}{A vector of column names from the first data frame +to be mapped.} + +\item{\code{second_data_frame_name}}{A string specifying the name of the second data frame.} +} +\if{html}{\out{
}} +} +\subsection{Details}{ +\itemize{ +\item If a direct link exists between the two data frames, the corresponding columns +are determined based on the \code{link_columns} of the existing link. +\item If no direct link exists, it defaults to a one-to-one mapping of the input columns +(\code{first_data_frame_columns}) in the first data frame. +} +} + +\subsection{Returns}{ +A named vector where the names represent the columns in the first data frame +and the values represent the corresponding columns in the second data frame. +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DataBook-get_link_columns_from_data_frames}{}}} +\subsection{Method \code{get_link_columns_from_data_frames()}}{ +This function finds a link between two data frames within the \code{DataBook} object and +returns the corresponding columns to use for linking. It ensures the link is valid +by checking that the columns exist in both data frames. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{DataBook$get_link_columns_from_data_frames( + first_data_frame_name, + first_data_frame_columns, + second_data_frame_name, + second_data_frame_columns +)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{first_data_frame_name}}{A string specifying the name of the first data frame.} + +\item{\code{first_data_frame_columns}}{A vector of column names from the first data frame to +be linked.} + +\item{\code{second_data_frame_name}}{A string specifying the name of the second data frame.} + +\item{\code{second_data_frame_columns}}{A vector of column names from the second data frame to +be linked.} +} +\if{html}{\out{
}} +} +\subsection{Details}{ +\itemize{ +\item If a direct link exists between the data frames, the function checks for valid \code{link_columns} +in the \code{existing_link} object. +\item A link is established if all columns in the specified \code{link_columns} exist in their +respective data frames. +\item If no valid link is found, an empty vector is returned. +} +} + +\subsection{Returns}{ +A named vector where the names represent the columns in the first data frame +and the values represent the corresponding columns in the second data frame. +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DataBook-save_calc_output}{}}} +\subsection{Method \code{save_calc_output()}}{ +This method saves the output of a calculation to the appropriate data frame +within the \code{DataBook} object. It manages links and metadata associated with +the calculation. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{DataBook$save_calc_output(calc, curr_data_list, previous_manipulations)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{calc}}{The calculation object.} + +\item{\code{curr_data_list}}{The list of data objects containing the calculation output.} + +\item{\code{previous_manipulations}}{A list of previous manipulations applied to the data.} +} +\if{html}{\out{
}} +} +\subsection{Details}{ +\itemize{ +\item If the output data has a summary or filter applied, appropriate links are created or updated. +\item Metadata is added to indicate that the column or data frame is the result of a calculation. +\item Dependencies between columns are updated based on the calculation. +} +} + +\subsection{Returns}{ +None. + +Import SST +} } \if{html}{\out{
}} \if{html}{\out{}}