Comments (3)
@leungi These are great! Would you want to make a pull request with the edits? For the other issue you can open a 2nd PR or combine them both into one, whichever one is easier for you.
If you haven't done a PR before I can walk you through it, or if you prefer I could make the changes myself. Either way afterwards we can add you as a contributor to the package. Let me know how you want to proceed
from tidytable.
I'll work on the PR; thanks for endorsing!
from tidytable.
Similarly for dt_bind_cols()
.
Another suggestion is taking a page out off dplyr::bind_cols()
with their column repair. The current dt_bind_cols()
doesn't check/prevent duplicated column names, and creates issue when it happens.
library(tidydt)
#>
#> Attaching package: 'tidydt'
#> The following object is masked from 'package:stats':
#>
#> dt
one <- mtcars[1:4,]
two <- mtcars[11:14,]
# both OK
dplyr::bind_cols(one, two)
#> mpg cyl disp hp drat wt qsec vs am gear carb mpg1 cyl1 disp1 hp1
#> 1 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 17.8 6 167.6 123
#> 2 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4 16.4 8 275.8 180
#> 3 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1 17.3 8 275.8 180
#> 4 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 15.2 8 275.8 180
#> drat1 wt1 qsec1 vs1 am1 gear1 carb1
#> 1 3.92 3.44 18.9 1 0 4 4
#> 2 3.07 4.07 17.4 0 0 3 3
#> 3 3.07 3.73 17.6 0 0 3 3
#> 4 3.07 3.78 18.0 0 0 3 3
dplyr::bind_cols(list(one, two))
#> mpg cyl disp hp drat wt qsec vs am gear carb mpg1 cyl1 disp1 hp1
#> 1 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 17.8 6 167.6 123
#> 2 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4 16.4 8 275.8 180
#> 3 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1 17.3 8 275.8 180
#> 4 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 15.2 8 275.8 180
#> drat1 wt1 qsec1 vs1 am1 gear1 carb1
#> 1 3.92 3.44 18.9 1 0 4 4
#> 2 3.07 4.07 17.4 0 0 3 3
#> 3 3.07 3.73 17.6 0 0 3 3
#> 4 3.07 3.78 18.0 0 0 3 3
# OK
dt_bind_cols(one, two)
#> mpg cyl disp hp drat wt qsec vs am gear carb mpg cyl disp hp
#> 1: 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 17.8 6 167.6 123
#> 2: 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4 16.4 8 275.8 180
#> 3: 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1 17.3 8 275.8 180
#> 4: 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 15.2 8 275.8 180
#> drat wt qsec vs am gear carb
#> 1: 3.92 3.44 18.9 1 0 4 4
#> 2: 3.07 4.07 17.4 0 0 3 3
#> 3: 3.07 3.73 17.6 0 0 3 3
#> 4: 3.07 3.78 18.0 0 0 3 3
# fails
dt_bind_cols(list(one, two))
#> Error in dt_bind_cols(list(one, two)): All inputs must be a data.frame or data.table
dt_bind_cols_edit <- function (.data, ...)
{
# check if input .data is already a list; if not, transform to list
if (class(.data) != "list") {
.data <- list(.data)
}
dots <- enexprs(...)
dots <- dt_map(dots, eval)
dots <- append(.data, dots)
if (!all(dt_map_lgl(dots, is.data.frame)))
stop("All inputs must be a data.frame or data.table")
if (!all(dt_map_lgl(dots, is.data.table)))
dots <- dt_map(dots, as.data.table)
do.call(cbind, dots)
# name repair from dplyr::bind_cols()
# tibble::repair_names(do.call(cbind, dots))
}
# both OK
dt_bind_cols_edit(one, two)
#> mpg cyl disp hp drat wt qsec vs am gear carb mpg cyl disp hp
#> 1: 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 17.8 6 167.6 123
#> 2: 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4 16.4 8 275.8 180
#> 3: 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1 17.3 8 275.8 180
#> 4: 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 15.2 8 275.8 180
#> drat wt qsec vs am gear carb
#> 1: 3.92 3.44 18.9 1 0 4 4
#> 2: 3.07 4.07 17.4 0 0 3 3
#> 3: 3.07 3.73 17.6 0 0 3 3
#> 4: 3.07 3.78 18.0 0 0 3 3
dt_bind_cols_edit(list(one, two))
#> mpg cyl disp hp drat wt qsec vs am gear carb mpg cyl disp hp
#> 1: 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 17.8 6 167.6 123
#> 2: 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4 16.4 8 275.8 180
#> 3: 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1 17.3 8 275.8 180
#> 4: 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 15.2 8 275.8 180
#> drat wt qsec vs am gear carb
#> 1: 3.92 3.44 18.9 1 0 4 4
#> 2: 3.07 4.07 17.4 0 0 3 3
#> 3: 3.07 3.73 17.6 0 0 3 3
#> 4: 3.07 3.78 18.0 0 0 3 3
Created on 2020-01-19 by the reprex package (v0.3.0)
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.