FileOpenCmd: Get Path of a Data File to Be Opened

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/DescTools.r

Description

Handling of pathnames is tedious in Windows because of the backslashes, that prevent simple pasting of a copied path into the source code. FileOpenCmd displays the FileOpen-Dialog for picking a file interactively. When done, backslashes in the returned path will be replaced by simple slashes as used in R path definitions.The edited path is invisibly returned and also written to the clipboard, from where it can easily be pasted in any code editor.

This is especially helpful in combination with RStudio's new AddIns-option.

Usage

1

Arguments

fmt

the format, in which the filename parts should be returned. This can be defined quite flexible containing the elements path, filename and ext (file extension) enclosed by %.
Default is path/filename.ext and coded as "%path%%filename%.%ext%". See examples for additional alternative definitions.

Details

There are 2 predefined formats that can be addressed with fmt = 1 resp. fmt = 2. 1 will return the path enclosed by a typical read.table(...) command, 2 will do the same with load(...).

Value

character string containing the path (also present in the clipboard)

Author(s)

Andri Signorell <[email protected]>

See Also

file.choose

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## Not run: 
# choose a file
fn <- FileOpenCmd()
print(gettextf("You chose the file: %s ", fn))

# the path and filename can as well be nested in a command,
#   done here to build a read.table command that can be well inserted into the code:
FileOpenCmd(fmt="d.%fname% <- read.table(file = \"%path%\%fname%.%fxt%\",
  header = TRUE, sep = \";\", na.strings = c(\"NA\",\"NULL\"), strip.white = TRUE)")

# go to your editor and paste...

## End(Not run)

DescTools documentation built on March 19, 2018, 9:03 a.m.