R/dates.R

Defines functions as_date_management_df

#' Convert the dates of a management_df to Date
#'
#' The calculations compare dates and add days to them, which requires the
#'  class `Date`. Dates of class `POSIXct` (e.g. from `readxl`) or character
#'  dates ("YYYY-MM-DD") are converted with [as.Date()]. Other columns and
#'  the class of the data are kept. [check_management_df()] warns about dates
#'  that are not of class `Date` (`SM-W217`).
#'
#' @param var_MGMT_data a `management_df`
#'
#' @return `var_MGMT_data` with the column `date` of class `Date`
#'
#' @md
#' @noRd
as_date_management_df <- function(var_MGMT_data) {
  if ("date" %in% names(var_MGMT_data) && !inherits(var_MGMT_data$date, "Date")) {
    var_MGMT_data$date <- as.Date(var_MGMT_data$date)
  }
  var_MGMT_data
}

Try the SoilManageR package in your browser

Any scripts or data that you put into this service are public.

SoilManageR documentation built on Nov. 17, 2026, 5:08 p.m.