1
1
#
2
2
# viewer.R
3
3
#
4
- # Copyright (C) 2023-2024 Posit Software, PBC. All rights reserved.
4
+ # Copyright (C) 2023-2025 Posit Software, PBC. All rights reserved.
5
5
#
6
6
#
7
7
8
8
options(" viewer" = function (url , height = NULL , ... ) {
9
9
# Validate the URL argument.
10
- if (! is.character(url ) || (length(url ) != 1 ))
11
- stop(" url must be a single element character vector." )
12
-
13
- # Normalize paths for comparison. This is necessary because on e.g. macOS,
14
- # the `tempdir()` may contain `//` or other non-standard path separators.
15
- normalizedPath <- normalizePath(url , mustWork = FALSE )
16
- normalizedTempdir <- normalizePath(tempdir(), mustWork = FALSE )
10
+ if (! is_string(url )) {
11
+ stop(" `url` must be a string." )
12
+ }
17
13
18
14
# Validate the height argument.
19
15
height <- .ps.validate.viewer.height(height )
20
16
17
+ # Open `http(s)://` urls in the browser immediately, avoid normalizing their
18
+ # paths since they aren't files (posit-dev/positron#4843)
19
+ if (is_http_url(url )) {
20
+ return (utils :: browseURL(url , ... ))
21
+ }
22
+
23
+ # Normalize file paths for comparison against the `tempdir()`. This is
24
+ # necessary because on e.g. macOS, the `tempdir()` may contain `//` or other
25
+ # non-standard path separators.
26
+ normalizedPath <- normalizePath(url , mustWork = FALSE )
27
+ normalizedTempdir <- normalizePath(tempdir(), mustWork = FALSE )
28
+
21
29
# Is the URL a temporary file?
22
30
if (startsWith(normalizedPath , normalizedTempdir )) {
23
31
# Derive a title for the viewer from the path.
@@ -26,7 +34,7 @@ options("viewer" = function(url, height = NULL, ...) {
26
34
# If so, open it in the HTML viewer.
27
35
.ps.Call(" ps_html_viewer" , normalizedPath , title , height , FALSE )
28
36
} else {
29
- # If not, open it in the system browser.
37
+ # If not, fall back to opening it in the system browser.
30
38
utils :: browseURL(normalizedPath , ... )
31
39
}
32
40
})
0 commit comments