select_single_file: Interactively choose a single file

Description Usage Arguments Details Value

View source: R/misc_fun.R

Description

This is a convenient wrapper to select one file in the directory path from multiple files matching pattern.

Usage

1
2
3
4
5
6
7
8
9
select_single_file(
  path = getwd(),
  prefix = ".+",
  suffix = "*",
  pattern = NULL,
  filetype = "file",
  caption = "Select a",
  label = "Select"
)

Arguments

path

A character vector of file paths; the default corresponds to the working directory, getwd(). Tilde expansion (see path.expand) is performed.

prefix

A regular expression to match the filename (without extension).

suffix

A character to match the file extension, e.g. "csv".

pattern

A regular expression. Only file names which match the regular expression will be returned.

filetype

A human-readable file type designation. Along with suffix will be used to construct filter in rstudioapi::selectFile.

caption

The window title.

label

The label to use for the 'Accept' / 'OK' button.

Details

In case multiple files are found, the user is prompted to choose one option or none.

If pattern is not NULL, prefix and suffix will be ignored.

prefix is ignored when the RStudio API is used.

Value

A character vector with a single element in case a single file matches pattern or a single choice was made, else an empty character vector.

In a non-interactive session, returns an empty character vector and a warning if multiple files were found.


benjbuch/summerr documentation built on July 11, 2021, 9:40 a.m.