doc
attribute, or on a separate text object (useful for package and dataset documentation). doc2Rd
will produce legal Rd even with completely informal documentation (see Details). However, if your documentation looks like plain pager-style R help, then doc2Rd
makes a big effort to generate the special Rd fields (sections, code fragments, links, URLs, etc) that result in nice-looking help.
You probably won't need to call doc2Rd
yourself, because pre.install
does it for you when you are building a package; the entire documentation of package doc2Rd( text, file=NULL, append=, warnings.on=TRUE)
doc
attribute that is a c.v. of d..!is.null(file)
; should output be appended rather than overwriting?class
of "cat" so it prints nicely on the screen..GlobalEnv
and .BaseNamespaceEnv
go into \dochelp
, though, so can be used to hide an unhelpful USAGE, say, or to hide an "#ifdef windows".
Triple dots are converted to \doc2Rd
runs, the docfile name will appear in both the \pre.install
will actually create the file "utility-funs.Rd". The next non-blank lines form the other alias entries. Each line should consist of one word, preceded by one or more spaces for safety (not necessary if they have normal names).
"Informal documentation" is interpreted as any documentation that doesn't include a "DECRIPTION" line (or a "Description:" line). If this is the case, doc2Rd
first looks for a blank line, treats everything before it as \print.cat
, the USAGE section should contain a call to print(x,...)
rather than print.cat(x,...)
. doc2Rd
will detect this and produce correct Rd format. If you document several different S3 methods for the same generic in the same piece of documentation (and even if you don't), then it may help the user if you put a comment with the method name after each call, e.g. print(x,...) # print.cat
, especially if the optional arguments are different. Doing that also gives pre.install
a better chance of correctly sorting out the documentation.
Sometimes you have a function which looks like it might be an S3 method, but isn't (e.g. as.data.frame.I
in package pre.install
because you will of course have used the full name in the USAGE section, because it isn't a method.
S3 classes themselves need to be documented via a relevant function, using aliasses.
Q: What about S4?
A: I am not a fan of S4 and have found no need for it in many 1000s of lines of R code...hence I haven't included any explicit support for it so far. Nevertheless, things might well work anyway, unless special Rd constructs are needed. If doc2Rd
doesn't work for your S4 stuff (bear in mind that the %-line mechanism may help), then for now you'll still have to write S4 Rd files yourself; see pre.install
for where to put them. However, if anyone would like the flatdoc facility for S4 and is willing to help out, I'm happy to try to add support.doc
attributes can be displayed by the replacement help
in mvbutils
(see dochelp
) without any further ado. This is very useful while developing code before the package-creation stage, and you can write such documentation any way you want. When you want to generate a package, doc2Rd
will convert pretty much anything into a legal Rd file. However, if you can follow a very few rules, using doc2Rd
will actually give nice-looking authentic R help. For this to work, your documentation basically needs to look like a plain-text help file, as displayed by help( ..., pager=T)
.
Rather than wading through this help file to work out how to write plain-text help, just have a look at a couple of R's help screens in the pager (i.e. not HTML or CHM help) and try making one yourself. You can also use help2flatdoc
to convert an existing plain-text help file. Also check the file "sample.fun.rrr" in the "demostuff" subdirectory of this package (see Examples). If something doesn't work, delve more deeply...help
will display a \\'myfun( "'No no no!'")'
pre.install
.
To check the results: "RCMD Rd2dvi --pdf XXX.Rd" and "RCMD Rdconv -t=html XXX.Rd" and/or "-t=txt" (though patch.installed
will allow to check the HTML version immediately).
To convert existing Rd documentation: help2flatdoc
.
If you want to tinker with the underlying mechanisms: flatdoc
, write.sourceable.function
## Needs a function with the right kind of "doc" attr
## Look at file "demostuff/sample.fun.rrr"
lodlibs <- library()[[2]]
mvb.lib.loc <- lodlibs[ lodlibs[,1]=='mvbutils', 2][1]
sample.fun <- source.mvb( file.path( mvb.lib.loc, 'mvbutils', 'demostuff', 'sample.fun.rrr'))
cat( '***Original plain-text doco:***\n')
print( as.cat( attr( sample.fun, 'doc'))) # unescaped, ie what you'd actually edit
cat( '\n***Rd output:***\n')
sample.fun.Rd <- doc2Rd( sample.fun)
print( sample.fun.Rd) # already "cat" class
Run the code above in your browser using DataLab