diff --git a/R/DisplayDaily.R b/R/DisplayDaily.R new file mode 100644 index 0000000..9b2de0a --- /dev/null +++ b/R/DisplayDaily.R @@ -0,0 +1,330 @@ +#' Display Daily Meteorological Data +#' +#' @description +#' Display daily meteorological data in a readable table format. +#' This function was developed by Helen Greatrex as part of the SSC-RCLIM package. It formats daily meteorological data for easy viewing, displaying values for each day of the month and summarising monthly statistics. The function is similar in display format to the INSTAT "DisplayDaily" feature. +#' +#' @param Datain A data frame containing meteorological data, with one column for each variable, one row for each date, and the following columns (case-sensitive): +#' - `Station`: names or identifiers for stations +#' - EITHER: a `Date` column (yyyy-mm-dd format, `option = 1`) +#' - OR: separate `Year`, `Month`, and `Day` columns (`option = 2`) +#' @param Stations A character vector of station names to view (e.g., `"KUND0002"`, `c("Paris", "London")`). If missing, all stations in `Datain` are selected. +#' @param Variables A character vector of column names for the variables to display (e.g., `"Rain"`, `"TMin"`, `"RH"`). If missing, all variables except metadata columns are selected. +#' @param option An integer (1 or 2) indicating date format: +#' - `1`: `Date` column format (yyyy-mm-dd) +#' - `2`: separate `Year`, `Month`, and `Day` columns. +#' @param Years An integer vector of years to view (default is all years in `Datain`). +#' @param Misscode Character string representing the display value for missing data (e.g., "-"). +#' @param Tracecode Character string for trace amounts of rainfall (default "tr"). +#' @param Zerocode Character string for zero values (default "--"). +#' @param Fileout Optional file path for saving the output table. If `NA`, results are printed to the console. +#' @param monstats A character vector of monthly statistics to compute, options include `"min"`, `"mean"`, `"median"`, `"max"`, `"IQR"`, and `"sum"`. +#' +#' @return This function prints a formatted daily table for each specified station, variable, and year. If a file path is specified in `Fileout`, the output is saved to that file. +#' +#' @details +#' This function checks for the presence of required columns and renames variables as needed to ensure compatibility with the `Datain` format. Missing data, trace rainfall, and zero values are replaced with user-defined codes. Monthly statistics are computed for each month. The function fills in any missing dates within the specified range for seamless daily reporting. +DisplayDaily <- function(Datain,Stations,Variables,option=1,Years,Misscode,Tracecode,Zerocode,Fileout=NA,monstats=c("min","mean","median","max","IQR","sum")){ + #-----------------------------------------------------------------------# + # Helen Greatrex, SSC, SSC-RCLIM package # + # # + # DisplayDaily: This function displays daily meteorological data in an # + # easy to view format # + # # + # INPUTS # + # Datain :This is the name of the data.frame containing your data # + # The format of this data.frame is discussed in the details # + # section of this help file # + # # + # Stations: This is the name of the weather station(s) you wish to view # + # e.g. "KUND0002", or c("Paris","London") # + # It is case sensitive and the stations should be values # + # in the Station column of your data.frame. This is set by # + # default to all stations in the data.frame # + # # + # Variables:This is name of the column of data you wish to view # + # e.g.Rain, TMin, RH. It is also case sensitive. This is set # + # default to all variables in the data.frame # + # # + # Option: Set to 1 if you have a column entitled Date, which contains # + # dates in the format yyyy-mm-dd. Set to 2 if you have a # + # column entitled Year, one entitled Month and one entitled # + # Day # + # # + # Years: A number or vector of the year(s) you would like to view # + # This is set by default to all years # + # # + # Months: A number or vector of the month(s) you would like to view # + # This is set by default to all months. This option has been # + # removed as it does not overlap to new years # + # # + # Misscode: This is the how you would like to display missing values # + # It is set by default to "-" # + # # + # Tracecode:This is the how you would like to display trace rainfall # + # values. It is set by default to "tr" # + # # + # Zerocode: This is the how you would like to display zero rainfall # + # values. It is set by default to "--" # + # # + # File: Would you like to view the results on the screen or print # + # them to a file. By default this prints to the screen, # + # If you want to print to a file, set this to a character # + # string with the filename (and path if needed) # + # # + # DETAILS # + # This function prints out daily data in an easy to view format, # + # similar to INSTAT's DisplayDaily button. # + # # + # Your input data.frame should have one column for each variable, one # + # row for each date and include the following columns (case sensitive) # + # # + # Station - containing your station names or identifier # + # # + # EITHER (set option = 1) # + # Date - containing a list of dates in the format yyyy-mm-dd # + # OR (set option = 2) # + # Year - containing a list of years in the format yyyy # + # Month - containing a list of months # + # Day - containing a list of days of month (from 1-31) # + # # + # A column for the variable you wish to study e.g. Rain, TMax, RH, ... # + # # + # Note, an experienced R user might wonder why I have not used the # + # options in print as much as I might have. This is because often # + # trace rainfall values need to be displayed as text, which messes up # + # the print function's missing/zero value options # + #-----------------------------------------------------------------------# + + #-----------------------------------------------------------------------# + # First, check that appropriate inputs exist # + #-----------------------------------------------------------------------# + if(missing(Datain)==TRUE){stop("Please enter an input data.frame")} + if(missing(Stations)==TRUE){Stations <- unique(Datain$Station)} + if(missing(Years)==TRUE){Years <- unique(Datain$Year)} + if(missing(Variables)==TRUE){ + Variables <- names(Datain) + Variables <- Variables[!(Variables %in% c("Key","Station","Date","Year","Month","Day","UserDOY"))] + if(length(Variables) <= 0){ + stop("Please indicate which column name you would like to display") + } + } + flag=0 + Months <- 1:12 + #-----------------------------------------------------------------------# + # Loop through the stations # + #-----------------------------------------------------------------------# + for (s in 1:length(Stations)){ + #-------------------------------------------------------------------# + # Does the selected station exist? # + #-------------------------------------------------------------------# + tmp <- Datain[(as.character(Datain$Station) == Stations[s]),] + + #-------------------------------------------------------------------# + # Stop the function if not # + #-------------------------------------------------------------------# + if(length(tmp[,1]) <= 0){ + print(paste("The function could not find your chosen station: '",Stations[s],"'",sep=""),quote=FALSE) + print("Possible choices in the Station column of selected data.frame are",quote=FALSE) + print(unique(Datain$Station)) + stop("Choose a station that exists in your data.frame") + } + + #-------------------------------------------------------------------# + # Loop through the variables # + #-------------------------------------------------------------------# + for(v in 1:length(Variables)){ + #--------------------------------------------------------------# + # Does the selected variable exist? # + #--------------------------------------------------------------# + if(!(Variables[v] %in% names(tmp))){ + print(paste("There is no column in your data.frame called '", Variables[v],"'",sep=""),quote=FALSE) + print("Please choose out of",quote=FALSE) + print(as.character(names(tmp))) + stop() + } + + #-------------------------------------------------------------# + # Now move on to years. First, fill in any missing dates # + #-------------------------------------------------------------# + if(option == 1){ + startday <- as.Date(paste(min(as.numeric(format.Date(tmp$Date,"%Y")),na.rm=TRUE),1,1,sep="-")) + endday <- as.Date(paste(max(as.numeric(format.Date(tmp$Date,"%Y")),na.rm=TRUE),12,31,sep="-")) + tmp$TEMPDate2 <- as.Date(tmp$Date) + tmp$Date <- as.Date(tmp$Date) + }else{ + startday <- as.Date(paste(min(tmp$Year,na.rm=TRUE),1,1,sep="-")) + endday <- as.Date(paste(max(tmp$Year,na.rm=TRUE),12,31,sep="-")) + tmp$TEMPDate2 <- as.Date(paste(tmp$Year,tmp$Month,tmp$Day,sep="-")) + tmp$Date <- as.Date(tmp$Date) + } + + newdatain <- data.frame(Date = seq(from=startday,to= endday,by="d")) + new <- merge(newdatain,tmp,by="Date",all.x=TRUE,all.y=TRUE) + # removes NA rows + new <- new[!is.na(new$TEMPDate2), ] + loc <- which(names(new)== Variables[v]) + + # newdates <- seq(startday,endday,1) + # new <- as.data.frame(matrix(nrow=length(newdates),ncol=dim(tmp)[2])) + # names(new) <- names(tmp) + # new$TEMPDate2 <- newdates + + # tmpmatch <- match(tmp$TEMPDate2,new$TEMPDate2) + # new[tmpmatch,(1:(dim(new)[2]-1))] <- tmp[,(1:(dim(new)[2]-1))] + + # new <- m + + #-------------------------------------------------------------# + # Rename things like the Station name # + #-------------------------------------------------------------# + new$Station <- Stations[s] + + #-------------------------------------------------------------# + # Now start to display the data # + # First, make an output template # + #-------------------------------------------------------------# + template <- as.data.frame(matrix(nrow=32,ncol=(1+length(Months)))) + names(template) <- c("MONTH",month.abb[Months]) + template[1,] <- "****" + template[,1] <- c("DAY",1:31) + + statstemplate <- as.data.frame(matrix(ncol=(1+length(Months)),nrow=length(monstats))) + names(statstemplate) <- names(template) + statstemplate[,1] <- monstats + + + for(y in 1:length(Years)){ + #----------------------------------------------------------# + # Print out header # + #----------------------------------------------------------# + print(" ",quote=FALSE) + print(paste("STATION : '",Stations[s],"'",sep=""),quote=FALSE) + print(paste("VARIABLE : '",Variables[v],"'",sep=""),quote=FALSE) + print(paste("YEAR :",Years[y]),quote=FALSE) + + #----------------------------------------------------------# + # And set up the template/subset the data for that year # + #----------------------------------------------------------# + out <- template + outstats <- statstemplate + tmp2 <- new[as.numeric(format.Date(new$TEMPDate2,"%Y")) == Years[y],] + + #----------------------------------------------------------# + # Now, put into the data.frame for each month.. # + #----------------------------------------------------------# + for(m in 1:length(Months)){ + dat <- tmp2[as.numeric(format.Date(tmp2$TEMPDate2,"%m")) == Months[m],] + + for(st in 1:length(monstats)){ + if(length(eval(parse(text=paste("suppressWarnings(",monstats[st],"(dat[,loc],na.rm=TRUE))"))))> 1){ + outstats[,(m+1)] <- "NA" + if(m == 1){ + print("",quote=FALSE) + print("*********",quote=FALSE) + print(paste("The '", monstats[st],"' statistic has more than one value in its output, e.g.",sep=""),quote=FALSE) + print(eval(parse(text=paste("suppressWarnings(",monstats[st],"(dat[,loc],na.rm=TRUE))"))),quote=FALSE) + print("therefore it has been ignored",quote=FALSE) + print("",quote=FALSE) + } + }else{ + outstats[st,(m+1)] <- as.character(sprintf("%12.1f",eval(parse(text=paste("suppressWarnings(",monstats[st],"(dat[,loc],na.rm=TRUE))"))))) + outstats[st,(m+1)] <- gsub("\\s+","",outstats[st,(m+1)]) + } + } + # If all the data is NA, set the stats to NA (except summary_count_missing) + if(length(dat[,loc])==length(which(is.na(dat[,loc]==TRUE)))){ + outstats[which(monstats != "summary_count_missing"),(m+1)] <- "NA" + } + # If there's no data, set all the stats to NA + if(length(dat[,loc]) == 0) outstats[,(m+1)] <- "NA" + #-------------------------------------------------------# + # Set to 2 d.p. # + #-------------------------------------------------------# + dat[is.na(dat[,loc])==FALSE,loc] <- as.character(sprintf("%12.2f",dat[is.na(dat[,loc])==FALSE,loc])) + + #-------------------------------------------------------# + # Deal with trace rainfall values # + #-------------------------------------------------------# + tmptrace <- which(dat[,loc] == "0.01") + if(length(tmptrace) > 0 && !missing(Tracecode)){ + dat[tmptrace,loc] <- Tracecode + } + + #-------------------------------------------------------# + # Set to 1 d.p. and remove spaces # + #-------------------------------------------------------# + dat[,loc] <- substr(dat[,loc],1,nchar(dat[,loc])-1) + dat[,loc] <- gsub("\\s+","",dat[,loc]) + + #-------------------------------------------------------# + # Deal with missing values (exc non existant dates) # + #-------------------------------------------------------# + tmpmiss <- which(is.na(dat[,loc]) == TRUE) + if(length(tmpmiss) > 0 && !missing(Misscode)){ + dat[tmpmiss,loc] <- Misscode + } + + #-------------------------------------------------------# + # Deal with zero values (exc non existant dates) # + #-------------------------------------------------------# + tmpzero <- which(dat[,loc] == "0.0") + if(length(tmpzero) > 0 && !missing(Zerocode)){ + dat[tmpzero,loc] <- Zerocode + } + tmpzero <- which(outstats[,(m+1)] == "0.0") + if(length(tmpzero) > 0){ + outstats[tmpzero,(m+1)] <- "0" + } + #-------------------------------------------------------# + # And put into the display data.frame # + #-------------------------------------------------------# + dat$TEMPday <- as.numeric(format.Date(dat$TEMPDate2,"%d")) + out[2:32,(m+1)] <- dat[match(1:31,dat$TEMPday),loc] + }#m + + #----------------------------------------------------------# + # Add the statistics onto the main data.frame # + #----------------------------------------------------------# + out[dim(out)[1]+1,] <- "____" + out[dim(out)[1],1] <- "STATS" + # temp fix to shorten display name of summary function + outstats[,1][outstats[,1] == "summary_count_missing"] <- "n_miss" + out <- rbind(out,outstats) + + #----------------------------------------------------------# + # Set non existant dates to be blank and display # + #----------------------------------------------------------# + out[is.na(out) == TRUE] <- " " + print(out,quote=FALSE,justify="right",row.names=F,digits=1) + print(" ",quote=FALSE) + + #----------------------------------------------------------# + # Write to file if requested # + #----------------------------------------------------------# + if(is.na(Fileout) == FALSE){ + if(flag==0){ + fileoutput <- file(Fileout, "w") + flag = 1 + cat(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) + }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) + } + } + rm(tmp2) + rm(out) + }#y + }#v + }#s + if(is.na(Fileout) == FALSE){ + close(fileoutput) + } +} #end of function \ No newline at end of file diff --git a/R/data_book.R b/R/data_book.R index dd6468d..6e72a42 100644 --- a/R/data_book.R +++ b/R/data_book.R @@ -210,8 +210,7 @@ #' \item{\code{wrap_or_unwrap_data(data_name, col_name, column_data, width, wrap = TRUE)}}{Wraps or unwraps the specified column data in the given data table to the specified width.} #' \item{\code{anova_tables2(data_name, x_col_names, y_col_name, signif.stars = FALSE, sign_level = FALSE, means = FALSE)}}{Generate ANOVA tables for specified columns in a dataset.} #' \item{\code{define_as_options_by_context(data_name, obyc_types = NULL, key_columns = NULL)}}{Define options by context for a specified dataset.} - - +#' \item{\code{display_daily_table(data_name, climatic_element, date_col, year_col, station_col, Misscode, Tracecode, Zerocode, monstats = c("min", "mean", "median", "max", "IQR", "sum"))}}{Display a daily summary table for a specified climatic data element.} #' @export DataBook <- R6::R6Class("DataBook", public = list( @@ -4249,13 +4248,31 @@ DataBook <- R6::R6Class("DataBook", self$get_data_objects(data_name)$anova_tables2(x_col_names = x_col_names, y_col_name = y_col_name, signif.stars = signif.stars, sign_level = sign_level, means = means) }, + #' @description + #' Display a daily summary table for a specified climatic data element. + #' + #' @param data_name A character string representing the name of the dataset. + #' @param climatic_element A vector specifying the climatic elements to be displayed (e.g., temperature, rainfall). + #' @param date_col The name of the column containing date information. Default is `date_col`. + #' @param year_col The name of the column containing year information. Default is `year_col`. + #' @param station_col The name of the column containing station information. If missing, assigns the `Station` column from metadata. + #' @param Misscode A value representing missing data in the dataset. + #' @param Tracecode A value representing trace amounts of the climatic element. + #' @param Zerocode A value representing zero values for the climatic element. + #' @param monstats A vector of summary statistics to calculate for monthly data. Options include `"min"`, `"mean"`, `"median"`, `"max"`, `"IQR"`, and `"sum"`. + #' + #' @return A data frame displaying the daily summary table for the specified climatic element. + display_daily_table = function(data_name, climatic_element, date_col = date_col, year_col = year_col, station_col = station_col, Misscode, Tracecode, Zerocode, monstats = c("min", "mean", "median", "max", "IQR", "sum")) { + self$get_data_objects(data_name)$display_daily_table(data_name = data_name, climatic_element = climatic_element, date_col = date_col, year_col =year_col, station_col = station_col, Misscode = Misscode, Tracecode = Tracecode, Zerocode = Zerocode, monstats = monstats) + }, + #' @title Import SST #' @description Imports SST data and adds keys and links to the specified data tables. #' @param dataset The SST dataset. #' @param data_from The source of the data. Default is 5. #' @param data_names A vector of data table names. #' @return None - import_SST = function(dataset, data_from = 5, data_names = c()) { + import_SST = function(dataset, data_from = 5, data_names = c()) { data_list <- convert_SST(dataset, data_from) if(length(data_list) != length(data_names)) stop("data_names vector should be of length 2") names(data_list) = data_names diff --git a/R/data_sheet.R b/R/data_sheet.R index fbfb2a0..a2be361 100644 --- a/R/data_sheet.R +++ b/R/data_sheet.R @@ -178,6 +178,7 @@ #' \item{\code{replace_values_with_NA(row_index, column_index)}}{Replaces values with NA in the specified rows and columns.} #' \item{\code{set_options_by_context_types(obyc_types = NULL, key_columns = NULL)}}{Set options by context types for the current data sheet.} #' \item{\code{has_labels(col_names)}}{Checks if the specified columns have labels.} +#' \item{\code{display_daily_table(data_name, climatic_element, date_col = date_col, year_col = year_col, station_col = station_col, Misscode, Tracecode, Zerocode, monstats = c("min", "mean", "median", "max", "IQR", "sum"))}}{Display a daily summary table for a specified climatic data element.} #' } #' #' @section Active bindings: @@ -5071,8 +5072,33 @@ DataSheet <- R6::R6Class( has_labels = function(col_names) { if(missing(col_names)) stop("Column name must be specified.") return(!is.null(attr(col_names, "labels"))) - } + }, + #' @description + #' Display a daily summary table for a specified climatic data element. + #' + #' @param data_name A character string representing the name of the dataset. + #' @param climatic_element A vector specifying the climatic elements to be displayed (e.g., temperature, rainfall). + #' @param date_col The name of the column containing date information. Default is `date_col`. + #' @param year_col The name of the column containing year information. Default is `year_col`. + #' @param station_col The name of the column containing station information. If missing, assigns the `Station` column from metadata. + #' @param Misscode A value representing missing data in the dataset. + #' @param Tracecode A value representing trace amounts of the climatic element. + #' @param Zerocode A value representing zero values for the climatic element. + #' @param monstats A vector of summary statistics to calculate for monthly data. Options include `"min"`, `"mean"`, `"median"`, `"max"`, `"IQR"`, and `"sum"`. + #' + #' @return A data frame displaying the daily summary table for the specified climatic element. + #' + #' @details + #' This function retrieves the data frame associated with the specified dataset and renames columns to standardise `Date`, `Year`, and `Station` for ease of processing. It then displays a daily summary table using the specified climatic elements, handling missing codes, trace codes, and zero codes as defined. Monthly statistics are calculated based on the `monstats` argument. + display_daily_table = function(data_name, climatic_element, date_col = date_col, year_col = year_col, station_col = station_col, Misscode, Tracecode, Zerocode, monstats = c("min", "mean", "median", "max", "IQR", "sum")) { + curr_data <- self$get_data_frame() + if(missing(station_col)) curr_data[["Station"]] <- self$get_metadata(data_name_label) + else names(curr_data)[names(curr_data) == station_col] <- "Station" + names(curr_data)[names(curr_data) == date_col] <- "Date" + names(curr_data)[names(curr_data) == year_col] <- "Year" + return(DisplayDaily(Datain = curr_data, Variables = climatic_element, option = 1, Misscode = Misscode, Tracecode = Tracecode, Zerocode = Zerocode, monstats = monstats)) + } ), diff --git a/man/DataBook.Rd b/man/DataBook.Rd index 45e1b73..b09a9bd 100644 --- a/man/DataBook.Rd +++ b/man/DataBook.Rd @@ -434,6 +434,7 @@ 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.} \describe{ @@ -1454,6 +1455,9 @@ 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. + + Imports SST data and adds keys and links to the specified data tables. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{DataBook$new( @@ -3097,6 +3101,24 @@ Imports SST data and adds keys and links to the specified data tables. \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{dataset}}{The SST dataset.} \item{\code{data_from}}{The source of the data. Default is 5.} diff --git a/man/DataSheet.Rd b/man/DataSheet.Rd index d17d7aa..77112e9 100644 --- a/man/DataSheet.Rd +++ b/man/DataSheet.Rd @@ -10,6 +10,8 @@ DataSheet Class } \details{ An R6 class to handle and manage a data frame with associated metadata, filters, and various settings. + +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. } \section{Methods}{ @@ -188,6 +190,7 @@ An R6 class to handle and manage a data frame with associated metadata, filters, \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.} } } @@ -395,6 +398,7 @@ If setting a value, column_selection must be a list.} \item \href{#method-DataSheet-replace_values_with_NA}{\code{DataSheet$replace_values_with_NA()}} \item \href{#method-DataSheet-set_options_by_context_types}{\code{DataSheet$set_options_by_context_types()}} \item \href{#method-DataSheet-has_labels}{\code{DataSheet$has_labels()}} +\item \href{#method-DataSheet-display_daily_table}{\code{DataSheet$display_daily_table()}} \item \href{#method-DataSheet-clone}{\code{DataSheet$clone()}} } } @@ -4281,6 +4285,52 @@ A logical vector indicating if each column has labels. } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-DataSheet-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{DataSheet$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. +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-DataSheet-clone}{}}} \subsection{Method \code{clone()}}{ diff --git a/man/DisplayDaily.Rd b/man/DisplayDaily.Rd new file mode 100644 index 0000000..b3dc358 --- /dev/null +++ b/man/DisplayDaily.Rd @@ -0,0 +1,59 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/DisplayDaily.R +\name{DisplayDaily} +\alias{DisplayDaily} +\title{Display Daily Meteorological Data} +\usage{ +DisplayDaily( + Datain, + Stations, + Variables, + option = 1, + Years, + Misscode, + Tracecode, + Zerocode, + Fileout = NA, + monstats = c("min", "mean", "median", "max", "IQR", "sum") +) +} +\arguments{ +\item{Datain}{A data frame containing meteorological data, with one column for each variable, one row for each date, and the following columns (case-sensitive): +\itemize{ +\item \code{Station}: names or identifiers for stations +\item EITHER: a \code{Date} column (yyyy-mm-dd format, \code{option = 1}) +\item OR: separate \code{Year}, \code{Month}, and \code{Day} columns (\code{option = 2}) +}} + +\item{Stations}{A character vector of station names to view (e.g., \code{"KUND0002"}, \code{c("Paris", "London")}). If missing, all stations in \code{Datain} are selected.} + +\item{Variables}{A character vector of column names for the variables to display (e.g., \code{"Rain"}, \code{"TMin"}, \code{"RH"}). If missing, all variables except metadata columns are selected.} + +\item{option}{An integer (1 or 2) indicating date format: +\itemize{ +\item \code{1}: \code{Date} column format (yyyy-mm-dd) +\item \code{2}: separate \code{Year}, \code{Month}, and \code{Day} columns. +}} + +\item{Years}{An integer vector of years to view (default is all years in \code{Datain}).} + +\item{Misscode}{Character string representing the display value for missing data (e.g., "-").} + +\item{Tracecode}{Character string for trace amounts of rainfall (default "tr").} + +\item{Zerocode}{Character string for zero values (default "--").} + +\item{Fileout}{Optional file path for saving the output table. If \code{NA}, results are printed to the console.} + +\item{monstats}{A character vector of monthly statistics to compute, options include \code{"min"}, \code{"mean"}, \code{"median"}, \code{"max"}, \code{"IQR"}, and \code{"sum"}.} +} +\value{ +This function prints a formatted daily table for each specified station, variable, and year. If a file path is specified in \code{Fileout}, the output is saved to that file. +} +\description{ +Display daily meteorological data in a readable table format. +This function was developed by Helen Greatrex as part of the SSC-RCLIM package. It formats daily meteorological data for easy viewing, displaying values for each day of the month and summarising monthly statistics. The function is similar in display format to the INSTAT "DisplayDaily" feature. +} +\details{ +This function checks for the presence of required columns and renames variables as needed to ensure compatibility with the \code{Datain} format. Missing data, trace rainfall, and zero values are replaced with user-defined codes. Monthly statistics are computed for each month. The function fills in any missing dates within the specified range for seamless daily reporting. +}