Comments (12)
I've checked methods(class = "data.frame")
in a new R session, indeed it looks like cbind()
and rbind()
are the only methods we want to have in tibble that are not overridden yet. Have I missed anything?
from tibble.
97a0e10 contains a draft, but especially the cases when binding a data frame to a non-data frame are tricky. There's cbind2()
but it's only triggered for S4 objects -> not currently for tibbles. I'm shelving this for now.
from tibble.
Related: #34 for rbind().
from tibble.
I second this issue. My use case is this:
Browse[1]> orpha_ext_id_extractor(x$ExternalReferenceList)
# A tibble: 1 × 2
ICD_10 OMIM
<chr> <chr>
1 Q77.3 607131
Browse[1]> d
# A tibble: 1 × 4
name Orpha_id DisorderFlag name_variants
<chr> <chr> <chr> <list>
1 Multiple epiphyseal dysplasia, Al-Gazali type 166024 476 <chr [1]>
Browse[1]> cbind(d,
orpha_ext_id_extractor(x$ExternalReferenceList)
) %>% str
'data.frame': 1 obs. of 6 variables:
$ name : chr "Multiple epiphyseal dysplasia, Al-Gazali type"
$ Orpha_id : chr "166024"
$ DisorderFlag : chr "476"
$ name_variants:List of 1
..$ Synonym: chr "Multiple epiphyseal dysplasia-macrocephaly-distinctive facies syndrome"
$ ICD_10 : chr "Q77.3"
$ OMIM : chr "607131"
I need to work with list columns, so I want to use tibbles to sidestep some problems. It's a bit annoying if they keep getting implicitly converted back to regular data frames.
I took a stab at it. This is probably a terrible way to do, and maybe buggy for other use cases. I left in my mistakes and attempts in case they are useful to someone else.
cbind.tbl_df = function(...) {
#data table related?
if (!identical(class(..1), "data.frame")) {
for (x in list(...)) {
if (inherits(x, "data.table"))
return(data.table::data.table(...))
}
}
#obvious attempt
# data_frame(...)
#Error in lazyeval::lazy_dots(...) : Promise has already been forced
#dont know what this means
#another attempt
#list(...) %>% set_names("x" + seq_along(.)) %>% as_data_frame
#Error: Each variable must be a 1d atomic vector or list.
#maybe hack solution...
#data.frame(..., check.names = FALSE) %>% as_data_frame
#this vectorizes the list column yielding 3 rows instead of 1
#make a long named list, then to d_f
l = list(...)
#we need to know whether to remove one level of lists
#otherwise we would remove list columns supplied to the function
df_vec = map_lgl(l, inherits, "data.frame")
#works but complicated!
# #peel one layer of the dfs
# l2 = do.call(what = c, args = list(l[[which(df_vec)]]))
#
# #join with the other arguments without peeling off a layer
# l3 = c(l[which(!df_vec)], l2)
#
# #finally, convert to d_f
# l3 %>% as_data_frame
#loop
l4 = list()
for (i in seq_along(l)) {
#peel or not
if (df_vec[i]) {
#peel
l4 = c(l4, l[[i]])
} else {
#not
l4 = c(l4, l[i])
}
}
l4 %>% as_data_frame
}
Test:
> cbind(v = 0, d = data_frame(a = 1), l = list(1:3))
# A tibble: 1 × 3
v a l
<dbl> <dbl> <list>
1 0 1 <int [3]>
So we get the right output.
from tibble.
from tibble.
Unfortunately, a cbind method seems to require patching the base R function, like data.table does. Please use dplyr::bind_cols()
instead.
from tibble.
Can't bind_cols()
(and bind_rows()
sensu #34 ) be moved to tibble? It doesn't make much sense to me for functions to manipulate tibbles to reside in dplyr.
Does that need a separate issue (perhaps one that I have overlooked)?
from tibble.
We should do this eventually, but this also seems to require moving considerable parts of the C++ code, especially for bind_rows()
. This code seems better suited in tibble anyway.
from tibble.
Would this make more sense now, given that the vctrising of tibble/dplyr means that bind_rows
/bind_cols
should have relatively concise implementations?
(I ran into this issue today in a small package I'm developing)
Cheers!
from tibble.
@jeffreypullin If it helps, there is now tibble::add_column()
, which addresses the original gap that started this thread. A lot has changed over 3 years.
from tibble.
Hi Jenny thanks for that - looks very useful. Apologies for not noticing it in the docs.
from tibble.
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 tibble.
Related Issues (20)
- `match(<num>, <num>)` fails on R 4.3.0.
- add_case/add_row silently converts factors to strings
- FR: Show column types like readr in the footer
- Feature request: Suppress message of new names being created in `tibble()` HOT 4
- YAML headers in Tibble
- Tweak the view function
- Calling tibble::rowid_to_column on an object of class "sf" before dplyr::rename will cause " internal error: can't find agr columns" HOT 5
- difference result between data.frame() with tibble()
- `as_tibble.data.table()` method? HOT 3
- Could `as_tibble.data.frame()` be stricter? HOT 2
- Error in stopifnot(is.character(filename), length(filename) == 1L) : reached elapsed time limit HOT 3
- Tibble creation not inputting (or displaying) correct values HOT 2
- create tibble with numeric(0) doesn't give same result as NULL column HOT 1
- Warn with `drop = TRUE` ?
- Weird row names inconsistency HOT 1
- Negative values after "num()" turned into a strange code, like "\033[31m0\033[39m\033[31m.\033......" HOT 1
- as_tibble.data.frame() treats attr()-type attributes inconsistently: sripts "n" but not others. HOT 2
- `tibble` 3.2.1.9017: some errors in running vignette code HOT 15
- tibble 3.2.1 testing fails on Windows R-4.3.2 HOT 6
- Possible edge case bug while identifying whether elements are in column 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 tibble.