1-
21rstudio <- local({
3-
42standalone_env <- environment()
53 parent.env(standalone_env )<- baseenv()
64
@@ -18,7 +16,8 @@ rstudio <- local({
1816" RSTUDIO_CONSOLE_COLOR" ,
1917" RSTUDIOAPI_IPC_REQUESTS_FILE" ,
2018" XPC_SERVICE_NAME" ,
21- " ASCIICAST" )
19+ " ASCIICAST"
20+ )
2221
2322d <- list (
2423pid = Sys.getpid(),
@@ -55,8 +54,10 @@ rstudio <- local({
5554if (clear_cache )data <<- NULL
5655if (! is.null(data ))return (get_caps(data ))
5756
58- if ((rspid <- Sys.getenv(" RSTUDIO_SESSION_PID" ))!= " " &&
59- any(c(" ps" ," cli" )%in% loadedNamespaces())) {
57+ if (
58+ (rspid <- Sys.getenv(" RSTUDIO_SESSION_PID" ))!= " " &&
59+ any(c(" ps" ," cli" )%in% loadedNamespaces())
60+ ) {
6061 detect_new(rspid ,clear_cache )
6162 }else {
6263 detect_old(clear_cache )
@@ -89,31 +90,26 @@ rstudio <- local({
8990
9091# direct subprocess
9192new $ type <- if (rspid == parentpid ) {
92-
9393if (pane == " job" ) {
9494" rstudio_job"
95-
9695 }else if (pane == " build" ) {
9796" rstudio_build_pane"
98-
9997 }else if (pane == " render" ) {
10098" rstudio_render_pane"
101-
102- } else if ( pane == " terminal" && new $ tty &&
103- new $ envs [ " ASCIICAST " ] != " true " ) {
99+ } else if (
100+ pane == " terminal" && new $ tty && new $ envs [ " ASCIICAST " ] != " true "
101+ ) {
104102# not possible, because there is a shell in between, just in case
105103" rstudio_terminal"
106-
107104 }else {
108105# don't know what kind of direct subprocess
109106" rstudio_subprocess"
110107 }
111-
112- } else if ( pane == " terminal" && new $ tty &&
113- new $ envs [[ " ASCIICAST " ]] != " true " ) {
108+ } else if (
109+ pane == " terminal" && new $ tty && new $ envs [[ " ASCIICAST " ]] != " true "
110+ ) {
114111# not a direct subproces, so check other criteria as well
115112" rstudio_terminal"
116-
117113 }else {
118114# don't know what kind of subprocess
119115" rstudio_subprocess"
@@ -123,58 +119,55 @@ rstudio <- local({
123119 }
124120
125121detect_old <- function (clear_cache = FALSE ) {
126-
127122# Cache unless told otherwise
128123cache <- TRUE
129124new <- get_data()
130125
131126new $ type <- if (new $ envs [[" RSTUDIO" ]]!= " 1" ) {
132127# 1. Not RStudio at all
133128" not_rstudio"
134-
135129 }else if (new $ gui == " RStudio" && new $ api ) {
136130# 2. RStudio console, properly initialized
137131" rstudio_console"
138-
139- }else if (! new $ api && basename(new $ args [1 ])== " RStudio" ) {
132+ }else if (! new $ api && basename(new $ args [1 ])== " RStudio" ) {
140133# 3. RStudio console, initializing
141134cache <- FALSE
142135" rstudio_console_starting"
143-
144136 }else if (new $ gui == " Rgui" ) {
145137# Still not RStudio, but Rgui that was started from RStudio
146138" not_rstudio"
147-
148139 }else if (new $ tty && new $ envs [[" ASCIICAST" ]]!= " true" ) {
149140# 4. R in the RStudio terminal
150141# This could also be a subprocess of the console or build pane
151142# with a pseudo-terminal. There isn't really a way to rule that
152143# out, without inspecting some process data with ps::ps_*().
153144# At least we rule out asciicast
154145" rstudio_terminal"
155-
156- }else if (! new $ tty &&
157- new $ envs [[" RSTUDIO_TERM" ]]== " " &&
158- new $ envs [[" R_BROWSER" ]]== " false" &&
159- new $ envs [[" R_PDFVIEWER" ]]== " false" &&
160- is_build_pane_command(new $ args )) {
146+ }else if (
147+ ! new $ tty &&
148+ new $ envs [[" RSTUDIO_TERM" ]]== " " &&
149+ new $ envs [[" R_BROWSER" ]]== " false" &&
150+ new $ envs [[" R_PDFVIEWER" ]]== " false" &&
151+ is_build_pane_command(new $ args )
152+ ) {
161153# 5. R in the RStudio build pane
162154# https://github.com/rstudio/rstudio/blob/master/src/cpp/session/
163155# modules/build/SessionBuild.cpp#L231-L240
164156" rstudio_build_pane"
165-
166- }else if (new $ envs [[" RSTUDIOAPI_IPC_REQUESTS_FILE" ]]!= " " &&
167- grepl(" rstudio" ,new $ envs [[" XPC_SERVICE_NAME" ]])) {
157+ }else if (
158+ new $ envs [[" RSTUDIOAPI_IPC_REQUESTS_FILE" ]]!= " " &&
159+ grepl(" rstudio" ,new $ envs [[" XPC_SERVICE_NAME" ]])
160+ ) {
168161# RStudio job, XPC_SERVICE_NAME=0 in the subprocess of a job
169162# process. Hopefully this is reliable.
170163" rstudio_job"
171-
172- }else if (new $ envs [[" RSTUDIOAPI_IPC_REQUESTS_FILE" ]]!= " " &&
173- any(grepl(" SourceWithProgress.R" ,new $ args ))) {
164+ }else if (
165+ new $ envs [[" RSTUDIOAPI_IPC_REQUESTS_FILE" ]]!= " " &&
166+ any(grepl(" SourceWithProgress.R" ,new $ args ))
167+ ) {
174168# Or we can check SourceWithProgress.R in the command line, see
175169# https://github.com/r-lib/cli/issues/367
176170" rstudio_job"
177-
178171 }else {
179172# Otherwise it is a subprocess of the console, terminal or
180173# build pane, and it is hard to say which, so we do not try.
@@ -297,4 +290,4 @@ rstudio <- local({
297290 )
298291})
299292
300- rstudio_detect <- function (... )rstudio $ detect(... )
293+ rstudio_detect <- function (... )rstudio $ detect(... )