write.sourceable.function: Sourceable code for functions (and more) with flat-format...

Description Usage Arguments Details See Also Examples

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. If applied to a non-function with a "source" attribute, just the source attribute is printed; the idea is that this could be read back by source (or source.mvb), probably in the course of FF after fixr, to regenerate the non-function object.

Usage

1
2

Arguments

x

function or other object, or the name thereof, that is to be written. If x is not a function, then it must have an attribute "source".

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

xn

(string) can set this to be the name of the function if print.name is TRUE

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 <<end of doc>>, but this will be adjusted if it appears in the attribute itself.

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## Not run: 
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)
# A non-function
scrunge <- c( 1:7, 11)
attr( scrunge, "source") <- c( "# Another way:", "c( 1:4, c( 5:7, 11))")
scrunge # [1] 1 2 3 4 5 6 7 11
write.sourceable.function( scrunge, stdout()) # source
fixr( scrunge) # source

## End(Not run)

mvbutils documentation built on May 2, 2019, 8:32 a.m.