1
|
|
###########################################################################/**
|
2
|
|
# @RdocDefault browseRsp
|
3
|
|
# @alias browseRsp.Package
|
4
|
|
#
|
5
|
|
# @title "Starts the internal web browser and opens the URL in the default web browser"
|
6
|
|
#
|
7
|
|
# \description{
|
8
|
|
# @get "title".
|
9
|
|
# From this page you access not only help pages and demos on how to use
|
10
|
|
# RSP, but also other package RSP pages.
|
11
|
|
# }
|
12
|
|
#
|
13
|
|
# @synopsis
|
14
|
|
#
|
15
|
|
# \arguments{
|
16
|
|
# \item{url}{A @character string for the URL to be viewed.
|
17
|
|
# By default the URL is constructed from the \code{urlRoot} and
|
18
|
|
# the \code{path} parameters.
|
19
|
|
# }
|
20
|
|
# \item{urlRoot}{A @character string specifying the URL root. By default
|
21
|
|
# the URL is constructed from the \code{host} and the \code{port}.}
|
22
|
|
# \item{host}{An optional @character string for the host of the URL.}
|
23
|
|
# \item{port}{An optional @integer for the port of the URL.}
|
24
|
|
# \item{path}{An optional @character string for the context path of the URL.}
|
25
|
|
# \item{start}{If @TRUE, the internal \R web server is started if not
|
26
|
|
# already started, otherwise not.}
|
27
|
|
# \item{stop}{If @TRUE, the internal \R web server is stopped, if started.}
|
28
|
|
# \item{...}{Additional arguments passed to @see "utils::browseURL".}
|
29
|
|
# }
|
30
|
|
#
|
31
|
|
# \value{
|
32
|
|
# Returns (invisibly) the URL.
|
33
|
|
# }
|
34
|
|
#
|
35
|
|
# @author
|
36
|
|
#
|
37
|
|
# \seealso{
|
38
|
|
# Internally, @see "utils::browseURL" is used to launch the browser.
|
39
|
|
# }
|
40
|
|
#
|
41
|
|
# @keyword file
|
42
|
|
# @keyword IO
|
43
|
|
# @keyword internal
|
44
|
|
#*/###########################################################################
|
45
|
|
setMethodS3("browseRsp", "default", function(url=paste(urlRoot, path, sep="/"), urlRoot=sprintf("http://%s:%d", host, port), host="127.0.0.1", port=8074L, path="", start=TRUE, stop=FALSE, ...) {
|
46
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
47
|
|
# Validate arguments
|
48
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
49
|
|
# Argument 'url':
|
50
|
0
|
if (!is.null(url)) {
|
51
|
0
|
if (!isUrl(url) && isUrl(urlRoot) && nchar(path) == 0L) {
|
52
|
0
|
path <- getRelativePath(url)
|
53
|
0
|
if (isAbsolutePath(path)) {
|
54
|
0
|
throw("Cannot open file, because it is not possible to infer its relative pathname: ", url)
|
55
|
|
}
|
56
|
0
|
url <- paste(urlRoot, path, sep="/")
|
57
|
|
}
|
58
|
|
}
|
59
|
|
|
60
|
|
# Argument 'port':
|
61
|
0
|
port <- Arguments$getInteger(port, range=c(0L,65535L))
|
62
|
|
|
63
|
|
# Argument 'stop':
|
64
|
0
|
stop <- Arguments$getLogical(stop)
|
65
|
|
|
66
|
|
|
67
|
|
# Get the/a HTTP daemon
|
68
|
0
|
httpDaemon <- getStaticInstance(HttpDaemon)
|
69
|
|
|
70
|
|
# Stop HTTP server?
|
71
|
0
|
if (stop) {
|
72
|
0
|
if (isStarted(httpDaemon))
|
73
|
0
|
stop(httpDaemon)
|
74
|
0
|
return(!isStarted(httpDaemon))
|
75
|
|
}
|
76
|
|
|
77
|
|
# Start HTTP server?
|
78
|
0
|
if (start) {
|
79
|
|
# Add the following directories to the list of known root paths:
|
80
|
|
# (1) current directory
|
81
|
0
|
paths <- getwd()
|
82
|
|
# (2) rsp/ under current directory
|
83
|
0
|
paths <- c(paths, file.path(getwd(), "rsp"))
|
84
|
|
# (3) the parent of all library paths
|
85
|
0
|
paths <- c(paths, dirname(.libPaths()))
|
86
|
|
# (4) /library/R.rsp/rsp/ as a root path too.
|
87
|
0
|
paths <- c(paths, system.file("rsp", package="R.rsp"))
|
88
|
0
|
appendRootPaths(httpDaemon, paths)
|
89
|
|
|
90
|
0
|
if (!isStarted(httpDaemon)) {
|
91
|
|
# Start the web server
|
92
|
0
|
start(httpDaemon, port=port, default="^index[.](html|.*)$")
|
93
|
|
}
|
94
|
|
}
|
95
|
|
|
96
|
0
|
if (!is.null(url)) {
|
97
|
0
|
browseURL(url, ...)
|
98
|
|
}
|
99
|
|
|
100
|
0
|
invisible(url)
|
101
|
|
})
|
102
|
|
|
103
|
|
|
104
|
|
setMethodS3("browseRsp", "Package", function(this, ..., path=sprintf("library/%s/rsp/", getName(this))) {
|
105
|
0
|
browseRsp(..., path=path)
|
106
|
|
})
|