R/choosing_templates.R

Defines functions get_template_form make_choice

Documented in get_template_form

#' @importFrom rlang .data
get_template_form = function(){
  forms = get_template_forms() %>%
    dplyr::mutate(id = dplyr::row_number())

  forms = forms %>% dplyr::filter(.data$title == "R") %>%
    rbind(forms %>% dplyr::filter(.data$title != "R"))

  forms %>%
    dplyr::select(
      .data$id, .data$title,
      .data$last_updated
    ) %>%
    print()

  choice = NA
  while(is.na(choice)){
    choice = select_template_form()
  }

  forms[choice,]
}


make_choice = function(){
  choice = readline("\nChoose a template by id, [default = 1]")
  if(choice == ""){
    choice = 1
  }else{
    choice = as.numeric(choice)
    if(is.na(choice)){
      print("bad choice, not numeric")
    }
  }
  return(choice)
}
jr-packages/jrTypeform documentation built on March 25, 2020, 9:55 p.m.