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

Feature Request: Add left_join Method to Augment Data #118

Open
billdenney opened this issue Sep 12, 2018 · 3 comments
Open

Feature Request: Add left_join Method to Augment Data #118

billdenney opened this issue Sep 12, 2018 · 3 comments

Comments

@billdenney
Copy link
Contributor

Similar to #117, it is sometimes helpful to augment the underlying data for plotting purposes.

Could a left_join() method be added that would allow that augmentation such as the following?

left_join.xpose_data <- function(x, y, by=names(y)[1], copy=FALSE, suffix=c(".x", ".y")) {
  ret <- x
  for (data_idx in seq_along(ret$data$data)) {
    if (all(by %in% names(ret$data$data[[data_idx]]))) {
      ret$data$data[[data_idx]] <-
        left_join(x=ret$data$data[[data_idx]], y=y, by=by, copy=copy, suffix=suffix)
    } else {
      warning("Column(s) ", paste(by, collapse=", "), " does not exist in data for problem ", data_idx)
    }
  }
  class(ret) <- class(x) # I think that this is needed because the xpose_data class doesn't have a $<- method
  ret
}

The only limitation I see with this code is that it doesn't assign variable types (and, it's an important limitation).

@billdenney
Copy link
Contributor Author

billdenney commented Sep 12, 2018

This is already covered by mutate() for the most part.

@bguiastr
Copy link
Collaborator

@billdenney that is a good point it could be useful to enrich the data by merging it with data.frames. I will see what I can do. FYI I am also planing to bring many of the mutate_if, mutate_at, summarize_if, etc. in future updates.

@bguiastr
Copy link
Collaborator

bguiastr commented Sep 12, 2018

By the way thanks for your comment about the $<- method I have used a work around xpdb <- as.xpdb(xpdb) (which is exported if you ever need to use it) but maybe your suggestion could be more elegant solution I will need to look into it.

@bguiastr bguiastr added this to the xpose 0.5 milestone Jan 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants