Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ark: Support a session init hook #3371

Open
jennybc opened this issue Jun 3, 2024 · 1 comment
Open

ark: Support a session init hook #3371

jennybc opened this issue Jun 3, 2024 · 1 comment
Labels
area: kernels Issues related to Jupyter kernels and LSP servers lang: r

Comments

@jennybc
Copy link
Member

jennybc commented Jun 3, 2024

Follow-up work related to #2070 and renv support.

RStudio supports a session init hook that runs after R is fully initialized:

https://github.com/rstudio/rstudio/blob/8ebe5431ca2fb3c9719b70d4fbc45201d226c79c/src/cpp/session/modules/SessionRHooks.hpp#L19

https://github.com/rstudio/rstudio/blob/8ebe5431ca2fb3c9719b70d4fbc45201d226c79c/src/cpp/session/SessionMain.cpp#L857

https://github.com/rstudio/rstudio/blob/8ebe5431ca2fb3c9719b70d4fbc45201d226c79c/src/cpp/session/modules/SessionRHooks.hpp#L36-L39

https://github.com/rstudio/rstudio/blob/8ebe5431ca2fb3c9719b70d4fbc45201d226c79c/src/cpp/session/modules/SessionRHooks.R#L16-L31


Good resource on R startup: https://rstats.wtf/r-startup


People typically use this sort of hook to schedule startup-ish code that makes use of, for example, readline(), menu() or rstudioapi. Our immediate use case here in Positron is related to renv, where it would be nice to schedule the "hey you need to do renv::restore(); shall we do it? interaction for execution after R has been fully stood up.


GitHub search for uses of rstudio.sessionInit:

https://github.com/search?q=rstudio.sessionInit&type=code

@jennybc jennybc added lang: r area: kernels Issues related to Jupyter kernels and LSP servers labels Jun 3, 2024
@jennybc
Copy link
Member Author

jennybc commented Jun 7, 2024

Notes for when we work on this: I think it would be interesting to make it possible for a frontend to advertise the name of its session init hook. In the current world, the most obvious place for such functionality to live is rstudioapi and then RStudio and Positron could both implement the associated function. That will reduce the need for packages to have code specific to RStudio vs. Positron.

This note is motivated by laying the groundwork in renv for playing more nicely in Positron. In the near term, we're going to be happy to prevent R's failure to launch (which is posit-dev/ark#383) and to recommend a version of renv that emits a message telling the user to run renv::restore() (which is rstudio/renv#1915). But we'd really like to have the same behaviour as RStudio, which is to defer interactive startup activities to a session init hook.

Update: Hmmm, upon further thought, one of the main reasons for RStudio's session init hook is because you can't call rstudioapi during startup. But I suspect that only applies to certain functions, i.e. to the ones that genuinely interact with RStudio. A simple function that just returns a string (the name of the session init hook) might be fine.

@petetronic petetronic modified the milestones: Future, Release Candidate Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: kernels Issues related to Jupyter kernels and LSP servers lang: r
Projects
None yet
Development

No branches or pull requests

2 participants