Comments (9)
Potentially AsIs
could be used with anything, so I think we just need a .AsIs()
method somewhere that just calls NextMethod()
from pillar.
Tried adding pillar_shaft.AsIs()
to no avail -- it's handled by pillar_shaft.default()
anyway which calls as.character()
on the input:
as.character(I(list(1, 1:2, 1:3)))
#> [1] "1" "1:2" "1:3"
Code:
Lines 134 to 138 in be24a37
We'd need to strip the "AsIs"
class from the object's classes, but somehow this smells like a bad idea. Please advise.
from pillar.
You're sure this doesn't work?
pillar_shaft.AsIs <- function(x, ...) {
NextMethod()
}
Oh, because list
isn't in the class vector?
from pillar.
We could do
#' @export
#' @rdname pillar_shaft
pillar_shaft.AsIs <- function(x, ...) {
pillar_shaft.list(x, ...)
}
or (more generally)
#' @export
#' @rdname pillar_shaft
pillar_shaft.default <- function(x, ...) {
if (is.list(x)) pillar_shaft.list(x, ...)
else pillar_shaft(as.character(x), ...)
}
But then:
pillar::colonnade(list(a = 1:3, b = I(list(1, 1:2, 1:3, c(1:3,3)))))
#> a b
#> <int> <S3: AsIs>
#> 1 1 <S3: AsIs>
#> 2 2 <S3: AsIs>
#> 3 3 <S3: AsIs>
Or we strip the class manually:
#' @export
#' @rdname pillar_shaft
pillar_shaft.AsIs <- function(x, ...) {
if (all(class(x) == "AsIs")) {
class(x) <- NULL
} else {
class(x) <- setdiff(class(x), "AsIs")
}
pillar_shaft(x, ...)
}
That one looks better, but I'm not sure if this is a safe approach:
pillar::colonnade(list(a = 1:3, b = I(list(1, 1:2, 1:3, c(1:3,3)))))
#> a b
#> <int> <S3: AsIs>
#> 1 1 <dbl [1]>
#> 2 2 <int [2]>
#> 3 3 <int [3]>
#> 1 1 <dbl [4]>
The NextMethod()
approach doesn't change the output, because the call is forwarded to .default()
and not to .list()
.
from pillar.
An even more general approach would be to do manual switchpatch in the default method:
#' @export
#' @rdname pillar_shaft
pillar_shaft.default <- function(x, ...) {
switch(typeof(x),
list = pillar_shaft.list(x, ...),
numeric = pillar_shaft.numeric(x, ...),
logical = pillar_shaft.logical(x, ...),
pillar_shaft.character(x, ...),
)
}
Then we're basically pretending that the final member of the class is always the typeof()
.
from pillar.
This works if we use switchpatch also in obj_sum.AsIs()
.
from pillar.
Oh yeah, that's a better idea - we either call NextMethod()
or do switchpatch depending on the length of the class.
from pillar.
Let's keep switchpatch in mind, I haven't added it yet. Current output:
tibble::as_tibble(data.frame(a = 1:3, b = I(list(1, 1:2, 1:3))))
#> # A tibble: 3 x 2
#> a b
#> <int> <I(list)>
#> 1 1 <dbl [1]>
#> 2 2 <int [2]>
#> 3 3 <int [3]>
from pillar.
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.
from pillar.
Related Issues (20)
- Very small numbers print as `Inf.e-324` HOT 6
- Should `*` or `i` be used for footer information? HOT 11
- Truncated list-cols don't seem to get grey coloring HOT 2
- pillar_num and logical vectors cause (potential?) issues
- Installation of pillar 1.9.0 in GitHub actions fails HOT 2
- Should time zones be changing datetime formatting?
- Conditional colouring of values in specific columns HOT 2
- Infinite date-time being printed twice
- Why do `new_pillar_shaft()` and `new_pillar_shaft_simple()` default `min_width` to `width`? HOT 1
- FR: don't print seconds in dttm if there is not enough space
- FR: Add a pillar.max_chars option HOT 1
- Modify tbl_df subclass print in a package HOT 2
- Feature request: Option to print both head and tail of tables? HOT 6
- Use pillar to make column titles red HOT 1
- Guidance colorizing values within a column HOT 2
- The output of `glimpse()` is too wide in RStudio Visual Editor mode HOT 6
- Show colour in `glimpse()` HOT 2
- pillar::num type vector is not properly treated by base::sum (with respect to na.rm=TRUE) HOT 1
- Some changes make warnings in tibble
- Please add col number to glimpse output HOT 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 pillar.