Flushing and comments
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 1.8k
- Forks
- 349
- Avg merge
- 5h 13m
- Merged PRs (30d)
- 4
Description
I am running the below code chunk with knitr in RStudio.
<<engine='python'>>=
#comment 1
a = True
a[0] = False
#comment 2
@
The expected output is that it prints an error immediately after a[0] = False but it somehow buffers until after #comment 2 as indicated below:

My temporary fix is to:
<<engine='python', echo=FALSE>>=
def fl():
import sys
sys.stdout.flush()
sys.stderr.flush()
@
<<engine='python'>>=
#comment 1
a = True
a[0] = False
fl()
#comment 2
@

However, I can't be putting fl() everywhere. How can I make it print before comment 2 without additional lines of code such as fl()?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the knitr Python engine using the code shown, focusing on the output produced after a[0] = False and before #comment 2. Trace how reticulate and knitr capture or flush Python stdout and stderr; done means the error appears before the later comment without adding fl() calls.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, r
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100