Learn R Programming

svMisc (version 0.9-68)

fileEdit: 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

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
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.

concept

file edition

See Also

systemFile, file.path, file.exists, file.edit

Examples

Run this code
## Create a template file in the tempdir...
tpl <- tempfile("template", fileext = ".txt")
cat("Example template file\nto be used with fileEdit()\n", file = tpl)

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

## Make sure the content ends with \n, and read it
cat("\n", file = newf, append = TRUE)
cat("Your file contains:\n")
readLines(newf)

## Eliminate both the file and template
unlink(newf)
unlink(tpl)

Run the code above in your browser using DataLab