Title: | An Easy and Quick Way to Loop a Character Vector as a Menu in the Console |
---|---|
Description: | A fast way to loop a character vector or file names as a menu in the console for the user to choose an option. |
Authors: | John Piper [aut, cre] |
Maintainer: | John Piper <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.1 |
Built: | 2024-12-07 06:42:13 UTC |
Source: | CRAN |
wrapper function to console_menu.
console_file_menu( folder_path = ".", pattern = NULL, instruction_msg = "Type the number in the console your choice and press enter: ", quit_key = "q", quit_message = paste0("To quit please type ", quit_key, " and press return."), return_number = FALSE, test_args = list(test_mode = FALSE, test_input = NA_character_) )
console_file_menu( folder_path = ".", pattern = NULL, instruction_msg = "Type the number in the console your choice and press enter: ", quit_key = "q", quit_message = paste0("To quit please type ", quit_key, " and press return."), return_number = FALSE, test_args = list(test_mode = FALSE, test_input = NA_character_) )
folder_path |
character. |
pattern |
character. Regex pattern used in list.files. |
instruction_msg |
character. Message shows under the menu selection. |
quit_key |
character. Character value for the user to quit the menu. |
quit_message |
character. Character value to explain how to quit the menu. |
return_number |
logical. TRUE return number choice. FALSE returns the index of chr_vector. |
test_args |
list(test_mode logical, test_input character). Only use for testing. |
character
## Not run: console_file_menu("/folder/path/with/files") console_file_menu("/folder/path/with/files", ".bmp", instruction_msg = "Please select a file to open") console_file_menu(folder_path = "/folder/path/with/files", pattern = "example_doc", instruction_msg = "Choose a excel file to open", quit_key = "Q", quit_message = "Type in Q and press return to quit", return_number = TRUE) # Example code on how the function could be used user_choice <- console_file_menu("/folder/path/", ".doc") switch_result <- switch( user_choice, "document_one.doc" = # code here, "document_two.doc" = # code here, "q" = # exit code here ) # Example code if the function returned the number in the list user_choice <- console_file_menu("/folder/path/", ".doc", return_number = FALSE) switch_result <- switch( user_choice, "1" = # code here, "2" = # code here, "q" = # exit code here ) ## End(Not run)
## Not run: console_file_menu("/folder/path/with/files") console_file_menu("/folder/path/with/files", ".bmp", instruction_msg = "Please select a file to open") console_file_menu(folder_path = "/folder/path/with/files", pattern = "example_doc", instruction_msg = "Choose a excel file to open", quit_key = "Q", quit_message = "Type in Q and press return to quit", return_number = TRUE) # Example code on how the function could be used user_choice <- console_file_menu("/folder/path/", ".doc") switch_result <- switch( user_choice, "document_one.doc" = # code here, "document_two.doc" = # code here, "q" = # exit code here ) # Example code if the function returned the number in the list user_choice <- console_file_menu("/folder/path/", ".doc", return_number = FALSE) switch_result <- switch( user_choice, "1" = # code here, "2" = # code here, "q" = # exit code here ) ## End(Not run)
Prints out a menu from a character vector and waits for user selection
console_menu( chr_vector, instruction_msg = "Type the number in the console your choice and press enter: ", quit_key = "q", quit_message = paste0("To quit please type ", quit_key, " and press return."), return_number = TRUE, test_args = list(test_mode = FALSE, test_input = NA_character_) )
console_menu( chr_vector, instruction_msg = "Type the number in the console your choice and press enter: ", quit_key = "q", quit_message = paste0("To quit please type ", quit_key, " and press return."), return_number = TRUE, test_args = list(test_mode = FALSE, test_input = NA_character_) )
chr_vector |
character vector. |
instruction_msg |
character. Message shows under the menu selection |
quit_key |
character. Character value for the user to quit the menu |
quit_message |
character. Character value to explain how to quit the menu |
return_number |
logical. TRUE return number choice. FALSE returns the index of chr_vector |
test_args |
list(test_mode logical, test_input character). Only use for testing. |
character
## Not run: console_menu(c("Eat", "sleep", "code", "repeat")) console_menu(c("Eat", "sleep", "code", "repeat"), "What would you like to do?", "quit", "Type quit to exit") # Example code on how the function could be used user_choice <- console_menu(c("Eat", "sleep")) switch_result <- switch( user_choice, "1" = # code here, "2" = # code here, "q" = # exit code here ) # Example code if the function returned the name in the character vector user_choice <- console_menu(c("Eat", "sleep"), return_number = FALSE) switch_result <- switch( user_choice, "Eat" = # code here, "sleep" = # code here, "q" = # exit code here ) ## End(Not run)
## Not run: console_menu(c("Eat", "sleep", "code", "repeat")) console_menu(c("Eat", "sleep", "code", "repeat"), "What would you like to do?", "quit", "Type quit to exit") # Example code on how the function could be used user_choice <- console_menu(c("Eat", "sleep")) switch_result <- switch( user_choice, "1" = # code here, "2" = # code here, "q" = # exit code here ) # Example code if the function returned the name in the character vector user_choice <- console_menu(c("Eat", "sleep"), return_number = FALSE) switch_result <- switch( user_choice, "Eat" = # code here, "sleep" = # code here, "q" = # exit code here ) ## End(Not run)