Skip to content

Commit a7abdcf

Browse files
author
Tal Hadad
committed
expose detach function to R API
1 parent 0d3f446 commit a7abdcf

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

R/session/init_late.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ source(file.path(dir_init, "vsc.R"), local = .vsc)
1717
exports <- local({
1818
.vsc <- .vsc
1919
.vsc.attach <- .vsc$attach
20+
.vsc.detach <- .vsc$detach
2021
.vsc.view <- .vsc$show_dataview
2122
.vsc.browser <- .vsc$show_browser
2223
.vsc.viewer <- .vsc$show_viewer

R/session/vsc.R

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,7 @@ attach <- function(host = "127.0.0.1", port = NA) {
655655
rstudioapi_util_env$update_addin_registry(addin_registry)
656656
}
657657
if (!is.na(request_tcp_connection)) {
658-
close(request_tcp_connection)
659-
request_tcp_connection <<- NA
658+
detach()
660659
}
661660
if (!is.na(port)) {
662661
request_tcp_connection <<- socketConnection(
@@ -685,6 +684,14 @@ attach <- function(host = "127.0.0.1", port = NA) {
685684
)
686685
}
687686

687+
detach <- function() {
688+
request("detach")
689+
if (!is.na(request_tcp_connection)) {
690+
close(request_tcp_connection)
691+
request_tcp_connection <<- NA
692+
}
693+
}
694+
688695
path_to_uri <- function(path) {
689696
if (length(path) == 0) {
690697
return(character())
@@ -965,9 +972,6 @@ reg.finalizer(.GlobalEnv, function(e) {
965972
# TODO: When exiting radian by EOF("CTRL+D") when coonecting to vsc by TCP,
966973
# the TCP connection is getting closed before we're able to call detach...
967974
tryCatch({
968-
.vsc$request("detach")
969-
if (!is.na(request_tcp_connection)) {
970-
close(request_tcp_connection)
971-
}
975+
detach()
972976
}, error = function(e) NULL)
973977
}, onexit = TRUE)

0 commit comments

Comments
 (0)