Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running examples apparently uses print() instead of show() #2848

Open
rvlenth opened this issue Jan 30, 2025 · 0 comments
Open

Running examples apparently uses print() instead of show() #2848

rvlenth opened this issue Jan 30, 2025 · 0 comments

Comments

@rvlenth
Copy link

rvlenth commented Jan 30, 2025

My package has different print() and show() methods. When I enter an expression on the console, the results are displayed using show(), not print(). A case in point is running example code for package functions. I think we would want to see what's displayed on the console; however, evidently pkgdown renders example results using print() rather than show().

I noticed this snippet for the man page for emmeans::ref_grid() on my pkgdown site:

fiber.lm <- lm(strength ~ machine*diameter, data = fiber)
ref_grid(fiber.lm)
#>  machine diameter prediction    SE df
#>  A           24.1       40.2 0.777  9
#>  B           24.1       41.6 0.858  9
#>  C           24.1       38.5 0.966  9
#> 

The above results are what is shown using print(). However, if I enter the code on the console, I see:

> fiber.lm <- lm(strength ~ machine*diameter, data = fiber)
> ref_grid(fiber.lm)
'emmGrid' object with variables:
    machine = A, B, C
    diameter = 24.133

... which are the results of show().

I also note that the reprex package *does use show(). Here are results using reprex::reprex():

library(emmeans)
## Welcome to emmeans.
## Caution: You lose important information if you filter this package's results.
## See '? untidy'
fiber.lm <- lm(strength ~ machine*diameter, data = fiber)
ref_grid(fiber.lm)
## 'emmGrid' object with variables:
##     machine = A, B, C
##     diameter = 24.133

ref_grid(fiber.lm) |> show()
## 'emmGrid' object with variables:
##     machine = A, B, C
##     diameter = 24.133

ref_grid(fiber.lm) |> print()
##  machine diameter prediction    SE df
##  A           24.1       40.2 0.777  9
##  B           24.1       41.6 0.858  9
##  C           24.1       38.5 0.966  9

Created on 2025-01-30 with reprex v2.1.1
What we see here is the default, plus explicit pipes to show() and print().

I believe that pkgdown should use show() when it renders example output.

Note

I reference my site above, but probably by the time you review this issue, it will be rendered differently, as I changed the print method to show so as to get what I want to see on the site. However, I still think this is a bug in pkgdown and will revert to my old code when you fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant