Skip to main content
AI in Production 2026 is now open for talk proposals.
Share insights that help teams build, scale, and maintain stronger AI systems.
items
Menu
  • About
    • Overview 
    • Join Us  
    • Community 
    • Contact 
  • Training
    • Overview 
    • Course Catalogue 
    • Public Courses 
  • Posit
    • Overview 
    • License Resale 
    • Managed Services 
    • Health Check 
  • Data Science
    • Overview 
    • Visualisation & Dashboards 
    • Open-source Data Science 
    • Data Science as a Service 
    • Gallery 
  • Engineering
    • Overview 
    • Cloud Solutions 
    • Enterprise Applications 
  • Our Work
    • Blog 
    • Case Studies 
    • R Package Validation 
    • diffify  

Customising your Rprofile

Author: Colin Gillespie

Published: January 17, 2020

tags: r, packages, rstudio, rprofile

What is an Rprofile

Every time R starts, it runs through a couple of R scripts. One of these scripts is the .Rprofile. This allows users to customise their particular set-up. However, some care has to be taken, as if this script is broken, this can cause R to break. If this happens, just delete the script!

Full details of how the .Rprofile works can be found in my book with Robin on Efficient R programming. However, roughly R will look for a file called .Rprofile first in your current working directory, then in your home area. Crucially, it will only load the first file found. This means you can have per project Rprofile.

Do you use Professional Posit Products? If so, check out our managed Posit services

My Rprofile

A few months ago, I noticed my Rprofile was becoming increasing untidy, so I bundled it up into a single, opinionated, package. This also made it easier for me to switch between computers. Last week, there was an interesting twitter thread on customising your .Rprofile started by Kara Woo. The thread became popular with lots of great suggestions on neat customisations. This also provided the impetus to write this post.

Installation

You can install the package from GitHub with:

# install.packages("remotes")
remotes::install_github("csgillespie/rprofile")

The package also uses two non-cran packages

# Used for nice prompts
remotes::install_github("gaborcsardi/prompt")
# Used for nice colours in the terminal; not for Windows
remotes::install_github("jalvesaq/colorout")

R Prompt

You can make simple customisations to your R prompt using options(), but for extra bling I use the the {prompt} package.

  • If you are in a Git repo, the branch will be displayed.
  • If R’s memory becomes large, the size will also be displayed.

As the RStudio console already has alot of nice features, e.g. syntax highlighting, a distinction needs to be made between the RStudio Console and running R in the terminal. So in .Rprofile I’ve got some logic to detect where I’m running R (in my .Rprofile) and adjust accordingly.

Useful Start-up Messages

If you use R a lot, you want to minimise noise. I used to have the {fortunes} package display a fortune in my profile, but this got repetitive. Then I tried grabbing stuff from twitter, but this slowed everything down when the wifi was poor.

Currently three start-up messages are displayed:

  • The wifi network you are connected too with speed info (Linux only)
  • The number of open R sessions (Linux only)
  • RStudio project info
  • I also clear all the standard R licence stuff from the screen.

If anyone wants to expand the Linux only functions to Windows and Macs, please submit a pull request!

Helper Functions

It’s always dangerous to load functions in your start-up script, so I’ve only included functions I’m fairly sure won’t be used in a script.

  • create_make_functions() - if you have a Makefile in your working directory, this will automatically generate all associated make functions. For example, if you have a force argument in the Makefile this will generate make_force(). This is actually run at startup.
  • lsos() - a handy function for listing large objects.
  • library() - Over writes the library() function with a smarter version. If a package is missing, automatically provides the option to install from CRAN or GitHub.
  • last_error() and last_trace() - pre-loads from {rlang}. Nicer error investigation.

RStudio Functions

  • op(path = ".") - Creates & opens an RStudio project in the directory specified.
  • cp() - Lists previous RStudio projects and gives an option to open.
  • inf_mr() - Short cut to xaringan::inf_mr().

Setting Better options()

The set_startup_options() function sets better (in my opinion) set of start-up options. These include

  • Setting Ncpus to run parallel installs by default
  • Removing significant stars
  • Set mc.cores to a sensible default
  • Change the continue = "+" to a blank space
  • Reduce the default print length
  • Plus a few others (see ?set_startup_options)

