Available RStudio Hooks

What RStudio hooks are available? I've found

setHook("rstudio.sessionInit", function(newSession) {

But this doesn't get executed when I restart R, only when starting a project.

You can control some aspects of your RStudio session using:

1 Like

Thanks @andrie

The problem I'm trying to solve is I want to run some rstudioapi functions in the Rprofile. For example,


However, since RStudio hasn't started, just adding this to the Rprofile doesn't work (hence the hook). But the hook doesn't seem to be called on restarting R.

I managed to get this to work:

setHook("rstudio.sessionInit", function(newSession) {
  if (newSession) {
    message("Welcome to RStudio ", rstudioapi::getVersion())
  ap <- rstudioapi::getActiveProject()
  if (is.null(ap)) ap <- "No active project"
  message("Active RStudio project: ", ap)
}, action = "append"

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.