R/check_new_tasks.R

Defines functions check_new_tasks

Documented in check_new_tasks

#' Check New Tasks
#'
#' This function allows you to compare checklists for new items and completions.
#' @param list1 A checklist for a Trello card.
#' @param list2 A more recent checklist for the same card.
#' @keywords repello
#' @export

check_new_tasks <- function(list1, list2){
  changes <- dplyr::setdiff(list2, list1)
  item_history <- c()
  task_completeness <- c()
  if (list2$item[1] == "No checklist for this project"){
    changes <- data.frame(item=character(), history=character(), status=character())
    changes
  } else {
    for (i in 1:nrow(list2)){
      if (list2$item[i] %in% list1$item & list2$item[i] %in% changes$item){
        item_history[i] <- "Existing Item"
        task_completeness[i] <- "Newly Completed"
      } else if (list2$item[i] %in% list1$item & !(list2$item[i] %in% changes$item)){
        item_history[i] <- "Existing Item"
        if (list2$status[i]=="complete"){
          task_completeness[i]="Previously Completed"
        } else {
          task_completeness[i]="Incomplete"
        }
      } else {
        item_history[i] <- "New Item"
        if (list2$status[i]=="complete"){
          task_completeness[i] <- "Newly Completed"
        } else {
          task_completeness[i] <- "Incomplete"
        }
      }
    }
    changes <- data.frame(item=list2$item, history=item_history, status=task_completeness)
    changes
  }
}

Try the repello package in your browser

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

repello documentation built on Jan. 15, 2021, 3:35 p.m.