From murdoch.duncan at gmail.com  Fri Dec  5 18:51:22 2014
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Fri, 05 Dec 2014 12:51:22 -0500
Subject: [Rd] Use of tools:::httpdPort in a package for CRAN.
In-Reply-To: <CAHuTOvrtpTYO47ZADBy6KEdGX9xH3dGy=-FXTZ6J75ozF5N24A@mail.gmail.com>
References: <CAHuTOvrtpTYO47ZADBy6KEdGX9xH3dGy=-FXTZ6J75ozF5N24A@mail.gmail.com>
Message-ID: <5481F09A.9080800@gmail.com>

On 05/12/2014 11:24 AM, Sven E. Templer wrote:
> 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

I don't see any way to get it other than this, but it seems like a 
reasonable thing to want to do.  I think the way I'd do it is to modify 
the exported function startDynamicHelp() so that it doesn't give an 
error if the help system is already running, it just returns the active 
port number.

So the code above would become

hport <- startDynamicHelp()

(or some variation using try().)

I think a change like this could make it into 3.1.3 and later versions.

Duncan Murdoch

>
> 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.
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Use of tools:::httpdPort in a package for CRAN.
Duncan Murdoch