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.
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
)
Path to one or more files to edit.
The title of the editor window (not honored by all editors, most external editors only display the file name or path).
Editor to use. Either the name of the program, or a string containing the command to run, using \ the filename in the command, or a function with 'file', 'title' and 'wait' arguments to delegate process of the files.
Encoding of the files. If ""
or native.enc
, the
files are considered as being already in the right encoding.
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.
Force replacement of files if template=
is not null.
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).
The function returns TRUE
if it was able to edit the files or
FALSE
otherwise, invisibly. Encountered errors are reported as warnings.
# 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