Modify RStudio prompt to show current git branch

[This article was first published on Rtask, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

You can read the original post in its original format on Rtask website by ThinkR here: Modify RStudio prompt to show current git branch

At the last Raddicts Paris Meetup, Romain Francois (to be followed on twitter here) made one strong impression, among others, with his RStudio console which indicates the active git branch and the RAM memory used by R.

If you too want to have this (to shine in society or because you spend your time doing git checkout):

git info shown in R console prompt in RStudio

 

Here is the way to go:

This code to show the active git branch and R memory used needs to be hosted in your ".Rprofile"

  • You first need to install package {prompt} from Gabor Csardi. This package is not on CRAN, you will need to install it from GitHub using:
    remotes::install_github("gaborcsardi/prompt")
  • Dependencies may not be directly installed and you will need to additionally install package {memuse}:
    install.packages("memuse")
  • Then, open your ".Rprofile", using {usethis} usethis::edit_r_profile()
  • The content of your ".Rprofile" is executed as soon as you start R. Add the following code in this file:
prompt::set_prompt(function(...){
paste0(
"[", prompt::git_branch(), prompt::git_dirty(), prompt::git_arrows(), "] ",
prompt::prompt_memuse()
)
})

Tada !

Thanks Romain !!

This post is better presented on its original ThinkR website here: Modify RStudio prompt to show current git branch

To leave a comment for the author, please follow the link and comment on their blog: Rtask.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)