Reputation: 4145
I found a number of functions here on stackoverflow that extract the html code of help files from within R but I would like to access the help files from an external script (Python). How can I get the actual html code of the help file from outside of R?
Here are possible solutions:
Use console call to R from Python or other language such as this one R --slave -e 'library(MASS); help(survey)' > survey.txt The problem with this approach is that I often don't know in which package a specific function is. So this approach does not really work. Or are there work arounds?
Extract all help files from R and save them in a database, which can be accessed from an external script. Shouldn't be to hard but it's kind of annoying also because this help database has to be updated by rerunning the script.
Access R's help database directly but I have no idea about the structure etc!?
Any ideas and possible solutions?
Edit: I also thought about the helpr
package but wasn't able to try it with R 2.15 because of this bug
https://github.com/hadley/helpr/issues/27
Upvotes: 1
Views: 143
Reputation: 162321
If you are able to compile R from its sources, then directly accessing the help files (your option 3) seems like it may be the cleanest and easiest approach.
The various html help files that come with an R binary distribution are stored in:
R_HOME/doc/html/ # CHANGES, NEWS, other miscellany
R_HOME/doc/manual/ # An Intro to R, R Language Definition, etc.
R_HOME/library/<pkg-name>/html/ # help files for packages
Unfortunately for your purposes, (as explained in section 2.2 of R-admin), "by default, HTML help pages are created when needed rather than being built at install time". At least for Windows (and, it appears, for Mac) the standard R binaries available from CRAN were built with these default settings.
If you are willing/able to compile R from its sources, you can set an optional flag/directive telling R to create those static HTML help pages. On UNIX (and, I'd guess Mac OS X) operating systems, do this by setting the configure option --enable-prebuilt-html
. On Windows, set BUILD_HTML = YES
in either "MkRules.dist" or "MkRules.local" prior to running make all recommended
.
Upvotes: 1