Learn R Programming

svMisc (version 1.1.0)

file_edit: Invoke an external text editor for a file

Description

Edit a text file using an external editor. Possibly wait for the end of the program and care about creating the file (from a template) if it does not exists yet.

Usage

file_edit(..., title = files, editor = getOption("fileEditor"),
  file.encoding = "", template = NULL, replace = FALSE, wait = FALSE)

fileEdit(..., title = files, editor = getOption("fileEditor"), file.encoding = "", template = NULL, replace = FALSE, wait = FALSE)

Arguments

...

Path to one or more files to edit.

title

The title of the editor window (not honoured by all editors, most external editors only display the file name or path).

editor

Editor to use. Either the name of the program, or a string containing the command to run, using %s as replacement tag where to place the filename in the command, or a function with 'file', 'title' and 'wait' arguments to delegate process of the files.

file.encoding

Encoding of the files. If "" or native.enc, the files are considered as being already in the right encoding.

template

One or more files to use as template if files must be created. If NULL, an empty file is created. This argument is recycled for all files to edit.

replace

Force replacement of files if template= is not null.

wait

Wait for edition to complete. If more than one file is edited, the program waits sequentially for each file to be edited in turn (with a message in the R console).

Value

The function returns TRUE if it was able to edit the files or FALSE otherwise, invisibly. Encountered errors are reported as warnings.

See Also

system_file(), file.path(), file.edit()

Examples

Run this code
# NOT RUN {
# Create a template file in the tempdir...
template <- tempfile("template", fileext = ".txt")
cat("Example template file to be used with file_edit()", file = template)

# ... and edit a new file, starting from that template:
new_file <- tempfile("test", fileext = ".txt")
file_edit(new_file, template = template, wait = TRUE)

message("Your file contains:")
readLines(new_file)

# Eliminate both the file and template
unlink(new_file)
unlink(template)
# }

Run the code above in your browser using DataLab