Description Housekeeping info Redefined functions Ess and mvbutils Display bugs Author(s) See Also
Package mvbutils is a collection of utilities offering the following main features:
Hierarchical organization of projects (AKA tasks) and sub-tasks, allowing switching within a single R session, searching and moving objects through the hierarchy, objects in ancestor tasks always visible from child (sub)tasks, etc. See cd
.
Improved function, text, and script editing facilities, interfacing with whichever text editor you prefer. The R command line is not frozen while editing, and you can have multiple edit windows open. Scriptlets can be edited as expressions, for subsequent calls to eval
. Function documentation can be stored as plain text after the function definition, and will be found by help
even if the function isn't part of a package. There is also a complete automatic text-format backup system for functions & text. See fixr
.
Automated package construction, including production of Rd-format from plain text documentation. Packages can be edited & updated while loaded, without needing to quit/rebuild/reinstall. See mvbutils.packaging.tools
.
"Lazy loading" for individual objects, allowing fast and transparent access to collections of biggish objects where only a few objects are used at a time. See mlazy
.
Miscellaneous goodies: local/nested functions (mlocal
), display of what-calls-what (foodweb
), multiple replacement (multirep
), nicely-formatted latex tables (xtable.mvb
), numerous lower-level lower-level utility functions and operators (mvbutils.utils
, mvbutils.operators
, extract.named
, mcut
, search.for.regexpr
, strip.missing
, FOR
)
To get the full features of the mvbutils package– in particular, the project organization– you need to start R in the same directory every time (your "ROOT task"), and then switch to whichever project from inside R; see cd
. Various options
always need to be set to make fixr
and the debug package work the way you want, so one advantage of the start-in-the-same directory-approach is that you can keep all your project-independent options()
, library loads, etc., in a single .First
function or ".Rprofile" file, to be called automatically when you start R. However, many features (including support for the debug package) will work even if you don't follow this suggestion.
The remaining sections of this document cover details that most users don't know about; there's no need to read them when you are just starting out with mvbutils
.
On loading, the mvbutils package creates a new environment in the search path, called mvb.session.info
, which stores some housekeeping information. mvb.session.info
is never written to disk, and disappears when the R session finishes. [For Splus users: mvb.session.info
is similar to frame 0.] You should never change anything in mvb.session.info
by hand, but it is sometimes useful to look at some of the variables there:
.First.top.search
is the directory R started in (your ROOT task).
.Path
shows the currently-attached part of the task hierarchy.
base.xxx
is the original copy of an overwritten system function, e.g. library
fix.list
keeps track of objects being edited via fixr
session.start.time
is the value of Sys.time()
when mvbutils
was loaded
source.list
is used by source.mvb
to allow nesting of sources
r.window.handle
is used by the handy package (Windows only)
partial.namespaces
is used to alleviate difficulties with unloadable data files– see mvbutils.packaging.tools
things whose name starts with ".." are environments used in live-editing packages
maintained.packages
is a list of the latter
On loading, package mvbutils redefines a few system functions: lockEnvironment
, importIntoEnv
loadNamespace
, print.function
, help
, rbind.data.frame
and, by default, library
, savehistory
, loadhistory
, and save.image
. (The original version of routine xxx
can always be obtained via base.xxx
if you really need it.) The modifications, which are undone when you unload mvbutils
, should have [almost] no side-effects. Briefly:
library
is modified so that its default pos
argument is just under the ROOT workspace (the one that was on top when mvbutils
was loaded), which is needed by cd
. This means that packages no longer get attached by default always in position 2.
lockEnvironment
and importIntoEnv
are modified to allow live-editing of your own maintained packages– no change to default behaviour.
loadNamespace
has the default value of its "partial" argument altered, to let you bypass .onLoad
for selected faulty packages– see mvbutils.packaging.tools
and look for partial.namespaces
. This allows the loading of certain ".RData" files which otherwise crash from hidden attempts to load a namespace. It lets you get round some truly horrendous problems arising from faults with 3rd-party packages, as well as problems when you stuff up your own packages.
rbind.data.frame
does not ignore zero-row arguments (so it takes account of their factor levels, for example).
rbind.data.frame
: dimensioned elements (i.e. matrices & arrays within data.frames) no longer have any extra attributes removed. Hence, for example, you can (if you are also using my nicetime
package) rbind
two data frames that both have POSIXct-matrix elements without turning them into raw seconds and losing timezones.
help
and ?
are modified so that, if utils:::help
can't find help for a function (but not a method, dataset, or package), it will look instead for a doc
attribute of the function to display in a pager/browser using dochelp
. Character objects with a ".doc" extension will also be found and displayed. This lets you write and distribute "informal help".
loadhistory
and savehistory
are modified so that they use the current "R_HISTFILE" environment variable if it set. This can be set dynamically during an R session using Sys.setenv
. Standard R behaviour is to respect "R_HISTFILE" iff it is set before the R session starts, but not to track it during a session. If "R_HISTFILE" is not set, then cd
will on first use set "R_HISTFILE" to "<<ROOT task>>/.RHistory", so that same the history file will be used throughout each and every session.
save.image
is modified to call Save
instead; this will behave exactly the same for workspaces not using mvbutils
task-hierarchy feature or the debug package, but otherwise will prevent problems with mtrace
d functions and mlazy
ed objects.
print.function
is modified to let you go on seamlessly using functions written prior to R 2.14 in conjunction with the srcref
system imposed by R 2.14; see fixr
.
Some of these redefinitions are optional and can be turned off if you really want: loadhistory
, savehistory
, save.image
, library
, lockEnvironment
, importIntoEnv
, and loadNamespace
. To turn them off, set options(mvbutils.replacements=FALSE)
before loading mvbutils
. However, I really don't recommend doing so; it will prevent cd
etc, fixr
, and the package-maintenance tools from working properly, and if you use debug
you will probably cause yourself trouble when you forgetfully save.image
an mtrace
d function. You can also set the "mvbutils.replacements" option to a character vector comprising some or all of the above names, so that only those happen; if so, you're on your own. The other replacements are unavoidable (but should not be apparent for packages that don't import mvbutils
).
After mvbutils
has loaded, you can undo the modification of a function xxx
by calling assign.to.base( "xxx", base.xxx)
. Exceptions are help
, ?
, print.function
, rbind.data.frame
which are intrinsic to mvbutils. Unloading
mvbutils' will undo all the modifications.
POSIXct
etc have some nasty behaviour, and mvbutils
used to include some functions that ameliorated things. I've moved them into a separate package nicetime, available on request.
For ESS users: I'm not an Emacs user and so haven't tried ESS with the mvbutils package myself, but a read-through of the ESS documentation (as of ~2005) suggests that a couple of ESS variables may need changing to get the two working optimally. Please check the ESS documentation for further details on these points. I will update this helpfile when/if I receive more feedback on what works (though there hasn't been ESS feedback in ~8 years...).
cd
changes the search list, so you may need to alter "ess-change-sp-regex" in ESS.
cd
also changes the prompt, so you may need to alter "inferior-ess-prompt". Prompts have the form WORD1/WORD2/.../WORDn> where WORDx is a letter followed by zero or more letters, underscores, periods, or digits.
move
can add/remove objects in workspaces other than the top one, so if ESS relies on stored internal summaries of "what's where", these may need updating.
If you have a buggy Linux display where readline()
always returns the cursor to the start of the line, overwriting any prompt, then try options( cd.extra.CR=TRUE)
.
Mark Bravington
cd
, fixr
, mlazy
, flatdoc
, dochelp
, maintain.packages
, source.mvb
, mlocal
, do.in.envir
, foodweb
, mvbutils.operators
, mvbutils.utils
, mvbutils.packaging.tools
, package debug
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.