Add ability to show the current session ID

Open
#237 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
api

Research direction

Start by reviewing the existing rstudioapi entry points around terminalExecute and the RSTUDIO_SESSION_ID environment variable. Done means an R or RStudio caller can retrieve the current session ID directly, matching the value available from the Terminal.

Written by the indexing model from the issue text.

Description

enhancement

It might prove useful to get the current session ID within RStudio, for use in the Console, R scripts, R Markdown, etc. Specifically, I have a case in which it's useful for conducting some testing. The value would be the same as the environment variable RSTUDIO_SESSION_ID that is available when opening the Terminal.

Meanwhile, I can sort of fake it with the Terminal:

temp <- rstudioapi::terminalExecute("echo -n $RSTUDIO_SESSION_ID > ~/current_session_id", show = FALSE)
session_id <- readr::read_file(file = "~/current_session_id")
session_id

results in

> temp <- rstudioapi::terminalExecute("echo -n $RSTUDIO_SESSION_ID > ~/current_session_id", show = FALSE)
> session_id <- readr::read_file(file = "~/current_session_id") 
> session_id 
[1] "d963e8cd"
>

Similarly with

term <- rstudioapi::terminalExecute("echo $RSTUDIO_SESSION_ID", show = FALSE)
while (is.null(rstudioapi::terminalExitCode(term))) { Sys.sleep(0.01) }
session_id <- rstudioapi::terminalBuffer(term)
Dominant language
R
Stars
175
Forks
37
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rstudio/rstudioapi

All issues in rstudio/rstudioapi

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.