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.
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:
The rstudioapi
package, and the code you mention can be found in the vignette https://rstudio.github.io/rstudioapi/articles/r-session.html
The RStudio Server Pro Tutorial API
Also take a look at https://rstudio.github.io/rstudio-extensions/index.html
Thanks @andrie
The problem I'm trying to solve is I want to run some rstudioapi
functions in the Rprofile. For example,
rstudioapi::getActiveProject()
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.