-
Notifications
You must be signed in to change notification settings - Fork 12
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
Making Rcompadre pipe-friendly #25
Comments
I think this would require a new definition for However, I think (Someone else also should weigh in here: this is outside my personal experience) |
I'm not sure that piping is the problem here, it's having a function that does what @patrickbarks wants to do (in the example, take the output from What this comes down to is that people may want to be able to subset based on some properties of the matrices (is_ergodic, has_NAs, lambda). Perhaps then it's a question of making
|
As best I can tell, all you need to do to make it pipe friendly is make sure the first argument of the subsequent function is the I've only tried this with S3 for other projects, but I don't think it should be any different for S4. |
I don't think I'm grasping the issue properly! But I think I get it now. In Patrick's example, I guess it would work if:
I guess it's not working in the pipe sequence because the variables |
@levisc8 beat me to it. But I guess it doesn't change the original problem? I can see now it may be useful to have some sort of function that adds to the metadata to make the objects more pipe-friendly so that (as @tdjames1) pointed out), @patrickbarks first code sequence would work with a |
This thread helped me clarify what I'm after. I guess I was really only interested in creating a mutate-like function that takes a CompadreData db, and adds a column to In any case, the proposal in #27 would make this unnecessary because with the flat structure of the proposed |
Stepping back a bit, I wonder if there is any mileage in thinking about implementing a method that allows user to mutate
The user-specified function would be applied to the This is an alternative approach to flattening the data (cf. #27, #29) that maintains the integrity of the matrix objects while allowing users access to their contents to calculate derived values. |
As noted briefly in PR #24, I'm interested in making Rcompadre work nicely with dplyr's pipe operator (
%>%
). The pipe operator passes an object on the left side to a function on the right side (e.g.x %>% mean()
==mean(x)
), and when used in series can make code more readable.A particular piping sequence I often perform with compadre is to calculate some quantity for every row of the db, add it as a column to the metadata, and then subset the db based on that new column (and repeat). In the past I've worked with a tibble version of the db (i.e. metatadata + list-columns for matA, matU, ..., matrixClass) to make this sequence easier:
For instance, say I want to work with a set of matrices reflecting populations in decline (lambda < 1), and I only want ergodic matrices with no NAs. With the tibble version I can use a sequence of dplyr and purrr functions to repeatedly add columns (mutate) and subset (filter) based on those new columns.
With a CompadreData object, the equivalent sequence might look something like this:
So piping works fine with subsetting (and cleanDB), but I can't replicate the fully-piped sequence without an Rcompadre equivalent to dplyr::mutate(). What we would need is a function that takes a CompadreData object as the first argument, and returns a CompadreData object with an additional metadata column (based on some transformation specified in the second argument). I don't know what this function would entail in practice, but I think this general type of functionality would be desirable (to me anyway). Thoughts?
The text was updated successfully, but these errors were encountered: