Fix a Function.

DESCRIPTION:
Invokes an editor on object and assigns the edited version.

USAGE:
fix(x, file=tempfile("fix"), window=F, display=getenv("DISPLAY"),
      geometry="80x24", diff=F, fix=T, save.options=T)

OPTIONAL ARGUMENTS:
x:
The unquoted name of an S-PLUS object to edit. If the object does not exist, an empty template function will be edited. If x is omitted, fix attempts to determine what was last fixed, and uses that. This applies whether or not there was an error last time.
file:
character string naming a file to use for editing. If missing, a temporary file is created.
window:
logical flag: if TRUE, the editor will be started in its own window. This option is currently implemented only for X11-based window systems. For it to work, either display must be specified or the environment variable DISPLAY must be set, and the window system must be running.
display:
character string specifying which X11 server should receive the window. Argument window must be TRUE for this to have any effect. If window=TRUE and display is omitted, the DISPLAY environment variable is examined.
geometry:
character string specifying the geometry parameters for the X11 window. Meaningful only when window=TRUE. See the UNIX xterm manual page for syntax.
diff:
logical flag or character string, specifying whether a listing of differences between the old and new versions of x should be produced at the end of the edit session. If diff is a character string, it should name a UNIX program, optionally with flags, which takes two file names as arguments and writes on standard output. If diff=TRUE, the program defaults to UNIX diff.
fix:
logical flag: if FALSE, nothing is edited. Used to change the option values without modifying anything else. See the OPTIONS section below.
save.options:
logical flag: if TRUE, the current option values will be saved. See the OPTIONS section.

VALUE:
If fix=TRUE, the new version of the edited object is invisibly returned. It is not usually necessary to capture this, because it will also be automatically assigned under the name passed in x. If fix=FALSE, a list containing the previous values of the saved options is invisibly returned.

SIDE EFFECTS:
A new version of the edited object is automatically assigned on the working database, if there were no errors.

DETAILS:
The basic functionality of fix is like f <- vi(f). Whereas vi, ed, and data.ed accept any expression and return the edited version of the data, assigning nothing, fix expects a name and will assign the new version of the object under that name.

OPTIONS:
The arguments window, display, geometry, and diff are saveable options. If save.options=TRUE, the default, then the values of any of these options explicitly named in a call to fix will be remembered, and used automatically in the next call during the same S-PLUS session. When S-PLUS exits, the option values are discarded; fix will revert to the defaults described above in the next session. (But see below.)

To use a different option value for only the current call to fix, specify save.options=FALSE. To change an option value and save it without editing anything, specify fix=FALSE. Thus one can customize fix options automatically at the start of each S-PLUS session by putting, for example, fix(window=T, diff=T, fix=F) in function .First or environment variable S_FIRST.

The editor program and the pager program (to page the diff) are global S-PLUS options. See the options helpfile.


ERROR:
If the file cannot be read back in, most typically because of a syntax error, the message "Errors occurred; Use fix() to re-edit this object." will appear on the screen. Typing fix() with no x argument will then start the editor on the same file, whose contents will reflect the previous edit session. When the file can be read back into S-PLUS, the object will be assigned as usual.

It is important that such errors be corrected as described before any other use of the fix function, and before exiting the S-PLUS session. Otherwise it may be difficult to locate the file containing one's work.


LIMITATIONS:
fix will be most useful with S-PLUS functions. Though it will often work with matrices, etc., data.ed is recommended there.

SEE ALSO:
data.ed , ed , vi , options .

EXAMPLES:
fix(my.fun)    # edit and re-assign my.fun
fix()          # edit my.fun again
fix(new.fun)   # new.fun does not exist yet
fix(f)   # we will leave a syntax error in the file
# Syntax error: Unbalanced parentheses, expected "}", before ")"
# at line 4, file /tmp/fix17056
# Dumped
Errors occurred; Use fix() to re-edit this object.
fix()    # get back into same file; omit x argument
fix(f, diff=T)    # show me what I changed
fix(f, diff="diff -c")        # print a context diff
fix(f, window=T, geometry="80x24+50+50")
      # make X11 window 80 characters wide and 24 lines long,
      # and [always] place it at coordinates (50,50)
fix(f, window=T, geometry="80x50", save.options=F)
      # long window, this time only
fix(window=T, diff=T, fix=F)    # set new defaults; no editing
args(fix)
      # show function argument defaults, ignoring saved overrides
print(fix(fix=F))   # show saved override values