Force R help HTML server to always use the same URL port

October 22, 2012
By

(This article was first published on jottR, and kindly contributed to R-bloggers)

The below code shows how to configure the ‘help.ports’ option in R such that the built-in R help server always uses the same URL port. Just add it to the .Rprofile file in your home directory (iff missing, create it). For more details, see help(“Startup”).

# Force the URL of the help to http://127.0.0.1:21510
options(help.ports=21510);

A slighter fancier version is to use a environment variable to set the port(s):

local({
ports <- Sys.getenv("R_HELP_PORTS", 21510);
ports <- as.integer(unlist(strsplit(ports, ",")));
options(help.ports=ports);
})

However, if you launch multiple R sessions in parallel, this means that they will all try to use the same port, but it’s only the first one that will success and all other will fail.  An alternative is then to provide R with a set of ports to choose from (see help(“startDynamicHelp”, package=”tools”)). To set the ports to 21510-21519 if you run R v2.15.1, to 21520-21529 if you run R v2.15.2, to 21600-21609 if you run R v2.16.0 (“devel”) and so on, do:

local(
port <- sum(c(1e4,100)*as.double(R.version[c("major", "minor")]));
options(help.ports=port+0:9);
})

With this it will be easy from the URL to identify for which version of R the displayed help is for. Finally, if you wish the R help server to start automatically in the background when you start R, add:

# Try to start HTML help server
if (interactive()) {
try(tools::startDynamicHelp());
}

To leave a comment for the author, please follow the link and comment on their blog: jottR.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)