-
-
Notifications
You must be signed in to change notification settings - Fork 969
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
Adding "paged_df"
to a data.frame
class stops the data frame from printing to console when {rmarkdown}
is loaded
#2562
Comments
Do you remember when it was working ? Which version of the tools ? This is really puzzling to me it was working before... Let's discuss why this is happening. I believe you get the issue because your print method is returning The printing does correctly happens, meaning This all happens in evaluate handlers So using diff --git a/R/print.R b/R/print.R
index d6a3d201..3959cb95 100644
--- a/R/print.R
+++ b/R/print.R
@@ -3,7 +3,6 @@
print.tidytable <- function(x, ..., n = NULL, width = NULL, n_extra = NULL) {
y <- set_class(x, print_class("tidytable_print"))
print(y, ..., n = n, width = width, n_extra = n_extra)
- invisible(x)
}
#' @export I did a few tests, and this is happening at the evaluate level too > str(evaluate::evaluate(input = "library(rmarkdown)\nlibrary(tidytable)\ntidytable(x = 1:3, y = 1:3)"))
List of 3
$ :List of 1
..$ src: chr "library(rmarkdown)\n"
..- attr(*, "class")= chr "source"
$ :List of 1
..$ src: chr "library(tidytable)\n"
..- attr(*, "class")= chr "source"
$ :List of 1
..$ src: chr "tidytable(x = 1:3, y = 1:3)"
..- attr(*, "class")= chr "source" See how there is no result captured when rmarkdown is making the print method available We have one results showing when no rmarkdown is loaded, > str(evaluate::evaluate(input = "suppressPackageStartupMessages(library(tidytable))\ntidytable(x = 1:3, y = 1:3)"))
List of 3
$ :List of 1
..$ src: chr "suppressPackageStartupMessages(library(tidytable))\n"
..- attr(*, "class")= chr "source"
$ :List of 1
..$ src: chr "tidytable(x = 1:3, y = 1:3)"
..- attr(*, "class")= chr "source"
$ : chr "# A tidytable: 3 × 2\n x y\n <int> <int>\n1 1 1\n2 2 2\n3 3 3\n" So maybe this is specific to how I am still wondering about this nested print() of object, and how evaluate works. @yihui you know all this better than me - do you confirm this what is happening when the method defined is print.tidytable <- function(x, ..., n = NULL, width = NULL, n_extra = NULL) {
y <- set_class(x, print_class("tidytable_print"))
print(y, ..., n = n, width = width, n_extra = n_extra)
invisible(x)
} and that this is how it work ? Or is there an issue somewhere. I am surprised this was working before as mentioned .... 🤔 @markfairbanks regarding printing in knitr context, you can have custom
Though adding the class is working ok. |
I'm not sure unfortunately. It's been working fine for a few years but broke semi-recently.
I've tried all sorts of things but nothing I do seems to allow me to define the Is there a simple way to define "if Feel free to close this issue by the way as maybe this is more of a Stack Overflow type question - but if you happen to know what I need to do that'd be great. |
I'll think about this. To understand full context, out of curiosity, why return |
I can't remember to be honest 😅. I think a contributor recommended it and it was part of the hack to get paged printing to work, but it's possible it was unnecessary to add. Edit: If I remove |
So I reset printing to get back to basics. Essentially I have a data frame which uses printing from But now paged printing doesn't work. library(tidytable)
df <- tidytable(x = 1:3, y = c("a", "a", "b"))
df
#> # A tidytable: 3 × 2
#> x y
#> <int> <chr>
#> 1 1 a
#> 2 2 a
#> 3 3 b
class(df)
#> [1] "tidytable" "tbl" "data.table" "data.frame" |
Adding
"paged_df"
to adata.frame
subclass stops the data frame from printing to console when{rmarkdown}
is loaded.This issue occurs when using
library(rmarkdown)
but also prevents things from working with the{reprex}
package.This is a new issue, not sure what changed. I found out about it due to this issue here. I add
"paged_df"
as a subclass of atidytable
found in the print method here so paged printing would work in Rmarkdown. Not sure if there is a better/recommended way to allow paged printing of a data frame subclass like a tidytable?There's not output here when using
reprex::reprex()
Created on 2024-07-01 with reprex v2.1.0
Created on 2024-07-01 with reprex v2.1.0
-->
Checklist
When filing a bug report, please check the boxes below to confirm that you have provided us with the information we need. Have you:
formatted your issue so it is easier for us to read?
included a minimal, self-contained, and reproducible example?
pasted the output from
xfun::session_info('rmarkdown')
in your issue?upgraded all your packages to their latest versions (including your versions of R, the RStudio IDE, and relevant R packages)?
installed and tested your bug with the development version of the rmarkdown package using
remotes::install_github("rstudio/rmarkdown")
?The text was updated successfully, but these errors were encountered: