Skip to content

Commit 0caa4b4

Browse files
author
hornik
committed
Use HTML by default if interactive, and allow fragements for R manuals.
git-svn-id: https://svn.r-project.org/R/trunk@88481 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 5f552c9 commit 0caa4b4

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/library/utils/R/RShowDoc.R

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ RShowDoc <- function(what, type = c("pdf", "html", "txt"), package)
3737
else browseURL(paste0("file://", URLencode(path)))
3838
}
3939

40-
type <- match.arg(type)
40+
type <- if(interactive()) {
41+
if(missing(type))
42+
"html"
43+
else
44+
match.arg(type, c("html", "pdf", "txt"))
45+
} else
46+
match.arg(type)
4147
if(missing(what) || length(what) != 1L || !is.character(what)) {
4248
message(" RShowDoc() should be used with a character string argument specifying\n a documentation file")
4349
return(invisible())
@@ -115,20 +121,21 @@ RShowDoc <- function(what, type = c("pdf", "html", "txt"), package)
115121
path <- file.path(R.home("share"), "licenses", what)
116122
file.show(path)
117123
return(invisible(path))
118-
} else if(what %in% c("R-admin", "R-data", "R-exts", "R-FAQ", "R-intro",
119-
"R-ints", "R-lang")) {
124+
} else if((what0 <- sub("#.*", "", what)) %in%
125+
c("R-admin", "R-data", "R-exts", "R-FAQ", "R-intro",
126+
"R-ints", "R-lang")) {
120127
if(type == "pdf") {
121-
path <- file.path(R.home("doc"), "manual", paste.(what, "pdf"))
128+
path <- file.path(R.home("doc"), "manual", paste.(what0, "pdf"))
122129
if(file.exists(path)) {
123130
pdf_viewer(path)
124131
return(invisible(path))
125132
}
126133
type <- "html"
127134
}
128135
if(type == "html") {
129-
path <- file.path(R.home("doc"), "manual", paste.(what, "html"))
136+
path <- file.path(R.home("doc"), "manual", paste.(what0, "html"))
130137
if(file.exists(path)) {
131-
html_viewer(path)
138+
html_viewer(paste0(path, "#", sub(".*#", "", what)))
132139
return(invisible(path))
133140
}
134141
}

0 commit comments

Comments
 (0)