How to write contents of help to a file from within R?

前端 未结 2 1684
再見小時候
再見小時候 2020-12-04 01:13

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
相关标签:
2条回答
  • 2020-12-04 02:09

    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)
    • Then follow these instructions to save less buffer to file
      • i.e., type 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
        • and ending at $ which indicates the end of the buffer
        • to the shell command tee which allows standard out to be sent to a file
    0 讨论(0)
  • 2020-12-04 02:13

    Looks 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.

    0 讨论(0)
提交回复
热议问题