Skip to content
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

[FR] list_cbind() matrices #1082

Closed
mikmart opened this issue May 27, 2023 · 4 comments
Closed

[FR] list_cbind() matrices #1082

mikmart opened this issue May 27, 2023 · 4 comments

Comments

@mikmart
Copy link
Contributor

mikmart commented May 27, 2023

It would be nice if list_cbind() worked with matrices.

A <- matrix(1:4, 2, 2)
B <- matrix(5:8, 2, 2)
do.call(cbind, list(A, B))
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    3    5    7
#> [2,]    2    4    6    8
purrr::list_cbind(list(A, B))
#> Error in `purrr::list_cbind()`:
#> ! Each element of `x` must be either a data frame or `NULL`.
#> ℹ Elements 1 and 2 are not.
#> Backtrace:
#>     ▆
#>  1. └─purrr::list_cbind(x = list(A, B))
#>  2.   └─purrr:::check_list_of_data_frames(x)
#>  3.     └─cli::cli_abort(...)
#>  4.       └─rlang::abort(...)
@mikmart
Copy link
Contributor Author

mikmart commented May 27, 2023

And of course also list_rbind() (forgot to mention it for the search keyword).

@hadley
Copy link
Member

hadley commented Jul 26, 2023

We don't have support for this in vctrs, so unfortunately it's a long way from coming to purrr:

A <- matrix(1:4, 2, 2)
B <- matrix(5:8, 2, 2)
str(vctrs::vec_cbind(A, B))
#> New names:
#> • `` -> `...1`
#> • `` -> `...2`
#> • `` -> `...3`
#> • `` -> `...4`
#> 'data.frame':    2 obs. of  4 variables:
#>  $ ...1: int  1 2
#>  $ ...2: int  3 4
#>  $ ...3: int  5 6
#>  $ ...4: int  7 8

Created on 2023-07-26 with reprex v2.0.2

@hadley hadley closed this as completed Jul 26, 2023
@mikmart
Copy link
Contributor Author

mikmart commented Jul 26, 2023

Thanks. I presume there are no plans to add it to vctrs, as the current behaviour always results in a data frame?

@hadley
Copy link
Member

hadley commented Jul 27, 2023

Yeah, and I like the idea of keeping list_rbind() and list_cbind() closely focussed on data frames as the semantics will get complicated if you have a mix of data frames and matrices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants