From henrik.bengtsson at gmail.com  Wed Aug 30 01:19:04 2017
From: henrik.bengtsson at gmail.com (Henrik Bengtsson)
Date: Tue, 29 Aug 2017 16:19:04 -0700
Subject: [Rd] BUG: HMTL-based help.search() on vignettes may generate error
	(with PATCH)
Message-ID: <CAFDcVCQgEvHhGFsRSt+tmg_kaW3F1=B_y-20KcsNW-DJGjx4Rw@mail.gmail.com>

REPRODUCIBLE EXAMPLE:

With the R.rsp package installed, the following search, which gives a hit:

    options(help_type = "html")
    help.search("rsp")

generates:

    Error in if (nchar(Outfile)) Outfile else File :
      argument is not interpretable as logical

in the browser (e.g. http://127.0.0.1:30410/doc/html/Search?results=1).

Another example is help.search("tm") with jsonlite installed.


TROUBLESHOOTING:

This occurs because utils:::merge_vignette_index() uses:

    base[, "Name"] <- sub("\\.[^.]*$", "", basename(vDB$File))
    base[, "Topic"] <- base[, "Name"]

which assumes that the 'Name' (and hence the 'Topic') can be inferred
from the basename of the vignette source file by dropping the filename
extension.  This assumption was valid in R (< 3.0.0), but with the
introduction of generic vignette engines, we may now have multiple
("nested") file-name extensions on vignette source files.  For
instance, vignette source file 'vignette.tex.rsp' outputs
'vignette.pdf'.  Another example is 'vignette.pdf.asis' that outputs
'vignette.pdf'.

Now, the assumption on a single file-name extension is still valid on
the vignette output product file, where we can only have file name
extensions *.pdf and *.html.  Because of this, a solution is to use
'basename(vDB$PDF)' instead of 'basename(vDB$File)'.  This is also
what tools:::httpd() uses internally and the difference between the
two approach is what causes the error in help.search() above.


PATCH:

A patch (against R-devel) is:

svn diff src/library/utils/R/help.search.R
Index: src/library/utils/R/help.search.R
===================================================================
--- src/library/utils/R/help.search.R (revision 73159)
+++ src/library/utils/R/help.search.R (working copy)
@@ -43,7 +43,7 @@
  base[, "LibPath"] <- path
  id <- as.character(1:nrow(vDB) + NROW(hDB[[1L]]))
  base[, "ID"] <- id
- base[, "Name"] <- sub("\\.[^.]*$", "", basename(vDB$File))
+ base[, "Name"] <- tools::file_path_sans_ext(basename(vDB$PDF))
  base[, "Topic"] <- base[, "Name"]
  base[, "Title"] <- vDB$Title
  base[, "Type"] <- "vignette"

I have verified that the above patch solves the problem.  I thought it
is ok to use tools::file_path_sans_ext() since other functions in
'utils' already do so.

I'm happy to submit this one via https://bugs.r-project.org/bugzilla3/ as well.


APPENDIX:

> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.3 LTS

Matrix products: default
BLAS: /usr/lib/atlas-base/atlas/libblas.so.3.0
LAPACK: /usr/lib/atlas-base/atlas/liblapack.so.3.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.4.1

/Henrik



[Rd] BUG: HMTL-based help.search() on vignettes may generate error (with PATCH)
Henrik Bengtsson