Comments (9)
I hadn't seen that actually. I gave it a try and it didn't work unfortunately.
It seems to mimic this process of creating a setup chunk and setting global chunk options:
```{r setup}
knitr::opts_chunk$set(paged.print=TRUE)
from tidytable.
That's interesting. I thought for sure knitr
would check for that and print them with the same formatting. I'll try to read up on it over the next few days and see what I can find.
from tidytable.
Interesting. What does the error look like?
from tidytable.
No error, but it prints differently. If you open an R Notebook and paste in this code you'll see that the data.table returns a "paged print" that allows you to scroll through the data, and the tidytable does a normal console print.
library(tidytable)
library(data.table)
data.table(x = 1:50, y = 1:50) # Returns a paged.print
tidytable(x = 1:50, y = 1:50) # Returns a console print
In Rmarkdown paged.print = TRUE
is the default. When set to FALSE
it returns a console print. So the tidytable should (hypothetically) return a paged.print
in this situation.
I think I have to somehow register an S3 method for tidytable with the knitr
or rmarkdown
print, but I can't seem to figure out how.
Here are a couple pages I've found that seem to touch on the topic:
https://cran.r-project.org/web/packages/knitr/vignettes/knit_print.html#for-package-authors
https://community.rstudio.com/t/customizing-general-objects-formatting-output/11262
from tidytable.
Oh, yes. I've seen this with other output. Does the tidytable
class have a second class (like data.table
or data.frame
)?
from tidytable.
Yep - there's 3 classes: c("tidytable", "data.table", "data.frame")
from tidytable.
So I don't know if this is the "correct" way, but it seems like inside print.tidytable
there should be a way to do something like this:
if ("knitr" %in% installed.packages()) {
if (knitr::opts_chunk$get()$paged.print) {
rmarkdown::paged_table(x)
}
}
But I can't seem to get it to work. Not sure if you have any ideas on that one.
This issue shows that explicitly calling print()
overrides paged.print = TRUE
. So the "if" statement shouldn't be necessary, but I haven't been able to figure out another way
from tidytable.
You probably saw this but wanted to check. Have you put those arguments in the Rmarkdown yet and is it still printing wrong?
from tidytable.
Found a workaround! Basically - if knitr is installed and paged.print = TRUE
, make the class of the object c("data.table", "tidytable", "data.frame")
. If not make the class c("tidytable", "data.table", "data.frame")
.
That makes it page-print like a data.table, but console print like a tidytable.
There's probably a better way, but this will work for now until we can figure out a better solution.
@TysonStanley Thanks for taking a look!
as_tidytable <- function(x) {
UseMethod("as_tidytable")
}
#' @export
as_tidytable.tidytable <- function(x) {
x
}
#' @export
as_tidytable.default <- function(x) {
if (is.data.table(x)) x <- add_class(x)
else x <- add_class(as.data.table(x))
x
}
add_class <- function(.data) {
if (knitr_installed) {
if (!knitr::opts_chunk$get()$paged.print %||% TRUE) {
class(.data) <- c("tidytable", "data.table", "data.frame")
} else {
class(.data) <- c("data.table", "tidytable", "data.frame")
}
}
.data
}
from tidytable.
Related Issues (20)
- `distinct` not working with lists HOT 2
- using `pick()` inside `count()` leads to an unhelpful error HOT 5
- deprecated notation HOT 1
- Bug: unnest() HOT 2
- Failure with dev glue HOT 3
- Release v0.11.0 HOT 1
- When two tidytables are subtracted, the class `tidytable` gets lost on the way. HOT 2
- weird error using testthat HOT 2
- exposing list_flatten HOT 1
- summarize with across behaves in a strange way and gives an error when I use lapply inside
- Renaming in `group_by()` can lead to grouping by nonexistent columns
- ifelse and if_else HOT 1
- pmap is not working for data frames HOT 1
- Error "mutate_rowwise()" several columns. HOT 2
- Group_by bug with purrr::reduce HOT 4
- pmap() doesn't name list elements using existing names HOT 2
- `tidytable` objects are not printed after loading `quarto` HOT 4
- `group_by` + equality `filter` on column with `NA` values introduces `NA` rows HOT 2
- Allow paged printing in `rmarkdown`
- Release v0.11.1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tidytable.