I\'d like to be able to write the contents of a help file in R to a file from within R. The following works from the command-line:
R --slave -e \'library
While Joshua's instructions work perfectly, I stumbled upon another strategy for saving an R helpfile; So I thought I'd share it. It works on my computer (Ubuntu) where less
is the R pager. It essentially just involves saving the file from within less
.
help(survey)
less
buffer to file
g|$tee survey.txt
g
goes to the top of the less buffer if you aren't already there|
pipes text between the range starting at current mark$
which indicates the end of the buffertee
which allows standard out to be sent to a fileLooks like the two functions you would need are tools:::Rd2txt
and utils:::.getHelpFile
. This prints the help file to the console, but you may need to fiddle with the arguments to get it to write to a file in the way you want.
For example:
hs <- help(survey)
tools:::Rd2txt(utils:::.getHelpFile(as.character(hs)))
Since these functions aren't currently exported, I would not recommend you rely on them for any production code. It would be better to use them as a guide to create your own stable implementation.