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  

Forgotten features of R 4.0.0

Author: Colin Gillespie

Published: January 25, 2022

tags: r, python

R version 4.0.0 was released almost two years ago. The change in the major version, 3.x.y to 4.0.0, represented significant and potentially breaking changes. For an organisation to start using these new features, everyone in the company must have access to that version; otherwise code isn’t shareable. This naturally slows down adoption.

We moved our internal R projects to depend on version R 4.0.0 around twelve months ago - a few months after the release date. Over the last year we’ve also assisted a number of clients in making the move; typically with Shiny applications. This post aims to highlight some of the features we’ve found useful and also some of the potential pitfalls.

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

StringsAsFactors

From the beginning, R converted imported strings to factors. For most users, this typically occurred when reading in data using read.csv(). This default made sense for statistical modelling, but was a little tricky for new users. Especially as today’s data sets tend to have messy string data.

In R 4.0.0, this default changed, with stringsAsFactors now being FALSE by default. For our internal applications, this didn’t really cause issues, but we’ve had to help a number of clients “upgrade” their Shiny app to run using R version 4.0.0. If you are planning on making this move, here’s our standard “gotcha” check-list:

  • Are there any calls to read.csv(), read.table() or read.delim()? If so, this could cause issues. You can either set stringsAsFactors = TRUE in these functions, or fix any issues that crop up.
  • Are there any data frames saved as rds files? If so, check the columns for factors.
  • Do you use data.frame() to create data frames? If so, factors might creep in.
  • Do packages return data frames that you use? This is the trickiest bug to track down.

Raw Character Strings

Using the syntax r"(some characters)" we can now define literal strings. This avoids the painful adding of backslashes when escaping special characters. We’ve recently started using this regularly when generating PDF documents that have LaTeX in them. For example,

r"(Avoiding \texttt{backslash} and "speech mark" hell.)"
#> [1] "Avoiding \\texttt{backslash} and \"speech mark\" hell."

Other uses are regular expressions and HTML code.

Caching with R_user_dir()

Buried deep within the changelog was a reference to R_user_dir() from the {tools} package. This function provides a nice, cross-platform method for creating directories that can be used to store R-related user-specific data, configuration and cache files.

For example,

tools::R_user_dir("my_pkg", which = "cache")
#> [1] "/home/ncsg3/.cache/R/my_pkg"

provides a string that can be used to create a directory. In the {oysteR} package, I use this idea to cache API results. As R generates the path, I don’t have to worry about which OS the user is on.

Also of note

I’ve not used the new reference counting directly, but by switching to R 4.0.0 I’ve certainly benefited from a slightly faster, less resource-hungry version of R. Likewise, the {grid} package was improved, so {ggplot2} is also a little quicker. This is one of the benefits of upgrading R versions; things just get a bit nicer.

References

  • R Changelog
  • A nice overview of R 4.0.0 by David Smith.

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

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

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