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

Better column names when unnamed objects passed to merge #248

Closed
joshuaulrich opened this issue Jun 17, 2018 · 0 comments
Closed

Better column names when unnamed objects passed to merge #248

joshuaulrich opened this issue Jun 17, 2018 · 0 comments
Assignees
Labels
enhancement Enhancement to existing feature
Milestone

Comments

@joshuaulrich
Copy link
Owner

The column names of a merge() result can be monstrous if raw, unnamed objects are passed to merge(). This can occur when merge() is called via do.call(). For example:

data(sample_matrix)
x <- as.xts(sample_matrix)
d <- setNames(lapply(head(x, 2), function(x) { dimnames(x) <- NULL; x }), NULL)

# cbind.xts() calls merge.xts()
do.call(cbind, d)
           c.50.0397819115463..50.2304961977954.
2007-01-02                              50.03978
2007-01-03                              50.23050
           c.50.1177772350145..50.421876002125.
2007-01-02                             50.11778
2007-01-03                             50.42188
           c.49.9504146442813..50.2304961977954.
2007-01-02                              49.95041
2007-01-03                              50.23050
           c.50.1177772350145..50.3976663383861.
2007-01-02                              50.11778
2007-01-03                              50.39767

# zoo is similar
do.call(cbind, lapply(d, as.zoo))
           structure(c(50.0397819115463, 50.2304961977954), .Dim = c(2L, 
2007-01-02                                                       50.03978
2007-01-03                                                       50.23050
           structure(c(50.1177772350145, 50.421876002125), .Dim = c(2L, 
2007-01-02                                                      50.11778
2007-01-03                                                      50.42188
           structure(c(49.9504146442813, 50.2304961977954), .Dim = c(2L, 
2007-01-02                                                       49.95041
2007-01-03                                                       50.23050
           structure(c(50.1177772350145, 50.3976663383861), .Dim = c(2L, 
2007-01-02                                                       50.11778
2007-01-03                                                       50.39767

# matrix is a little nicer
do.call(cbind, lapply(d, as.matrix))
             X[[i]]   X[[i]]   X[[i]]   X[[i]]
2007-01-02 50.03978 50.11778 49.95041 50.11778
2007-01-03 50.23050 50.42188 50.23050 50.39767
@joshuaulrich joshuaulrich added the enhancement Enhancement to existing feature label Jun 17, 2018
joshuaulrich added a commit that referenced this issue Apr 19, 2019
We called as.character(dots) for all objects passed to merge(), even
if we had symbol names. This was incredibly expensive for large
objects.

Now we only call as.character() on the subset of dots that do not have
symbol names. This means we will often not call as.character() at all.

See #248.
@joshuaulrich joshuaulrich self-assigned this Apr 19, 2019
@joshuaulrich joshuaulrich added this to the 0.11-2 milestone Jul 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to existing feature
Projects
None yet
Development

No branches or pull requests

1 participant