MyNixOS website logo
Description

An Easy and Quick Way to Loop a Character Vector as a Menu in the Console.

A fast way to loop a character vector or file names as a menu in the console for the user to choose an option.

consolechoice

R-CMD-check CRANstatus Codecov testcoverage

The goal of consolechoice is to make it easier to display a menu to the console for the user to select an option. This will save time writing code with loops and conditional logic. Only one line of code is required using consolechoice to solve this issue.

consolechoice allows character vectors or folder paths as an argument to print the menu to the console. Regular expression syntax can also be used to limit certain file types or names for selection.

consolechoice helps take away the complexity of showing a menu in the console and waiting for the users choice.

Installation

You can install the development version of consolechoice from GitHub with:

# install.packages("devtools")
devtools::install_github("John-Piper/consolechoice")

Usage

library(consolechoice)

# Example using console_menu function.

options <- c("Eat", "Sleep", "Code", "Repeat")


choice <- console_menu(options)

result <- switch(
  choice,
       "1" = "Eating some food",
       "2" = "Going to Sleep",
       "3" = "Doing some coding",
       "4" = options,
       "q" = stop("You have decided to quit")
)
       
print(result)


# Example using console_file_menu function.

choice <- console_file_menu(
  folder_path ="example/foler/address",
  pattern = ".txt"
  )

if (choice == "example.txt") {
  
  # code here...
  
} else {
  
  # more code here...
  
}
Metadata

Version

1.1.1

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows