You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
a failed loadhistory() discards the session's console history #19686
RStudio Edition : Desktop and Server
RStudio Version : main (2026.12 development)
OS Version : all
R Version : all
Steps to reproduce the problem
Run a few commands in the Console.
Run loadhistory("no-such-file"). On macOS and Linux this reports No such file or directory; on Windows it reports nothing.
Run savehistory(tmp <- tempfile()), then readLines(tmp).
Describe the problem in detail
readLines(tmp) returns character(0): the commands from step 1 are gone. The failed loadhistory() emptied the session's console history.
ConsoleHistory::loadFromFile() (src/cpp/r/session/RConsoleHistory.cpp) clears the history before it checks that the file exists, and reads straight into it, so any failure -- a mistyped path, a file that can't be read, a read error part-way through -- leaves the history empty or partial. The Console's own command list still looks unchanged, because the reset is only sent to the client after a successful load, but the session's copy is what gets written out. With "Always save history" on (the default), quitting the session then overwrites .Rhistory with only the commands run after the failed load. The emptied history also carries across a session suspend and resume.
Activity
keep the history when the history file is a directory
keep the console history when loadhistory() fails (#19688)