Comments (3)
The way collateral currently works is that map_safely()
and map_quietly()
just use purrr::map()
, but they add S3 classes (safely_mapped
and quietly_mapped
, respectively—not collat
) to the list that comes back. Then S3 methods are registered to those classes to do the fancy output. S3 classes generally dispatch by checking an object's classes from first to last and dispatching to the method of the first registered class.
So what I'm thinking is that when you rbind
two data frames where one has one class and the other has the other class, the list columns are probably concatenated successfully, but the classes just get thrown together and the method dispatch goes to whichever class ended up in front. I didn't really consider a scenario where someone might concatenate a safe column and a quiet column, and since the methods for printing just check whether components like error
or warning
are present, they don't crash if fed the wrong class—they just don't check for one or the other!
from collateral.
One misleading thing here is that the type shown at the top of the tibble column, collat
, is not actually one of the classes of the list. That might make it falsely seem like a safe column and a quiet column could be concatenated. Anticipating your use case here, I think this is probably less of an issue if we fix #8 and provide a way to check for both errors and warnings at once 😄
from collateral.
I'm looking back into this, as some workflows I'm testing that involve using dplyr::bind_rows()
on data frames that have collateral columns cause them to lose their formatting:
library(tidyverse)
library(collateral)
test =
# tidy up and trim down for the example
mtcars %>%
rownames_to_column(var = "car") %>%
as_tibble() %>%
select(car, cyl, disp, wt) %>%
# spike some rows in cyl == 4 to make them fail
mutate(wt = dplyr::case_when(
wt < 2 ~ -wt,
TRUE ~ wt)) %>%
# nest and do some operations quietly()
nest(-cyl) %>%
mutate(qlog = map_quietly(data, ~ log(.$wt)))
# now slice them up...
test1 = test %>% slice(1)
test2 = test %>% slice(2)
test3 = test %>% slice(3)
# ... and combine them. problem!
test_rejoined = bind_rows(test1, test2, test3)
#> Warning in bind_rows_(x, .id): Vectorizing 'quietly_mapped' elements may
#> not preserve their attributes
#> Warning in bind_rows_(x, .id): Vectorizing 'quietly_mapped' elements may
#> not preserve their attributes
#> Warning in bind_rows_(x, .id): Vectorizing 'quietly_mapped' elements may
#> not preserve their attributes
test_rejoined
#> # A tibble: 3 x 3
#> cyl data qlog
#> <dbl> <list> <list>
#> 1 6 <tibble [7 x 3]> <list [4]>
#> 2 4 <tibble [11 x 3]> <list [4]>
#> 3 8 <tibble [14 x 3]> <list [4]>
class(test_rejoined$qlog)
#> [1] "list"
Created on 2019-07-09 by the reprex package (v0.3.0)
This took me by surprise a little, as my understanding is that classes are supposed to be exempt from attributes getting wiped when a vector is modified. So I'm not 100% sure what's happening, but it may be that I need to handle collateral lists getting concatenated or subsetted a little more explicitly.
R/format.r
has some extra S3 methods that I mostly added because I was trying to follow along with the pillar
documentation, but I wonder if—for example—these two might deserve some more attention:
#' @rdname collateral_extras
#' @export
c.safely_mapped <- function(x, ...) {
as_safely_mapped(NextMethod())
}
#' @rdname collateral_extras
#' @export
`[.safely_mapped` <- function(x, i) {
as_safely_mapped(NextMethod())
}
from collateral.
Related Issues (14)
- `pmap` variants not handling `.l` properly HOT 3
- Column classes don't survive dplyr::bind_rows (or joins?) HOT 1
- Refresh and solicit feedback on vignettes
- Add example datasets
- Integration with reticulate
- Coloured output in README not being converted to HTML
- collateral not on cran anymore? HOT 7
- Knitted output HOT 3
- Exact the "output" as a new column from a `collateral` class column [question] HOT 4
- Integration with furrr HOT 1
- Add safely() arguments HOT 1
- Helpers for extracting side effects HOT 2
- feature request: handle errors and warnings together peacfully HOT 8
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 collateral.