I’ve also created a convenience function for adding additional R repositories - set_repos(). Probably not needed by most people.

Example .Rprofile

Open your .Rprofile, e.g. file.edit("~/.Rprofile") and customise however you want. Here’s an example

if (interactive() && requireNamespace("rprofile", quietly = TRUE)) {

  # Only useful if you use Makefiles
  rprofile::create_make_functions()

  # Startup options
  rprofile::set_startup_options()

  # Not RStudio console
  if (rprofile::is_terminal()) {
    rprofile::set_terminal()
  } else {
    rprofile::set_rstudio()
  }

  .env = rprofile::set_functions()
  attach(.env)
  # Display wifi and no of R sessions
  # Linux only
  rprofile::set_startup_info()
}

# Prints RStudio project on start-up
setHook("rstudio.sessionInit", function(newSession) {
  active_rproj = rprofile::get_active_rproj()
  if (!is.null(active_rproj)) {
    message(glue::glue("{crayon::yellow('R-project:')} {active_rproj}"))
  }
}, action = "append")

Notes and thanks

  • The lsos() function was taken from the SO question.
  • The improved version of library() was adapted from the autoinst. I did think about importing the package, but I had made too many personal tweaks.
  • Setting the prompt uses the excellent prompt package.
  • I’ve probably “borrowed” some of the other ideas from blogposts and SO questions. If I’ve missed crediting you, please let me know and I’ll rectify it.
  • If you have any suggestions or find bugs, please use the GitHub issue tracker
  • Feel free to submit pull requests

Jumping Rivers Logo

Recent Posts

  • Start 2026 Ahead of the Curve: Boost Your Career with Jumping Rivers Training 
  • Should I Use Figma Design for Dashboard Prototyping? 
  • Announcing AI in Production 2026: A New Conference for AI and ML Practitioners 
  • Elevate Your Skills and Boost Your Career – Free Jumping Rivers Webinar on 20th November! 
  • Get Involved in the Data Science Community at our Free Meetups 
  • Polars and Pandas - Working with the Data-Frame 
  • Highlights from Shiny in Production (2025) 
  • Elevate Your Data Skills with Jumping Rivers Training 
  • Creating a Python Package with Poetry for Beginners Part2 
  • What's new for Python in 2025? 

Top Tags

  • R (236) 
  • Rbloggers (182) 
  • Pybloggers (89) 
  • Python (89) 
  • Shiny (63) 
  • Events (26) 
  • Training (23) 
  • Machine Learning (22) 
  • Conferences (20) 
  • Tidyverse (17) 
  • Statistics (14) 
  • Packages (13) 

Authors

  • Colin Gillespie 
  • Amieroh Abrahams 
  • Aida Gjoka 
  • Gigi Kenneth 
  • Osheen MacOscar 
  • Sebastian Mellor 
  • Keith Newman 
  • Pedro Silva 
  • Shane Halloran 
  • Russ Hyde 
  • Myles Mitchell 
  • Tim Brock 
  • Theo Roe 

Keep Updated

Like data science? R? Python? Stan? Then you’ll love the Jumping Rivers newsletter. The perks of being part of the Jumping Rivers family are:

  • Be the first to know about our latest courses and conferences.
  • Get discounts on the latest courses.
  • Read news on the latest techniques with the Jumping Rivers blog.

We keep your data secure and will never share your details. By subscribing, you agree to our privacy policy.

Follow Us

  • GitHub
  • Bluesky
  • LinkedIn
  • YouTube
  • Eventbrite

Find Us

The Catalyst Newcastle Helix Newcastle, NE4 5TG
Get directions

Contact Us

  • hello@jumpingrivers.com
  • + 44(0) 191 432 4340

Newsletter

Sign up

Events

  • North East Data Scientists Meetup
  • Leeds Data Science Meetup
  • Shiny in Production
British Assessment Bureau, UKAS Certified logo for ISO 9001 - Quality management British Assessment Bureau, UKAS Certified logo for ISO 27001 - Information security management Cyber Essentials Certified Plus badge
  • Privacy Notice
  • |
  • Booking Terms

©2016 - present. Jumping Rivers Ltd