Skip to content

Background Jobs: Newlines added, but also ignored, when outputting to stdout (works in stderr) #15325

Open

Description

@HenrikBengtsson

System details

RStudio Edition : Server
RStudio Version : 2024.09.0-375 (also 2024.04.1-748)
OS Version      : Linux Ubuntu 22.04.5 LTS
R Version       : 4.4.1

Steps to reproduce the problem

Save the following as bg.R and run it as a background job:

con <- stdout()
cat("1", file = con)
cat("2", file = con)
cat("3", file = con)
cat("\n\n\n", file = con)
cat("a\n", file = con)
cat("b\n", file = con)
cat("c\n", file = con)

Describe the problem in detail

Running bg.R as a background job outputs:

1
2
3
a
b
c

Note how there are newlines added automatically, but note also how multiple newlines (\n\n\n) are replaced with a single one.

Describe the behavior you expected

The expected output is:

123


a
b
c

as we get when we run it in the RStudio Console and in the terminal.

If we send the output to the standard error (stderr), by updating the code to:

con <- stderr()

the output is as expected.

  • 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.

Activity

  1. added
    new
    on Oct 16, 2024
  2. kevinushey commented on Oct 16, 2024

    @kevinushey
    Collaborator

    Looks like this happens here:

    // if this isn't the final line in the set, add a newline
    if (i < lines.size() - 1)
    {
    output.append("\n");
    }

    The complication here happens because RStudio appends a bunch of progress markers into the generated output, and then tries to remove those when actually providing that output back to the front-end for display.

  3. removed
    new
    on Oct 16, 2024
  4. added this to the Mariposa Orchid milestone on Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions