From sven.templer at gmail.com  Fri Dec  5 17:24:02 2014
From: sven.templer at gmail.com (Sven E. Templer)
Date: Fri, 5 Dec 2014 17:24:02 +0100
Subject: [Rd] Use of tools:::httpdPort in a package for CRAN.
Message-ID: <CAHuTOvrtpTYO47ZADBy6KEdGX9xH3dGy=-FXTZ6J75ozF5N24A@mail.gmail.com>

Hello,

I wrote a function to show the help/index page of a package in a
browser (and want to include this in an update for a CRAN package). I
asked in R-help how to obtain the 00Index.html file, Duncan Murdoch
suggested to inspect (see
http://r.789695.n4.nabble.com/Obtain-00Index-html-tt4697661.html)
tools:::httpd (thank you therefore!). So I came up with:


help.index <- function (pkg, browser = NA, encodeIfNeeded = FALSE) {

pkg <- as.character(substitute(pkg))
hport <- tools:::httpdPort

if (!pkg %in% rownames(installed.packages()))
stop(paste("Package", pkg, "not found."))

if (hport == 0) {
cat("Starting dynamic help.\n")
t <- try(startDynamicHelp(), silent = TRUE)
if (class(t) == "try-error")
stop("Could not start dynamic help.")
hport <- tools:::httpdPort
}

if (!is.na(browser)) {
if (tolower(browser) == "rstudio")
options(browser = function (x) .Call("rs_browseURL", url))
else
options(browser = browser)
}

url <- paste0("http://127.0.0.1:", hport, "/library/", pkg,
"/html/00Index.html")
browseURL(url, encodeIfNeeded = encodeIfNeeded)
invisible(NULL)

}

(also at https://github.com/setempler/miscset/blob/master/R/help.index.R)

I tried to avoid `:::` so I used the 00Index.html file from the
library on my disk (like
/home/user.foo/R/lib.bar/package.baz/html/00Index.html). It does show
the index, but the link to the help pages are not accessible.
Nevertheless, my implementation now works, but R CMD check --as-cran
gives a warning, and the R help also says to avoid `:::`. Also
get(httpd, as.environment("package:tools")) didn't help.

My question: do I have another possibility to achieve my goal without
referencing by `:::` (concerning a submission to CRAN), if so, please
tell me!

Thank you in advance,
Sven.



[Rd] Use of tools:::httpdPort in a package for CRAN.
Sven E. Templer