From f6876863a904ea139f8fad98060d7851bedd1d38 Mon Sep 17 00:00:00 2001 From: Guillermo martinez Date: Thu, 17 Oct 2024 15:54:00 -0500 Subject: [PATCH] Metadata Correction --- CRAN-SUBMISSION | 4 ++-- DESCRIPTION | 16 ++++++++------- R/get_gfdata.R | 23 ++++++++++----------- R/pellin.R | 18 ++++++++-------- R/process_gfdata.R | 32 ++++++++++++++--------------- R/report_gfdata.R | 42 +++++++++++++++++++------------------- R/utils.R | 25 +++++++++++------------ R/viseat.R | 22 ++++++++++---------- inst/DailyReportsGF.Rmd | 6 +++--- inst/FinalReportsGF.Rmd | 6 +++--- man/convert_unit.Rd | 6 +++--- man/ensure_date_format.Rd | 5 ++--- man/filter_within_range.Rd | 2 +- man/get_gfdata.Rd | 21 +++++++++---------- man/has_credentials.Rd | 4 ++-- man/pellin.Rd | 14 ++++++------- man/process_gfdata.Rd | 16 +++++++-------- man/process_rfid_data.Rd | 8 ++++---- man/report_gfdata.Rd | 30 +++++++++++++-------------- man/viseat.Rd | 18 ++++++++-------- vignettes/greenfeedr.Rmd | 4 ++-- 21 files changed, 160 insertions(+), 162 deletions(-) diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index c64646b..ee76293 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ Version: 1.0.0 -Date: 2024-10-16 14:11:39 UTC -SHA: b738b472e7bfe04747898a65e8d48087fd328caa +Date: 2024-10-16 15:48:00 UTC +SHA: 06aa2c9af8d8b20b0846068ab9528f46a691e462 diff --git a/DESCRIPTION b/DESCRIPTION index 89b9856..77563fa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: greenfeedr Type: Package -Title: Process and Report GreenFeed Data +Title: Process and Report 'GreenFeed' Data Version: 1.0.0 Authors@R: c( @@ -16,12 +16,14 @@ Authors@R: role = c("ctb")) ) Maintainer: Guillermo Martinez-Boggio -Description: Functions for downloading, processing, and reporting GreenFeed data. The - GreenFeed system generates large amount of daily data that could be overwhelming for users. - So, the first step is to retrieve data from C-Lock system so use `get_gfdata()` to download via API. - Also, other function such as `report_gfdata()` allows to download and report daily and final data from GreenFeed. - The function `process_gfdata()` process daily or final data for further analysis. Two more functions as - `pellin()` and `viseat()` helps for processing and checking pellet intakes and visits to the GreenFeed. +Description: Downloading, Processing, and Reporting 'GreenFeed' Data. + The 'GreenFeed' system generates substantial amounts of daily data, which can be overwhelming for users. + This package facilitates data retrieval and reporting from the 'GreenFeed' system using a streamlined process. + Users can retrieve data from the 'C-Lock' system via an 'API' using the get_gfdata() function. + Additionally, the report_gfdata() function allows users to generate both daily and final reports from 'GreenFeed' data. + The process_gfdata() function further processes this data for analysis. + For pellet intake processing and visit checks, the package also provides the pellin() and viseat() functions, + ensuring a comprehensive toolset for managing and analyzing 'GreenFeed' data. License: GPL (>= 3) Encoding: UTF-8 LazyData: true diff --git a/R/get_gfdata.R b/R/get_gfdata.R index 20e041e..0e4cafb 100644 --- a/R/get_gfdata.R +++ b/R/get_gfdata.R @@ -1,23 +1,22 @@ #' @name get_gfdata -#' @title Download Daily GreenFeed Data via API +#' @title Download Daily 'GreenFeed' Data via 'API' #' -#' @description Downloads daily GreenFeed data from the C-Lock Inc. server -#' via an application programming interface (API). Retrieves data -#' based on specified parameters such as login information, date range and units, -#' and provides an Excel file with the GreenFeed data. +#' @description Downloads daily 'GreenFeed' data from the 'C-Lock Inc.' server via an 'API'. +#' Retrieves data based on specified parameters (login, date range and units), and +#' provides a CSV file with the 'GreenFeed' daily data. #' -#' @param user a character string representing the user name to logging into GreenFeed system -#' @param pass a character string representing password to logging into GreenFeed system +#' @param user a character string representing the user name to logging into 'GreenFeed' system +#' @param pass a character string representing password to logging into 'GreenFeed' system #' @param exp a character string representing study name or other study identifier. It is used as file name to save the data -#' @param unit numeric or character vector, or a list representing one or more GreenFeed unit numbers +#' @param unit numeric or character vector, or a list representing one or more 'GreenFeed' unit numbers #' @param start_date a character string representing the start date of the study (format: "mm/dd/yyyy") #' @param end_date a character string representing the end date of the study (format: "mm/dd/yyyy") #' @param save_dir a character string representing the directory to save the output file #' -#' @return A CSV file with daily GreenFeed data in the specified directory +#' @return A CSV file with daily 'GreenFeed' data in the specified directory #' #' @examplesIf has_credentials() -#' # Please replace "your_username" and "your_password" with your actual GreenFeed credentials. +#' # Please replace "your_username" and "your_password" with your actual 'GreenFeed' credentials. #' user <- Sys.getenv("API_USER") #' pass <- Sys.getenv("API_PASS") #' exp <- "StudyName" @@ -36,7 +35,7 @@ #' @import stringr get_gfdata <- function(user, pass, exp = NA, unit, - start_date, end_date = Sys.Date(), save_dir = getwd()) { + start_date, end_date = Sys.Date(), save_dir = tempdir()) { # Ensure unit is a comma-separated string unit <- convert_unit(unit) @@ -54,7 +53,7 @@ get_gfdata <- function(user, pass, exp = NA, unit, "https://portal.c-lockinc.com/api/getemissions?d=visits&fids=", unit, "&st=", start_date, "&et=", end_date, "%2012:00:00" ) - print(URL) + message(URL) req <- httr::POST(URL, body = list(token = TOK)) httr::stop_for_status(req) diff --git a/R/pellin.R b/R/pellin.R index d6c08ec..77059ae 100644 --- a/R/pellin.R +++ b/R/pellin.R @@ -1,21 +1,21 @@ #' @name pellin -#' @title Process GreenFeed Pellet Intakes +#' @title Process 'GreenFeed' Pellet Intakes #' -#' @description Processes the feedtimes file from GreenFeed system, +#' @description Processes the "feedtimes" file from 'GreenFeed' system, #' including visits and food drops across a specific period, and it is used #' to calculate pellet intakes per animal from all units. #' Aggregates data to provide insights into the feeding behavior #' and pellet consumption of the animals during a study. #' -#' @param file_path a character string or list representing files(s) with feedtimes from C-Lock -#' @param unit numeric or character vector or list representing one or more GreenFeed unit numbers. The order should match with feedtimes files +#' @param file_path a character string or list representing files(s) with "feedtimes" from 'C-Lock Inc.' +#' @param unit numeric or character vector or list representing one or more 'GreenFeed' unit numbers. The order should match with "feedtimes" files #' @param gcup a numeric value representing the grams of pellets per cup. #' @param start_date a character string representing the start date of the study (format: "mm/dd/yyyy") #' @param end_date a character string representing the end date of the study (format: "mm/dd/yyyy") #' @param save_dir a character string representing the directory to save the output file -#' @param rfid_file a character string representing the file with individual IDs. The order should be AnimalName (col1) and RFID (col2) +#' @param rfid_file a character string representing the file with individual IDs. The order should be Visual ID (col1) and RFID (col2) #' -#' @return An Excel file with pellet intakes for all animals and days within the specified period is saved to `save_dir`. +#' @return An Excel file with pellet intakes for all animals and days within the specified period is saved to save_dir. #' The file is named "Pellet_Intakes_YYYY-MM-DD_YYYY-MM-DD.csv". #' #' @examples @@ -25,7 +25,7 @@ #' #' # You must include the grams of pellets per cup based on the result obtained from the 10-drops test #' -#' # If the user include an rfid file, the structure should be in col1 AnimalName or VisualID, and +#' # If the user include an rfid file, the structure should be in col1 AnimalName or Visual ID, and #' # col2 the RFID or TAG_ID. The file could be save in different formats (.xlsx, .csv, or .txt). #' RFIDs <- system.file("extdata", "RFID_file.csv", package = "greenfeedr") #' @@ -56,7 +56,7 @@ utils::globalVariables(c( )) pellin <- function(file_path, unit, gcup, start_date, end_date, - save_dir = getwd(), rfid_file = NULL) { + save_dir = tempdir(), rfid_file = NULL) { message("Please set the 'gcup' parameter based on the 10-drops test. If units have different gram values, define 'gcup' as a vector with an element for each unit.") @@ -88,7 +88,7 @@ pellin <- function(file_path, unit, gcup, start_date, end_date, - # If rfid_file provided, filter and get animal ID not visiting the GreenFeed units + # If rfid_file provided, filter and get animal ID not visiting the 'GreenFeed' units if (!is.null(rfid_file) && is.data.frame(rfid_file) && nrow(rfid_file) > 0) { df <- df[df$CowTag %in% rfid_file$RFID, ] noGFvisits <- rfid_file$FarmName[!(rfid_file$RFID %in% df$CowTag)] diff --git a/R/process_gfdata.R b/R/process_gfdata.R index 6151bf5..4d65cc1 100644 --- a/R/process_gfdata.R +++ b/R/process_gfdata.R @@ -1,11 +1,10 @@ #' @name process_gfdata -#' @title Process Daily and Final GreenFeed Data +#' @title Process Daily and Final 'GreenFeed' Data #' -#' @description Processes and calculates daily and weekly averages of GreenFeed data. -#' Handles data filtering, aggregation, and summarization to facilitate -#' further analysis and reporting. +#' @description Processes and calculates daily and weekly averages of 'GreenFeed' data. +#' Handles data filtering, aggregation, and summarization to facilitate further analysis. #' -#' @param data a data frame with daily or finalized GreenFeed data +#' @param data a data frame with daily or finalized 'GreenFeed' data #' @param start_date a character string representing the start date of the study (format: "mm/dd/yyyy") #' @param end_date a character string representing the end date of the study (format: "mm/dd/yyyy") #' @param param1 an integer representing the number of records per day to be consider for analysis @@ -13,8 +12,8 @@ #' @param min_time an integer representing the minimum number of minutes for a records to be consider for analysis. By default min_time is 2 #' #' @return A list of two data frames: -#' \item{daily_data }{data frame with daily processed GreenFeed data} -#' \item{weekly_data }{data frame with weekly processed GreenFeed data} +#' \item{daily_data }{data frame with daily processed 'GreenFeed' data} +#' \item{weekly_data }{data frame with weekly processed 'GreenFeed' data} #' #' @examples #' file <- system.file("extdata", "StudyName_GFdata.csv", package = "greenfeedr") @@ -25,7 +24,8 @@ #' start_date = "2024-05-13", #' end_date = "2024-05-25", #' param1 = 2, -#' param2 = 3 +#' param2 = 3, +#' min_time = 2 #' ) #' head(gf_data) #' @@ -229,17 +229,17 @@ process_gfdata <- function(data, start_date, end_date, # Description of mean, sd, and CV for weekly gases - print(paste0("CH4: ", round(mean(weekly_df$CH4GramsPerDay, na.rm = TRUE), 2), " +- ", round(stats::sd(weekly_df$CH4GramsPerDay, na.rm = TRUE), 2))) - print(paste0("CH4 CV = ", round(stats::sd(weekly_df$CH4GramsPerDay, na.rm = TRUE) / mean(weekly_df$CH4GramsPerDay, na.rm = TRUE) * 100, 1), "%")) + message(paste0("CH4: ", round(mean(weekly_df$CH4GramsPerDay, na.rm = TRUE), 2), " +- ", round(stats::sd(weekly_df$CH4GramsPerDay, na.rm = TRUE), 2))) + message(paste0("CH4 CV = ", round(stats::sd(weekly_df$CH4GramsPerDay, na.rm = TRUE) / mean(weekly_df$CH4GramsPerDay, na.rm = TRUE) * 100, 1), "%")) - print(paste0("CO2: ", round(mean(weekly_df$CO2GramsPerDay, na.rm = TRUE), 2), " +- ", round(stats::sd(weekly_df$CO2GramsPerDay, na.rm = TRUE), 2))) - print(paste0("CO2 CV = ", round(stats::sd(weekly_df$CO2GramsPerDay, na.rm = TRUE) / mean(weekly_df$CO2GramsPerDay, na.rm = TRUE) * 100, 1), "%")) + message(paste0("CO2: ", round(mean(weekly_df$CO2GramsPerDay, na.rm = TRUE), 2), " +- ", round(stats::sd(weekly_df$CO2GramsPerDay, na.rm = TRUE), 2))) + message(paste0("CO2 CV = ", round(stats::sd(weekly_df$CO2GramsPerDay, na.rm = TRUE) / mean(weekly_df$CO2GramsPerDay, na.rm = TRUE) * 100, 1), "%")) - print(paste0("O2: ", round(mean(weekly_df$O2GramsPerDay, na.rm = TRUE), 2), " +- ", round(stats::sd(weekly_df$O2GramsPerDay, na.rm = TRUE), 2))) - print(paste0("O2 CV = ", round(stats::sd(weekly_df$O2GramsPerDay, na.rm = TRUE) / mean(weekly_df$O2GramsPerDay, na.rm = TRUE) * 100, 1), "%")) + message(paste0("O2: ", round(mean(weekly_df$O2GramsPerDay, na.rm = TRUE), 2), " +- ", round(stats::sd(weekly_df$O2GramsPerDay, na.rm = TRUE), 2))) + message(paste0("O2 CV = ", round(stats::sd(weekly_df$O2GramsPerDay, na.rm = TRUE) / mean(weekly_df$O2GramsPerDay, na.rm = TRUE) * 100, 1), "%")) - print(paste0("H2: ", round(mean(weekly_df$H2GramsPerDay, na.rm = TRUE), 2), " +- ", round(stats::sd(weekly_df$H2GramsPerDay, na.rm = TRUE), 2))) - print(paste0("H2 CV = ", round(stats::sd(weekly_df$H2GramsPerDay, na.rm = TRUE) / mean(weekly_df$H2GramsPerDay, na.rm = TRUE) * 100, 1), "%")) + message(paste0("H2: ", round(mean(weekly_df$H2GramsPerDay, na.rm = TRUE), 2), " +- ", round(stats::sd(weekly_df$H2GramsPerDay, na.rm = TRUE), 2))) + message(paste0("H2 CV = ", round(stats::sd(weekly_df$H2GramsPerDay, na.rm = TRUE) / mean(weekly_df$H2GramsPerDay, na.rm = TRUE) * 100, 1), "%")) # Return a list of data frames diff --git a/R/report_gfdata.R b/R/report_gfdata.R index 940833e..4a0d0a7 100644 --- a/R/report_gfdata.R +++ b/R/report_gfdata.R @@ -1,28 +1,28 @@ #' @name report_gfdata -#' @title Download and Report GreenFeed Data +#' @title Download and Report 'GreenFeed' Data #' -#' @description Generates PDF reports of daily and final GreenFeed data. -#' If option "daily" is used, data is retrieved from C-Lock server via an application programming interface (API) -#' and generates a PDF report to with number of animals, records, and gas production of the ongoing study. -#' But, if option "final" is used, final data should be provided to generates a PDF report -#' to evaluate all GreenFeed data obtained from the finalized study. +#' @description Generates PDF reports of daily and final 'GreenFeed' data. +#' If the option daily is used, data is retrieved from 'C-Lock Inc.' server via an 'API' and +#' generates a PDF report to with number of animals, records, and gases production. +#' However, if the option final is used, the finalized data should be provided to generates a PDF report +#' to evaluate all 'GreenFeed' data obtained from the finalized study. #' -#' @param input_type a character string representing type of data (options: "daily" or "final") +#' @param input_type a character string representing type of data (options: "daily" and "final") #' @param exp a character string representing study name or other study identifier. It is used as file name to save the data -#' @param unit numeric or character vector, or a list representing one or more GreenFeed unit numbers +#' @param unit numeric or character vector, or a list representing one or more 'GreenFeed' unit numbers #' @param start_date a character string representing the start date of the study (format: "mm/dd/yyyy") #' @param end_date a character string representing the end date of the study (format: "mm/dd/yyyy") #' @param save_dir a character string representing the directory to save the output file -#' @param plot_opt a character string representing the gas(es) to plot (options: 'All', 'CH4', 'CO2', 'O2', 'H2') -#' @param rfid_file a character string representing the file with individual IDs. The order should be AnimalName (col1) and RFID (col2) -#' @param user a character string representing the user name to logging into GreenFeed system. If `input_type` is "final", this parameter is ignored -#' @param pass a character string representing password to logging into GreenFeed system. If `input_type` is "final", this parameter is ignored -#' @param file_path A list of file paths containing the final report(s) from the GreenFeed system. If `input_type` is "final", this parameter is ignored +#' @param plot_opt a character string representing the gas(es) to plot (options: "All", "CH4", "CO2", "O2", "H2") +#' @param rfid_file a character string representing the file with individual IDs. The order should be Visual ID (col1) and RFID (col2) +#' @param user a character string representing the user name to logging into 'GreenFeed' system. If input_type is "final", this parameter is ignored +#' @param pass a character string representing password to logging into 'GreenFeed' system. If input_type is "final", this parameter is ignored +#' @param file_path A list of file paths containing the final report(s) from the 'GreenFeed' system. If input_type is "final", this parameter is ignored #' -#' @return A CSV file with daily GreenFeed data and a PDF report with a description of the daily or final records +#' @return A CSV file with daily 'GreenFeed' data and a PDF report with a description of the daily or final records #' #' @examplesIf has_credentials() -#' # Please replace "your_username" and "your_password" with your actual GreenFeed credentials. +#' # Please replace "your_username" and "your_password" with your actual 'GreenFeed' credentials. #' user <- Sys.getenv("API_USER") #' pass <- Sys.getenv("API_PASS") #' @@ -54,7 +54,7 @@ utils::globalVariables(c("GoodDataDuration", "StartTime", "AirflowLitersPerSec", "Gas_Data")) report_gfdata <- function(input_type, exp = NA, unit, start_date, end_date = Sys.Date(), - save_dir = getwd(), plot_opt = "CH4", rfid_file = NULL, + save_dir = tempdir(), plot_opt = "CH4", rfid_file = NULL, user = NA, pass = NA, file_path) { # Ensure unit is a comma-separated string unit <- convert_unit(unit) @@ -84,12 +84,12 @@ report_gfdata <- function(input_type, exp = NA, unit, start_date, end_date = Sys "https://portal.c-lockinc.com/api/getemissions?d=visits&fids=", unit, "&st=", start_date, "&et=", end_date, "%2012:00:00" ) - print(URL) + message(URL) req <- httr::POST(URL, body = list(token = TOK)) httr::stop_for_status(req) a <- httr::content(req, as = "text") - print(a) + message(a) # Split the lines perline <- stringr::str_split(a, "\\n")[[1]] @@ -126,7 +126,7 @@ report_gfdata <- function(input_type, exp = NA, unit, start_date, end_date = Sys dir.create(save_dir, recursive = TRUE) } - # Save GreenFeed data as a csv file in the specified directory + # Save 'GreenFeed' data as a csv file in the specified directory readr::write_excel_csv(df, file = paste0(save_dir, "/", exp, "_GFdata.csv")) @@ -142,7 +142,7 @@ report_gfdata <- function(input_type, exp = NA, unit, start_date, end_date = Sys } } - # Dataframe (df) contains daily GreenFeed data + # Dataframe (df) contains daily 'GreenFeed' data df <- df %>% ## Remove "unknown IDs" and leading zeros from RFID col dplyr::filter(RFID != "unknown") %>% @@ -205,7 +205,7 @@ report_gfdata <- function(input_type, exp = NA, unit, start_date, end_date = Sys "AirflowCf" ) - # df contains finalized GreenFeed data + # df contains finalized 'GreenFeed' data df <- df %>% ## Remove "unknown IDs" and leading zeros from RFID col dplyr::filter(RFID != "unknown") %>% diff --git a/R/utils.R b/R/utils.R index 7f56286..a3d008d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,7 +1,7 @@ #' @name has_credentials -#' @title Check for API Credentials +#' @title Check for 'API' Credentials #' -#' @description Check if necessary API credentials are available in the environment. +#' @description Check if necessary 'API' credentials are available in the environment. #' #' @return A logical value: `TRUE` if both `API_USER` and `API_PASS` environment variables are set (i.e., not `NA`); `FALSE` otherwise #' @examples @@ -30,9 +30,8 @@ has_credentials <- function() { #' @name ensure_date_format #' @title Check date format and transform in a usable one #' -#' @description Check date format. -#' If the format is wrong 'NA' an error message is printed, else it will -#' formatted the date in the correct way (YYYY-MM-DD) +#' @description Check date format. If the format is wrong ('NA') an error message is printed, +#' else it will formatted the date in the correct way (YYYY-MM-DD) #' #' @param date_input Date included as input #' @@ -82,7 +81,7 @@ ensure_date_format <- function(date_input) { #' @name filter_within_range #' @title Detect outliers in data using mean and standard deviation #' -#' @description Detect outliers using the mean and sd +#' @description Detect outliers using the mean and standard deviation. #' #' @param v A vector with data #' @param cutoff A threshold or cutoff value that defines the range (e.g., 2.5) @@ -118,7 +117,7 @@ filter_within_range <- function(v, cutoff) { #' @name process_rfid_data #' @title Process RFID Data #' -#' @description Processes RFID data from animals in the study +#' @description Processes RFID data from animals in the study. #' #' @param rfid_file Path or data frame containing RFID data. #' @@ -131,18 +130,18 @@ filter_within_range <- function(v, cutoff) { #' V2 = c("12345", "67890", "54321") #' ) #' processed_df <- process_rfid_data(df) -#' print(processed_df) +#' message(processed_df) #' #' # Example with invalid input #' invalid_data <- process_rfid_data(NULL) #' # Expected output: message "RFID is NA. It is recommended to include it." and NULL -#' print(invalid_data) +#' message(invalid_data) #' #' # Example with unsupported file format #' # Assuming 'rfid_data.docx' is an unsupported file format #' invalid_file <- process_rfid_data("path/to/rfid_data.docx") #' # Expected output: error message "Unsupported file format." -#' print(invalid_file) +#' message(invalid_file) #' #' @export #' @keywords internal @@ -203,12 +202,12 @@ process_rfid_data <- function(rfid_file) { #' @name convert_unit -#' @title Convert GreenFeed Unit Number +#' @title Convert 'GreenFeed' Unit Number #' #' @description Processes the parameter unit to format it correctly as a comma-separated string, -#' regardless of whether it's provided as a numeric, character, or list/vector. +#' regardless of whether it is provided as a numeric, character, or list/vector. #' -#' @param unit Number of the GreenFeed unit(s). Can be a numeric, character, list, or vector. +#' @param unit Number of the 'GreenFeed' unit(s). Can be a numeric, character, list, or vector. #' #' @return A character string of the unit(s) in the correct comma-separated format. #' diff --git a/R/viseat.R b/R/viseat.R index 8287d07..273b7f9 100644 --- a/R/viseat.R +++ b/R/viseat.R @@ -1,23 +1,23 @@ #' @name viseat -#' @title Process GreenFeed Visits +#' @title Process 'GreenFeed' Visits #' -#' @description Processes GreenFeed visits and food drops for a requested period. -#' Generates a list of animals not visiting the GreenFeed to manage them, -#' and a description of animals visiting the GreenFeed. +#' @description Processes 'GreenFeed' visits and food drops for a requested period. +#' Generates a list of animals not visiting the 'GreenFeed' to manage them, +#' and a description of animals visiting the 'GreenFeed'. #' -#' @param file_path a character string or list representing files(s) with feedtimes from C-Lock. +#' @param file_path a character string or list representing files(s) with feedtimes from 'C-Lock Inc.'. #' @param unit numeric or character vector or list representing one or more GreenFeed unit numbers. #' @param start_date a character string representing the start date of the study (format: "mm/dd/yyyy") #' @param end_date a character string representing the end date of the study (format: "mm/dd/yyyy") -#' @param rfid_file a character string representing the file with individual RFIDs. The order should be col1=FarmName and col2=RFID +#' @param rfid_file a character string representing the file with individual RFIDs. The order should be Visual ID (col1) and RFID (col2) #' #' @return A list of two data frames: -#' \item{visits_per_unit }{Data frame with daily processed GreenFeed data, including columns for FarmName, Date, Time, number of drops, and visits.} -#' \item{visits_per_animal }{Data frame with weekly processed GreenFeed data, including columns for FarmName, total drops, total visits, mean drops, and mean visits.} +#' \item{visits_per_unit }{Data frame with daily processed 'GreenFeed' data, including columns for VisualID, Date, Time, number of drops, and visits.} +#' \item{visits_per_animal }{Data frame with weekly processed 'GreenFeed' data, including columns for VisualID, total drops, total visits, mean drops, and mean visits.} #' #' #' @examples -#' # You should provide the 'feedtimes' files. +#' # You should provide the feedtimes files. #' # it could be a list of files if you have data from multiple units to combine #' path <- list(system.file("extdata", "feedtimes.csv", package = "greenfeedr")) #' @@ -79,7 +79,7 @@ viseat <- function(file_path, unit, start_date, end_date, rfid_file = NA) { dplyr::mutate(CowTag = gsub("^0+", "", CowTag)) - # If rfid_file provided, filter and get animal ID not visiting the GreenFeed units + # If rfid_file provided, filter and get animal ID not visiting the 'GreenFeed' units df <- df[df$CowTag %in% rfid_file$RFID, ] noGFvisits <- rfid_file$FarmName[!(rfid_file$RFID %in% df$CowTag)] @@ -103,7 +103,7 @@ viseat <- function(file_path, unit, start_date, end_date, rfid_file = NA) { color = "black", position = position_dodge(0.9), size = 3.8 ) - print(plotFID) + message(plotFID) # Create a data frame with number of drops and visits per day per animal daily_visits <- df %>% diff --git a/inst/DailyReportsGF.Rmd b/inst/DailyReportsGF.Rmd index dd27fa8..83e5c71 100644 --- a/inst/DailyReportsGF.Rmd +++ b/inst/DailyReportsGF.Rmd @@ -27,7 +27,7 @@ library(stringr) if (!is.null(rfid_file) && is.data.frame(rfid_file) && nrow(rfid_file) > 0) { kbl(rfid_file, "simple") } else { - print("The 'rfid_file' is not provided.") + message("The 'rfid_file' is not provided.") } ``` @@ -326,7 +326,7 @@ generate_plots <- function(data, group_var, plot_opt = c("All", "CH4", "O2", "CO } plots <- c(plots, list(p4)) } else { - print("No hydrogen (H2) data from GreenFeed") + message("No hydrogen (H2) data from GreenFeed") } } @@ -336,6 +336,6 @@ generate_plots <- function(data, group_var, plot_opt = c("All", "CH4", "O2", "CO # Call the function and display the plots plots <- generate_plots(df, group_var, plot_opt) for (p in plots) { - print(p) + message(p) } ``` diff --git a/inst/FinalReportsGF.Rmd b/inst/FinalReportsGF.Rmd index 4972d96..c41dd84 100644 --- a/inst/FinalReportsGF.Rmd +++ b/inst/FinalReportsGF.Rmd @@ -129,7 +129,7 @@ generate_combined_plot <- function(df, plot_opt) { } plot_combined <- generate_combined_plot(df, plot_opt) -print(plot_combined) +message(plot_combined) ``` @@ -372,7 +372,7 @@ generate_plots <- function(data, group_var, plot_opt = c("All", "CH4", "O2", "CO } plots <- c(plots, list(p4)) } else { - print("No hydrogen (H2) data from GreenFeed") + message("No hydrogen (H2) data from GreenFeed") } } @@ -382,6 +382,6 @@ generate_plots <- function(data, group_var, plot_opt = c("All", "CH4", "O2", "CO # Call the function and display the plots plots <- generate_plots(df, group_var, plot_opt) for (p in plots) { - print(p) + message(p) } ``` diff --git a/man/convert_unit.Rd b/man/convert_unit.Rd index 909e234..d812706 100644 --- a/man/convert_unit.Rd +++ b/man/convert_unit.Rd @@ -2,19 +2,19 @@ % Please edit documentation in R/utils.R \name{convert_unit} \alias{convert_unit} -\title{Convert GreenFeed Unit Number} +\title{Convert 'GreenFeed' Unit Number} \usage{ convert_unit(unit) } \arguments{ -\item{unit}{Number of the GreenFeed unit(s). Can be a numeric, character, list, or vector.} +\item{unit}{Number of the 'GreenFeed' unit(s). Can be a numeric, character, list, or vector.} } \value{ A character string of the unit(s) in the correct comma-separated format. } \description{ Processes the parameter unit to format it correctly as a comma-separated string, - regardless of whether it's provided as a numeric, character, or list/vector. + regardless of whether it is provided as a numeric, character, or list/vector. } \examples{ # Example 1: Providing unit as a character vector diff --git a/man/ensure_date_format.Rd b/man/ensure_date_format.Rd index 160015e..debeb16 100644 --- a/man/ensure_date_format.Rd +++ b/man/ensure_date_format.Rd @@ -13,9 +13,8 @@ ensure_date_format(date_input) A character string representing the date in 'YYYY-MM-DD' format } \description{ -Check date format. - If the format is wrong 'NA' an error message is printed, else it will - formatted the date in the correct way (YYYY-MM-DD) +Check date format. If the format is wrong ('NA') an error message is printed, + else it will formatted the date in the correct way (YYYY-MM-DD) } \examples{ # Example of correct date formats diff --git a/man/filter_within_range.Rd b/man/filter_within_range.Rd index 1da6ef7..abe05cc 100644 --- a/man/filter_within_range.Rd +++ b/man/filter_within_range.Rd @@ -15,7 +15,7 @@ filter_within_range(v, cutoff) A logical vector of the same length as `v`, where each element is `TRUE` if the corresponding value in `v` falls within the specified range, and `FALSE` otherwise. } \description{ -Detect outliers using the mean and sd +Detect outliers using the mean and standard deviation. } \examples{ # Sample data diff --git a/man/get_gfdata.Rd b/man/get_gfdata.Rd index e23d25f..b4a7b84 100644 --- a/man/get_gfdata.Rd +++ b/man/get_gfdata.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/get_gfdata.R \name{get_gfdata} \alias{get_gfdata} -\title{Download Daily GreenFeed Data via API} +\title{Download Daily 'GreenFeed' Data via 'API'} \usage{ get_gfdata( user, @@ -11,17 +11,17 @@ get_gfdata( unit, start_date, end_date = Sys.Date(), - save_dir = getwd() + save_dir = tempdir() ) } \arguments{ -\item{user}{a character string representing the user name to logging into GreenFeed system} +\item{user}{a character string representing the user name to logging into 'GreenFeed' system} -\item{pass}{a character string representing password to logging into GreenFeed system} +\item{pass}{a character string representing password to logging into 'GreenFeed' system} \item{exp}{a character string representing study name or other study identifier. It is used as file name to save the data} -\item{unit}{numeric or character vector, or a list representing one or more GreenFeed unit numbers} +\item{unit}{numeric or character vector, or a list representing one or more 'GreenFeed' unit numbers} \item{start_date}{a character string representing the start date of the study (format: "mm/dd/yyyy")} @@ -30,17 +30,16 @@ get_gfdata( \item{save_dir}{a character string representing the directory to save the output file} } \value{ -A CSV file with daily GreenFeed data in the specified directory +A CSV file with daily 'GreenFeed' data in the specified directory } \description{ -Downloads daily GreenFeed data from the C-Lock Inc. server - via an application programming interface (API). Retrieves data - based on specified parameters such as login information, date range and units, - and provides an Excel file with the GreenFeed data. +Downloads daily 'GreenFeed' data from the 'C-Lock Inc.' server via an 'API'. + Retrieves data based on specified parameters (login, date range and units), and + provides a CSV file with the 'GreenFeed' daily data. } \examples{ \dontshow{if (has_credentials()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -# Please replace "your_username" and "your_password" with your actual GreenFeed credentials. +# Please replace "your_username" and "your_password" with your actual 'GreenFeed' credentials. user <- Sys.getenv("API_USER") pass <- Sys.getenv("API_PASS") exp <- "StudyName" diff --git a/man/has_credentials.Rd b/man/has_credentials.Rd index 0758a21..1431969 100644 --- a/man/has_credentials.Rd +++ b/man/has_credentials.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/utils.R \name{has_credentials} \alias{has_credentials} -\title{Check for API Credentials} +\title{Check for 'API' Credentials} \usage{ has_credentials() } @@ -10,7 +10,7 @@ has_credentials() A logical value: `TRUE` if both `API_USER` and `API_PASS` environment variables are set (i.e., not `NA`); `FALSE` otherwise } \description{ -Check if necessary API credentials are available in the environment. +Check if necessary 'API' credentials are available in the environment. } \examples{ # Example 1: When environment variables are set diff --git a/man/pellin.Rd b/man/pellin.Rd index 0119bb6..c45514f 100644 --- a/man/pellin.Rd +++ b/man/pellin.Rd @@ -2,11 +2,11 @@ % Please edit documentation in R/pellin.R \name{pellin} \alias{pellin} -\title{Process GreenFeed Pellet Intakes} +\title{Process 'GreenFeed' Pellet Intakes} \arguments{ -\item{file_path}{a character string or list representing files(s) with feedtimes from C-Lock} +\item{file_path}{a character string or list representing files(s) with "feedtimes" from 'C-Lock Inc.'} -\item{unit}{numeric or character vector or list representing one or more GreenFeed unit numbers. The order should match with feedtimes files} +\item{unit}{numeric or character vector or list representing one or more 'GreenFeed' unit numbers. The order should match with "feedtimes" files} \item{gcup}{a numeric value representing the grams of pellets per cup.} @@ -16,14 +16,14 @@ \item{save_dir}{a character string representing the directory to save the output file} -\item{rfid_file}{a character string representing the file with individual IDs. The order should be AnimalName (col1) and RFID (col2)} +\item{rfid_file}{a character string representing the file with individual IDs. The order should be Visual ID (col1) and RFID (col2)} } \value{ -An Excel file with pellet intakes for all animals and days within the specified period is saved to `save_dir`. +An Excel file with pellet intakes for all animals and days within the specified period is saved to save_dir. The file is named "Pellet_Intakes_YYYY-MM-DD_YYYY-MM-DD.csv". } \description{ -Processes the feedtimes file from GreenFeed system, +Processes the "feedtimes" file from 'GreenFeed' system, including visits and food drops across a specific period, and it is used to calculate pellet intakes per animal from all units. Aggregates data to provide insights into the feeding behavior @@ -36,7 +36,7 @@ path <- list(system.file("extdata", "feedtimes.csv", package = "greenfeedr")) # You must include the grams of pellets per cup based on the result obtained from the 10-drops test -# If the user include an rfid file, the structure should be in col1 AnimalName or VisualID, and +# If the user include an rfid file, the structure should be in col1 AnimalName or Visual ID, and # col2 the RFID or TAG_ID. The file could be save in different formats (.xlsx, .csv, or .txt). RFIDs <- system.file("extdata", "RFID_file.csv", package = "greenfeedr") diff --git a/man/process_gfdata.Rd b/man/process_gfdata.Rd index 2ab9d97..50cecad 100644 --- a/man/process_gfdata.Rd +++ b/man/process_gfdata.Rd @@ -2,9 +2,9 @@ % Please edit documentation in R/process_gfdata.R \name{process_gfdata} \alias{process_gfdata} -\title{Process Daily and Final GreenFeed Data} +\title{Process Daily and Final 'GreenFeed' Data} \arguments{ -\item{data}{a data frame with daily or finalized GreenFeed data} +\item{data}{a data frame with daily or finalized 'GreenFeed' data} \item{start_date}{a character string representing the start date of the study (format: "mm/dd/yyyy")} @@ -18,13 +18,12 @@ } \value{ A list of two data frames: - \item{daily_data }{data frame with daily processed GreenFeed data} - \item{weekly_data }{data frame with weekly processed GreenFeed data} + \item{daily_data }{data frame with daily processed 'GreenFeed' data} + \item{weekly_data }{data frame with weekly processed 'GreenFeed' data} } \description{ -Processes and calculates daily and weekly averages of GreenFeed data. - Handles data filtering, aggregation, and summarization to facilitate - further analysis and reporting. +Processes and calculates daily and weekly averages of 'GreenFeed' data. + Handles data filtering, aggregation, and summarization to facilitate further analysis. } \examples{ file <- system.file("extdata", "StudyName_GFdata.csv", package = "greenfeedr") @@ -35,7 +34,8 @@ gf_data <- process_gfdata( start_date = "2024-05-13", end_date = "2024-05-25", param1 = 2, - param2 = 3 + param2 = 3, + min_time = 2 ) head(gf_data) diff --git a/man/process_rfid_data.Rd b/man/process_rfid_data.Rd index 94b3178..dbd1fae 100644 --- a/man/process_rfid_data.Rd +++ b/man/process_rfid_data.Rd @@ -13,7 +13,7 @@ process_rfid_data(rfid_file) A data frame with standardized column names (`FarmName` and `RFID`). If the input is invalid or if no valid data is provided, the function returns `NULL`. } \description{ -Processes RFID data from animals in the study +Processes RFID data from animals in the study. } \examples{ # Example with a data frame @@ -22,18 +22,18 @@ df <- data.frame( V2 = c("12345", "67890", "54321") ) processed_df <- process_rfid_data(df) -print(processed_df) +message(processed_df) # Example with invalid input invalid_data <- process_rfid_data(NULL) # Expected output: message "RFID is NA. It is recommended to include it." and NULL -print(invalid_data) +message(invalid_data) # Example with unsupported file format # Assuming 'rfid_data.docx' is an unsupported file format invalid_file <- process_rfid_data("path/to/rfid_data.docx") # Expected output: error message "Unsupported file format." -print(invalid_file) +message(invalid_file) } \keyword{internal} diff --git a/man/report_gfdata.Rd b/man/report_gfdata.Rd index ddb71a3..c3a27d0 100644 --- a/man/report_gfdata.Rd +++ b/man/report_gfdata.Rd @@ -2,13 +2,13 @@ % Please edit documentation in R/report_gfdata.R \name{report_gfdata} \alias{report_gfdata} -\title{Download and Report GreenFeed Data} +\title{Download and Report 'GreenFeed' Data} \arguments{ -\item{input_type}{a character string representing type of data (options: "daily" or "final")} +\item{input_type}{a character string representing type of data (options: "daily" and "final")} \item{exp}{a character string representing study name or other study identifier. It is used as file name to save the data} -\item{unit}{numeric or character vector, or a list representing one or more GreenFeed unit numbers} +\item{unit}{numeric or character vector, or a list representing one or more 'GreenFeed' unit numbers} \item{start_date}{a character string representing the start date of the study (format: "mm/dd/yyyy")} @@ -16,29 +16,29 @@ \item{save_dir}{a character string representing the directory to save the output file} -\item{plot_opt}{a character string representing the gas(es) to plot (options: 'All', 'CH4', 'CO2', 'O2', 'H2')} +\item{plot_opt}{a character string representing the gas(es) to plot (options: "All", "CH4", "CO2", "O2", "H2")} -\item{rfid_file}{a character string representing the file with individual IDs. The order should be AnimalName (col1) and RFID (col2)} +\item{rfid_file}{a character string representing the file with individual IDs. The order should be Visual ID (col1) and RFID (col2)} -\item{user}{a character string representing the user name to logging into GreenFeed system. If `input_type` is "final", this parameter is ignored} +\item{user}{a character string representing the user name to logging into 'GreenFeed' system. If input_type is "final", this parameter is ignored} -\item{pass}{a character string representing password to logging into GreenFeed system. If `input_type` is "final", this parameter is ignored} +\item{pass}{a character string representing password to logging into 'GreenFeed' system. If input_type is "final", this parameter is ignored} -\item{file_path}{A list of file paths containing the final report(s) from the GreenFeed system. If `input_type` is "final", this parameter is ignored} +\item{file_path}{A list of file paths containing the final report(s) from the 'GreenFeed' system. If input_type is "final", this parameter is ignored} } \value{ -A CSV file with daily GreenFeed data and a PDF report with a description of the daily or final records +A CSV file with daily 'GreenFeed' data and a PDF report with a description of the daily or final records } \description{ -Generates PDF reports of daily and final GreenFeed data. - If option "daily" is used, data is retrieved from C-Lock server via an application programming interface (API) - and generates a PDF report to with number of animals, records, and gas production of the ongoing study. - But, if option "final" is used, final data should be provided to generates a PDF report - to evaluate all GreenFeed data obtained from the finalized study. +Generates PDF reports of daily and final 'GreenFeed' data. + If the option daily is used, data is retrieved from 'C-Lock Inc.' server via an 'API' and + generates a PDF report to with number of animals, records, and gases production. + However, if the option final is used, the finalized data should be provided to generates a PDF report + to evaluate all 'GreenFeed' data obtained from the finalized study. } \examples{ \dontshow{if (has_credentials()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -# Please replace "your_username" and "your_password" with your actual GreenFeed credentials. +# Please replace "your_username" and "your_password" with your actual 'GreenFeed' credentials. user <- Sys.getenv("API_USER") pass <- Sys.getenv("API_PASS") diff --git a/man/viseat.Rd b/man/viseat.Rd index 2f627bf..c058afd 100644 --- a/man/viseat.Rd +++ b/man/viseat.Rd @@ -2,9 +2,9 @@ % Please edit documentation in R/viseat.R \name{viseat} \alias{viseat} -\title{Process GreenFeed Visits} +\title{Process 'GreenFeed' Visits} \arguments{ -\item{file_path}{a character string or list representing files(s) with feedtimes from C-Lock.} +\item{file_path}{a character string or list representing files(s) with feedtimes from 'C-Lock Inc.'.} \item{unit}{numeric or character vector or list representing one or more GreenFeed unit numbers.} @@ -12,20 +12,20 @@ \item{end_date}{a character string representing the end date of the study (format: "mm/dd/yyyy")} -\item{rfid_file}{a character string representing the file with individual RFIDs. The order should be col1=FarmName and col2=RFID} +\item{rfid_file}{a character string representing the file with individual RFIDs. The order should be Visual ID (col1) and RFID (col2)} } \value{ A list of two data frames: - \item{visits_per_unit }{Data frame with daily processed GreenFeed data, including columns for FarmName, Date, Time, number of drops, and visits.} - \item{visits_per_animal }{Data frame with weekly processed GreenFeed data, including columns for FarmName, total drops, total visits, mean drops, and mean visits.} + \item{visits_per_unit }{Data frame with daily processed 'GreenFeed' data, including columns for VisualID, Date, Time, number of drops, and visits.} + \item{visits_per_animal }{Data frame with weekly processed 'GreenFeed' data, including columns for VisualID, total drops, total visits, mean drops, and mean visits.} } \description{ -Processes GreenFeed visits and food drops for a requested period. - Generates a list of animals not visiting the GreenFeed to manage them, - and a description of animals visiting the GreenFeed. +Processes 'GreenFeed' visits and food drops for a requested period. + Generates a list of animals not visiting the 'GreenFeed' to manage them, + and a description of animals visiting the 'GreenFeed'. } \examples{ -# You should provide the 'feedtimes' files. +# You should provide the feedtimes files. # it could be a list of files if you have data from multiple units to combine path <- list(system.file("extdata", "feedtimes.csv", package = "greenfeedr")) diff --git a/vignettes/greenfeedr.Rmd b/vignettes/greenfeedr.Rmd index 6ace5b0..b8ed76e 100644 --- a/vignettes/greenfeedr.Rmd +++ b/vignettes/greenfeedr.Rmd @@ -49,14 +49,14 @@ studies <- list( Unit = c(2, 3), StartDate = "2024-01-20", EndDate = Sys.Date(), - save_dir = "/Downloads/Experiment_01/" + save_dir = "/tempdir()/Experiment_01/" ), list( Experiment = "Experiment_02", Unit = c(212), StartDate = "2024-02-01", EndDate = Sys.Date(), - save_dir = "/Downloads/Experiment_02" + save_dir = "/tempdir()/Experiment_02/" ) )