Repository navigation
Description
System details
RStudio Edition : Desktop
RStudio Version : Version 2024.04.2+764
OS Version : macOS Sonoma 14.5
R Version : 4.4.1
also tested on
RStudio Edition : Desktop
RStudio Version : 2024.04.2 Build 764
OS Version : Windows Server 2022 Datacenter 21H2
R Version : 4.4.1
Steps to reproduce the problem
- Copy the following code into
test_control_various.R
write("I am about to write some ANSI cursor control sequence to stdout in the next line...\n", stdout())
write("Are Control Sequences Working in write (Y/N): N\x1b[1DY\n", stdout())
# Note also that in Terminal, the above line ends in Y, whereas in the Console it ends in N...
write("This is not printed to the console anymore if this script was sourced from the Console.\n", stdout())
write("But does get printed if we ran this file via Rscript in the Terminal!\n", stdout())
write("And this does get sent to a file correctly any way -- so the script does run, but stdout in console is ruined.","myfile.txt" )
-
From the console, source that R file:
source('./test_control_various.R'). Observe that only the first twowritecalls display anything. All the outputs are missing after the second write, which contains the ANSI cursor-moving control sequence "\x1b[1D". But a file is correctly created by the final call, so the problem is purely a "print-to-stdout" issue, not an execution problem. -
For comparison, use Rscript to source that R file in the terminal:
Rscript ./test_control_various.Rand see that all the outputs are present.
Describe the problem in detail
Using cursor movement ANSI Control sequences seems to close stdout for the rest of the script: no further output from that script is displayed in the console.
The console must reopen it afterwards, as future commands outside of that script work.
The problem does not occur when using Rscript to run the same script in the Terminal.
Describe the behavior you expected
I expect the write calls to still display text in the console after the one call that contains a control sequence.
I know from #9478 (comment) that the Console uses another rendering than the Terminal.
I also see from
| * such as cursor movement are ignored. |
I suspect this will be of interest in particular to @gtritchie who is the master of all things Console and ANSI :)
Thanks for your help!
- 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.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
Activity
kevinushey commentedon Jul 9, 2024
Somewhat more succinctly,
writeLines("N\x1b[1DY")gives:in a plain R session, but gives:
I believe RStudio's console only supports ANSI escapes typically used for colors, which implies the escape is normally closed via
\x1b[m. Note that the "regular" backspace character is handled correctly, though.jucor commentedon Jul 9, 2024
ronblum commentedon Aug 29, 2024
I tested using the example in the QA notes, and got the expected result:
However, I also tried this variation, going back 55, which changes the line with the command on it:
Also, going forward 5 executed the next line in a script, so running the first line
results in
@kevinushey I see why this happens, but is this the behavior that we want?
kevinushey commentedon Aug 29, 2024
I think this is fine.
jucor commentedon Aug 29, 2024
OK, how about the fact that subsequent write() aren't displayed after this one?
Where you able to reproduce?
Thanks for your work on this!
kevinushey commentedon Aug 29, 2024
Thanks for catching that; this appears to still be an issue.
kevinushey commentedon Aug 29, 2024
Sorry, yes, it is working -- I forgot to include
stdout()in my second usage.jucor commentedon Aug 29, 2024
Terrific, thanks!
ronblum commentedon Sep 10, 2024
Verified in
using the original script and the series of examples throughout this issue.