Learn R Programming

mvbutils (version 1.1.0)

write.sourceable.function: Sourceable code for functions with flat-format documentation

Description

Works like "write" for functions without flat documentation (i.e. without a "doc" attribute). If a "doc" attribute exists, the file is written in a form allowing it to be edited and then read back in with "source.mvb"; the "doc" attribute is given as free-form text following the function definition.

Usage

write.sourceable.function( x, con, append=FALSE, print.name=FALSE, doc.special=TRUE)

Arguments

x
function object (or the name of a function) to be output
con
a connection or filename
append
if "con" is not already open, should it be appended to rather than overwritten?
print.name
should output start with "NAME" <- (where NAME is deduced from x)?
doc.special
TRUE if doc attribute is to be printed as flat doc-- assumes readback via source.mvb

Details

If x is unquoted and print.name=TRUE, the name is obtained from deparse( substitute( x)). If x is a character string, the name is x itself and the function printed is get(x). The real criterion for an attribute to be output in flatdoc-style, is not whether the attribute is called doc, but rather whether it is a character-mode object of class docattr. You can use this to force flatdoc-style output of several doc-like attributes. The default EOF line for an attribute is <>, but this will be adjusted if it appears in the attribute itself.

See Also

source.mvb, readLines.mvb, flatdoc, the file "demo/original.dochelp.rrr", the demo in "flatdoc.demo.r"

Examples

Run this code
write.sourceable.function( write.sourceable.function, "wsf.r")
# To dump all functions and their documentation in a workspace into a single sourceable file:
cat( "", file="allfuns.r")
sapply( find.funs(), write.sourceable.function, file="allfuns.r", append=TRUE, print.name=TRUE)

Run the code above in your browser using DataLab