Skip to content

Buggy print() call works with inline output when it shouldn't #16483

Closed

Description

@mine-cetinkaya-rundel

System details

RStudio Edition : Desktop
RStudio Version : Version 2025.09.0+387 (2025.09.0+387)
OS Version      : Mac OS 15.6.1 
R Version       : 4.5.1

Steps to reproduce the problem

Add the following code cell into a Quarto document:

library(tidyverse)

as_tibble(mtcars) |>
  distinct(mpg) |>
  print(n = distinct(mpg))

Describe the problem in detail

With "Chunk output inline", this cell doesn't give an error and prints the output.

With "Chunk output in console", this gives an error.

Error in !is.null(n) && n >= 0 : 
  'length = 2475' in coercion to 'logical(1)'

Describe the behavior you expected

I would expect to see the same error regardless of where output is printed.

  • 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 Sep 26, 2025
  2. gtritchie commented on Sep 26, 2025

    @gtritchie
    Member

    Also reproduces in 2025.05.1+513.

    Happens with RMarkdown files as well.

  3. added theissue type on Sep 26, 2025
  4. added and removed
    new
    on Sep 26, 2025
  5. kevinushey commented on Sep 26, 2025

    @kevinushey
    Collaborator

    Just to confirm -- an error here is the expected result, given that this is the same behaviour you would see if you ran this code in a "plain" R session. Is that right?

    I think the confusion here arises because pillar:::print.tbl() accepts an argument n, and so the invocation of print(n = distinct(n)) ends up with n assigned (expectedly? unexpectedly?) that value.

    On the other hand, the print() wrappers that we install to capture table output effectively "block" the S3 dispatch to the print method you were expecting, and so this error doesn't happen.

    Fixing this feels kind of dicey.

  6. mine-cetinkaya-rundel commented on Sep 27, 2025

    @mine-cetinkaya-rundel
    Author

    Correct, error is the expected result.

    The problem is that code appears to work when running the code cells one by one but then fails when you render the document. This has been confusing for students learning R in Quarto documents.

  7. ronblum commented on Sep 29, 2025

    @ronblum
    Contributor

    Putting into "Later" for now due to the diciness, keeping it open in "Later" for reconsideration.

  8. added this to the Later milestone on Sep 29, 2025
  9. kevinushey commented on Oct 1, 2025

    @kevinushey
    Collaborator

    Somewhat related is the fact that you'll ultimately get different outputs even if you had code like:

    library(tidyverse)
    
    as_tibble(mtcars) |>
      distinct(mpg) |>
      print(n = 3)

    This will execute successfully in both cases, but in a chunk with inline output you would still see the regular paged table representation (with no truncation of the view), while in the console you get the truncated view with only 3 rows of output.

    One proposal would be for us to only use a paged-table representation for "auto-printed" tibbles, e.g. if you evaluate a statement that returns a tibble without explicitly printing it, versus the user explicitly calling print() on the object. Then, if print() is called, the user would have consistent behavior regardless.

    @mine-cetinkaya-rundel, do you have any opinions on what we should do in this situation?

  10. mine-cetinkaya-rundel commented on Oct 2, 2025

    @mine-cetinkaya-rundel
    Author

    My vote would be for consistency, therefore the idea of using a paged-table representation for "auto-printed" tibbles makes sense to me.

    Or, if folks are used to seeing the paged-table representation, print(n = 3) should still only print the top 3 rows, I think.

    Going with the first option would make the code I provided at the beginning of this thread fail when running the individual code cell, which I think is preferable. This way there's no expectation the Quarto document would render either.

  11. modified the milestones: Later, Apple Blossom on Oct 2, 2025
  12. self-assigned this
    on Oct 2, 2025
  13. ronblum commented on Oct 14, 2025

    @ronblum
    Contributor

    In RStudio Desktop 2025.11.0-daily+217 one Windows 11, I'm getting the following error with both of the examples above:

    Error in print.default(m, ..., quote = quote, right = right, max = max) :
    invalid 'na.print' specification

  14. ronblum commented on Oct 22, 2025

    @ronblum
    Contributor

    Verified in RStudio Desktop 2025.11.0-daily+261.pro1 on Windows 11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions