fixr
opens a function in your preferred text editor. Control returns immediately to the Rcommand line, so you can keep working in Rand can be editing several functions simultaneously (cf edit
). A session-duration list of files/functions being edited is maintained, so that the function can be easily sourced back in to the right workspace, either by calling FF()
or automatically on file change. There is an optional automatic text backup facility. readr
also opens a file in your text editor, but in read-only mode, and doesn't update the backups or the list of functions being edited.fixr( x, new=FALSE, install=FALSE)
readr( x, install=FALSE)
FF()
fixr
is run for the first time (or if you set install=TRUE
), it will ask you for some basic information about your text editor. In particular, you'll need to know what to type to invoke your text editor from the command shell (MS-DOS prompt on Windows) on a specific file. After supplying these details, fixr
will launch the editor and print a message showing some options
("backup.fix"
, "edit.scratchdir"
and "program.editor"
), that will need to be set in your .First
. function-- which you can do via fixr(.First)
.
readr
requires a similar installation process. To get the read-only feature, you'll need to add some kind of option/switch on the command line that invokes your text editor; not all text editors support this feature. Similarly to fixr
, you'll need to set options( program.reader=<>)
in your .First
; the installation process will tell you what to use.
fixr
creates a blank function template if none existed, or if new=TRUE
is specified.
If the function has attributes, it's wrapped in a structure(...)
construct. If a doc
attribute exists, it's printed as free-form text at the end of the file, and the call to structure
will end with a line similar to:
,doc=flatdoc( EOF="<source.mvb
for technical details), that line will cause the rest of the file to be read in as a doc
attribute, which can be displayed by help
. If you want to add "flat-format documentation", you can also add these lines yourself-- see flatdoc
.
To read functions back in again, call FF()
, which checks the modification times of any function files. If any have been updated, FF
sources in the code and modifies the appropriate functions. It tries to write functions back into the workspace they came from, which might not be .GlobalEnv. If not, you'll be asked whether you want to save.image
that workspace (provided it's a "task"-- see cd
). FF
should still put the function in the right place, even if you've called cd
after calling fixr
(unless you've detached the original task) or if you move
d it.
FF
can be called automatically whenever a valid command is executed (e.g. by typing 0autoFF
for how to do this.
If the function was being mtrace
d (see help(package=debug)
), FF
will re-apply mtrace
after loading the edited version.
If there is a problem with parsing, the source
attribute of the function is updated to the new code, but the function body is invisibly replaced with a stop
call, stating that parsing failed. FF
also prints an immediate warning.
The list of functions being edited by fixr
is stored in the variable fix.list
in the mvb.session.info
environment. When you quit and restart R, the function files you have been using will stay open in the editor, but fix.list
will be empty; hence, updating the file "myfun.r" will not update the corresponding Rfunction. If this happens, just type fixr(myfun)
in Rand when your editor asks you if you want to replace the on-screen version, say no. Save the file again (some editors require a token modification, such as space-then-delete, first) and Rwill notice the update.
An automatic text backup facility is available from fixr
and FF
: see ?get.backup
. The backup system also allows you to sort functions by edit date; see ?fix.order
..First
, edit
, cd
, get.backup
, fix.order
, move
, autoFF