read_line: Read a line from the terminal

Description Usage Arguments Value Examples

Description

Read a line from the terminal

Usage

1
2
read_line(prompt = "", multiline = FALSE, history = NULL,
  completions = NULL)

Arguments

prompt

A string that is printed at the beginning of the line of the user input. Ideally it should be short, so there is enough space for the input. It can be colored and styled with ANSI escape sequences from the crayon package.

multiline

Whether to use multi-line mode. This is ignored on unsupported terminals, those work similarly to multi-line mode, anyway.

history

If not NULL, then it must be a character scalar, the name of the file that is used as a browseable history. The newly entered entry is added to this file. Note that history might not be supported by the base::readline fallback method.

completions

A character vector of possible TAB-completions. Ignored on unsupported terminals that use the base::readline fallback mechanism.

Value

A character scalar, the string that was read.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Not run: 
  read_line(prompt = "what> ")

  ## History files
  hist <- tempfile()
  cat("previous entry\n", file = hist, append = TRUE)
  cat("another entry\n", file = hist, append = TRUE)
  read_line(prompt = "what> ", history = hist)

  ## The new entry is added to the history file
  readLines(hist)

  ## TAB-completion
  read_line(prompt = "what> ", completions = c("foobar", "foo", "bar"))

## End(Not run)

gaborcsardi/readline documentation built on May 16, 2019, 4:15 p.m.