Converts f_usage objects to text appropriate for usage sections in Rd files. Handles S3 methods.
1 2 3 4
an object from class
maximal width of text on a line.
deparse_usage1 and the
as.character method for
"f_usage", convert an
"f_usage" object to a
character string suitable for Rd documentation. The
as.character method is the user level function (it just calls
deparse_usage1 is internal function for
programming. In the example below the first command creates an
"f_usage" object, then the second converts it to character string.
(a <- pairlist2f_usage1(formals(cor), "cor"));cat(as.character(a))
Each usage entriy is formatted and, if necessary, split over several
lines. The width (number of characters) on a line can be changed with
deparse_usage can be used when
x is a list of
"f_usage" objects. It calls
deparse_usage1 with each of
them and returns a character vector with one element for each
x is an object from class
deparse_usage is equivalent to
as.character.f_usage, a named
character vector of length one (the name is the function name).
deparse_usage, a named character vector with one entry for
the usage text for each function.
Georgi N. Boshnakov
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
cur_wd <- getwd() tmpdir <- tempdir() setwd(tmpdir) ## prepare a list of "f_usage" objects fnseq <- reprompt(seq) # get and save the help page of "seq" rdoseq <- tools::parse_Rd(fnseq) # parse the Rd file ut <- get_usage_text(rdoseq) # get the contents of the usage section cat(ut, "\n") # of seq() (a character string) utp <- parse_usage_text(ut) # parse to a list of "f_usage" objects ## deparse the "f_usage" list - each statement gets a separate string cat(deparse_usage(utp), sep = "\n") ## explore some of the usage entries individually; ## the generic seq() has a boring signature utp[] as.character(utp[]) deparse_usage1(utp[]) # same ## the default S3 method is more interesting utp[] cat(deparse_usage1(utp[])) cat(as.character(utp[])) # same unlink(fnseq) setwd(cur_wd) unlink(tmpdir)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.