Code Monkey home page Code Monkey logo

Comments (8)

levisc8 avatar levisc8 commented on August 11, 2024 1

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 CompadreData object. %>% doesn't really recognize classes, just passes the output of the left side to the first part of the right side.

I've only tried this with S3 for other projects, but I don't think it should be any different for S4.

from rcompadre.

iainmstott avatar iainmstott commented on August 11, 2024

I think this would require a new definition for %>%, which is an exported method from dplyr. You're passing it an object (class CompadreData) which it won't understand, so we'll need to import it from dplyr and add it to the methods for CompadreData objects. This would mean the package importing dplyr and all of its imports (a fair few).

However, I think dplyr imports the pipe from magrittr which has no imports. Maybe we should look into using that instead.

(Someone else also should weigh in here: this is outside my personal experience)

from rcompadre.

tdjames1 avatar tdjames1 commented on August 11, 2024

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 subsetDB() and modify its metadata, in order to then subset on the new column).

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 subsetDB able to do those calculations on the fly? I've no idea how this but I'm thinking something like:

subsetDB(check_NA(matA) == FALSE)

from rcompadre.

iainmstott avatar iainmstott commented on August 11, 2024

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:

compadre_s4_use <- compadre_s4 %>% 
  cleanDB()
  subsetDB(compadre_S4_use, check_NA_A == FALSE & check_ergodic == TRUE)

I guess it's not working in the pipe sequence because the variables check_NA_A and check_ergodic aren't saved in the object yet (they normally would be after a call to cleanDB().

from rcompadre.

iainmstott avatar iainmstott commented on August 11, 2024

@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 CompadreData object, adding to the metadata

from rcompadre.

patrickbarks avatar patrickbarks commented on August 11, 2024

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 db@metadata based on some transformation of the original db@metadata and/or db@mat. It's the latter part that I think would be tricky to code (i.e. allowing the user to specify how the new column is derived, and specifically, allowing the transformation to be a function of db@metadata and/or db@mat).

In any case, the proposal in #27 would make this unnecessary because with the flat structure of the proposed data slot, a user could literally just use dplyr::mutate.

from rcompadre.

tdjames1 avatar tdjames1 commented on August 11, 2024

Stepping back a bit, I wonder if there is any mileage in thinking about implementing a method that allows user to mutate metadata with reference to the CompadreM object, e.g.

mutateDB(compadre_obj, <new_col> = <function of CompadreM>)

The user-specified function would be applied to the mat slot and the (required to be data frame friendly) output appended to metadata as a new column. There could be optional args to indicate a particular CompadreM slot(s) to be used as args to the function to make it easy to use with predefined functions that take a single matrix argument (e.g. popbio::lambda). The function would return the modified CompadreData object which you could then use in pipes with subsetDB etc.

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.

from rcompadre.

patrickbarks avatar patrickbarks commented on August 11, 2024

closed by #32 and #48

from rcompadre.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.