Skip to content

the R session crashes at startup when R_HISTSIZE is 0 and fails to start when it is negative #19690

Closed

Description

@kevinushey

System details

RStudio Edition : Desktop and Server
RStudio Version : main (2026.12 development)
OS Version      : all (reproduced on macOS)
R Version       : all

Steps to reproduce the problem

  1. Put R_HISTSIZE=0 in ~/.Renviron (a way to keep R from saving command history), in a directory where a .Rhistory file exists.
  2. Start RStudio.

Or: set R_HISTSIZE=-1 and start RStudio.

Describe the problem in detail

With R_HISTSIZE=0 and a .Rhistory to load, the R session crashes during startup (segmentation fault). The backtrace ends in ConsoleHistory::loadFromFile() -> readCollectionFromStream() -> circular_buffer::insert(): RStudio uses R_HISTSIZE as the capacity of the session's in-memory console history, and inserting the loaded lines into a zero-capacity buffer writes through an invalid slot.

With a negative R_HISTSIZE, the session fails to start with Unexpected exception: circular_buffer, because the negative capacity becomes a huge one.

Without a .Rhistory, R_HISTSIZE=0 starts, but the session keeps no command history: the History pane shows none of the session's commands, and the Console's command recall is empty after a browser reload.

R reads R_HISTSIZE differently. Per ?savehistory, it "controls the number of lines that are saved" to the history file (on quit, and by savehistory()), and "there is no limit on the number of lines of history retained during a session". R reads it at the time of saving, accepts 0 (save nothing), and ignores negative or invalid values with a warning, using its default of 512.

Found while working on #19687.

Describe the behavior you expected

RStudio starts with any R_HISTSIZE. As in R, R_HISTSIZE limits how many commands are written to the history file, and doesn't limit the history kept during the session; 0 saves none, and negative or invalid values are ignored.

  • I have read the guide for submitting good bug reports.
  • I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • If I am reporting an RStudio crash, I have included a diagnostics report.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions