Reputation: 52228
When opening help docs within RStudio with something like ?"function"
, how can we (easily) get the web version of these help docs?
Currently I look for a unique-ish sentence and google it with quotes. For example, to find the web version of ?"function"
, I googled "These functions provide the base mechanisms for defining new functions in the R language."
- but there must be something more efficient?
Upvotes: 2
Views: 1012
Reputation: 46856
In an R session outside RStudio, typing help.start()
, clicking on 'Search engine & keywords' and searching for, e.g., xtabs
results in a listing that includes stats::xtabs
; clicking on that link opens, for me, a url http://127.0.0.1:18412/library/stats/html/xtabs.html. The url consists of the local host http://127.0.0.1
, a port 18412
, and a path /library/stats/html/xtabs.html
. The fact that this is an http request on localhost implies that R is running a local http server (started by help.start()
, also by RStudio on startup).
The port is available (after the help server starts) with
> tools:::httpdPort()
[1] 18412
The path can be reconstructed from
paths = as.character(help('xtabs'))
where the path(s) returned indicate which (currently loaded) packages reference xtabs
and the relevant components (library and term) can be extracted with
pattern = paste0(R.home(), "(/library/[^/]+)/help(/.+)")
lib = sub(pattern, "\\1", paths)
term = sub(pattern, "\\2", paths)
Thus the url can be constructed as
> url = paste0("http://127.0.0.1:", port, lib, "/html", term, ".html")
and opened with, e.g.,
browseURL(url)
There are a number of challenges with this, e.g., when more than one package defines an alias to xtabs
(so that paths
and all subsequent steps have multiple elements).
For what it's worth, the individual help pages are not by default available directly with R, but rather are created dynamically by the web server. E.g., note that
> dir(R.home("library/stats/html"))
[1] "00Index.html" "R.css"
> browseURL(R.home("library/stats/html/00Index.html"))
displays the index page, but clicking on the xtabs
link results in a 404 file not found. Static pages can be generated when R and / or packages are installed with R CMD INSTALL --html ...
Upvotes: 3
Reputation: 383
If you want a webpage that gathers help files from several packages and organizes it in some way, I think you are looking for rdocumentation(dot)org. You just have to type what you want in the search bar.
Normally the docs are stored in your computer when you install the packages, that's why there's not a webpage with all of them. They're store locally.
I don't think there's any other place on the internet that does that.
Upvotes: 2