Perform functions immediately upon opening R

I was wondering how can I execute some predefined functions when opening R or R-studio?

I know this sounds silly, but I installed the package praiseand I want to try to run it praise()automatically every time I open R or R studio, without entering text praise().

+4
source share
1 answer

To do this, you can use .First()and .Last()in .Rprofile.

This is a typical R file that was launched at startup and is primarily used to export some default files.

An example .Rprofile:

# .First() run at the start of every R session. 
# Use to load commonly used packages? 
.First <- function() {
    library(ggplot2)
    cat("\nSuccessfully loaded .Rprofile at", date(), "\n")
}

# .Last() run at the end of the session
.Last <- function() {
    cat("\nGoodbye at ", date(), "\n")
}

Related: Expert R users, what's in your .Rprofile?

+4
source

Source: https://habr.com/ru/post/1608886/


All Articles