xpose icon indicating copy to clipboard operation
xpose copied to clipboard

Feature Request: Add left_join Method to Augment Data

Open billdenney opened this issue 7 years ago • 3 comments

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 avatar Sep 12 '18 17:09 billdenney

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

billdenney avatar Sep 12 '18 19:09 billdenney

@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 avatar Sep 12 '18 19:09 bguiastr

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 avatar Sep 12 '18 19:09 bguiastr