Description Usage Arguments Value Internal details Author(s) See Also Examples
The flatdoc
convention lets you edit plain-text documentation in the same file as your function's source code. flatdoc
is hardly ever called explicitly, but you will see it in text files produced by fixr
; you can also add it to such files yourself. mvbutils
extends help
so that ?myfunc
will display this type of documentation for myfunc
, even if myfunc
isn't in a package. There are no restrictions on the format of informal-help documentation, so flatdoc
is useful for adding quick simple help just for you or for colleagues. If your function is to be part of a maintained package (see mvbutils.packaging.tools
), then the documentation should follow a slightly more formal structure; use fixr( myfun, new.doc=T)
to set up the appropriate template.
1 2 3 4 5 6 | # ALWAYS use it like this:
# structure( function( ...) {body},
# doc=flatdoc( EOF="<<end of doc>>"))
# plaintext doco goes here...
# NEVER use it like this:
flatdoc( EOF="<<end of doc>>")
|
EOF |
character string showing when plain text ends, as in |
body |
replace with your function code |
... |
replace with your function arg list |
Character vector of class docattr
, as read from the current.source()
(qv) connection. The print method for docattr
objects just displays the string "# FLAT-FORMAT DOCUMENTATION", to avoid screen clutter.
This section can be safely ignored by almost all users.
On some text editors, you can modify syntax highlighting so that the "start of comment block" marker is set to the string "doc=flatdoc(".
It's possible to use flatdoc
to read in more than one free-format text attribute. The EOF
argument can be used to distinguish one block of free text from the next. These attributes can be accessed from your function via attr( sys.function(), "<<attr.name>>")
, and this trick is occasionally useful to avoid having to include multi-line text blocks in your function code; it's syntactically clearer, and avoids having to escape quotes, etc. mvbutils:::docskel
shows one example.
fixr
uses write.sourceable.function
to create text files that use the flatdoc
convention. Its counterpart FF
reads these files back in after they're edited. The reading-in is not done with source
but rather with source.mvb
, which understands flatdoc
. The call to doc=flatdoc
causes the rest of the file to be read in as plain text, and assigned to the doc
attribute of the function. Documentation can optionally be terminated before the end of the file with the following line:
1 | <<end of doc>>
|
or whatever string is given as the argument to flatdoc
; this line will cause source.mvb
to revert to normal statement processing mode for the rest of the file. Note that vanilla source
will not respect flatdoc
; you do need to use source.mvb
.
flatdoc
should never be called from the command line; it should only appear in text files designed for source.mvb
.
The rest of this section is probably obsolete, though things should still work.
If you are writing informal documentation for a group of functions together, you only need to flatdoc
one of them, say myfun1
. Informal help will work if you modify the others to e.g.
1 |
If you are writing with doc2Rd
in mind and a number of such functions are to be grouped together, e.g. a group of "internal" functions in preparation for formal package release, you may find make.usage.section
and make.arguments.section
helpful.
Mark Bravington
source.mvb
, doc2Rd
, dochelp
, write.sourceable.function
, make.usage.section
,
make.arguments.section
, fixr
, the demo in "flatdoc.demo.R"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ## Not run:
## Put next lines up to "<<end of doc>>" into a text file <<your filename>>
## and remove the initial hashes
#structure( function( x) {
# x*x
#}
#,doc=flatdoc("<<end of doc>>"))
#
#Here is some informal documentation for the "SQUARE" function
#<<end of doc>>
## Now try SQUARE <- source.mvb( <<your filename>>); ?SQUARE
## Example with multiple attributes
## Put the next lines up to "<<end of part 2>>"
## into a text file, and remove the single hashes
#myfun <- structure( function( attname) {
# attr( sys.function(), attname)
#}
#, att1=flatdoc( EOF="<<end of part 1>>")
#, att2=flatdoc( EOF="<<end of part 2>>"))
#This goes into "att1"
#<<end of part 1>>
#and this goes into "att2"
#<<end of part 2>>
## Now "source.mvb" that file, to create "myfun"; then:
myfun( 'att1') # "This goes into \\"att1\\""
myfun( 'att2') # "and this goes into \\"att2\\""
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.