From xie at yihui.name  Fri Dec  5 19:03:15 2014
From: xie at yihui.name (Yihui Xie)
Date: Fri, 5 Dec 2014 12:03:15 -0600
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: <CANROs4cSA00TS3C++Di78r=3dqHgW3y3wxLA-nC_Zn9S6quksw@mail.gmail.com>

Perhaps I missed something, but isn't this just a one-liner function?

help.index = function (pkg) help(package = (pkg), help_type = "html")

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Web: http://yihui.name


On Fri, Dec 5, 2014 at 10:24 AM, Sven E. Templer <sven.templer at gmail.com> 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
>
> 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.
Yihui Xie