library('readxl') #chemba field_boundaries_sf <- st_read(here(data_dir, "pivot.geojson")) names(field_boundaries_sf) <- c("field", "sub_field", "geometry") field_boundaries <- field_boundaries_sf %>% terra::vect() harvesting_data <- read_excel(here(data_dir, "harvest.xlsx")) %>% dplyr::select( c( "field", "sub_field", "year", "season_start", "season_end", "age", "sub_area", "tonnage_ha" ) ) %>% mutate( field = as.character(field), sub_field = as.character(sub_field), year = as.numeric(year), season_start = as.Date(season_start), season_end = as.Date(season_end), age = as.numeric(age), sub_area = as.character(sub_area), tonnage_ha = as.numeric(tonnage_ha) ) %>% mutate( season_end = case_when(season_end > Sys.Date() ~ Sys.Date(), TRUE ~ season_end), age = round(as.numeric(season_end - season_start) / 7, 0) ) # Define the log file path log_file <- here("laravel_app/storage/app/rmd_log.txt") # Create a logging function log_message <- function(message) { cat(message, "\n", file = log_file, append = TRUE) }