Skip to content
Prev 12058 / 21307 Next

[Bioc-devel] R6 class v.s. S4 class

Thank you all for the feedback. Just to give some extra context, here we have the Python and Javascript versions of the biothings_client:


https://github.com/biothings/biothings_client.py


https://github.com/biothings/biothings_client.js


And here is the work-in-progress R client:


https://github.com/biothings/biothings_client.R



You can find some examples from the README and the test code to see how the client works in Python and Javascript.


One of the nice features of both Python and JS clients is it allows users to use the same client instance for any new "BioThings" API in the future, which can be created by another user, not just from us. In this case, one can do this to work with a new API in python client:


from biothings_client import get_client

mything_client = get_client("mything", url="http://example.com/v1/api")   # could have some extra parameters

mything_client.query(...)

mything_client.get_mything(...)

...


As the developer of all these three biothings_clients, we, of course, like to keep the same pattern for R, and R6 looks the closest to me. But it looks like, from R users' perspective, this is not a popular pattern to use.  With your suggestion, I think it can work this way in R:


library(biothings)

gene_client = BioThingsClient('gene')     # a gene client with a preset config

queryBioThings(gene_client, "CDK2")    # whether we should keep client as the first argv, that's still TBD, based on the previous pipe comment


mything_client = BioThingsClient('mything', url= "http://example.com/v1/api")

queryBioThings(mything_client, "something')



Another thing I should mention, in Python client, each client has these methods:


gene_client.getgene

gene_client.getgenes

gene_client.query

gene_client.querymany

gene_client.metdata


Then in R, we will have to create these generic methods (hope this is the right term):


getBioThing(mything_client, ...)

getBioThings

queryBioThings

queryManyBioThings

BioThingsMetadata


I personally still like the Python/JS pattern, as you can have client specific name like "getgene", "getgenes", instead of the generic getBioThing and getBioThings name. Plus that users can just call "gene_client" part as "gc" or whatever, it just has much less to type :-) in the code. In R S4 case, the function name has to be more verbose because they are global.


Does this sound good to the group? Any more suggestions?


Chunlei
Message-ID: <CY4PR11MB140024D01364DA902208C86CB9430@CY4PR11MB1400.namprd11.prod.outlook.com>
In-Reply-To: <CAOQ5Nydoscms07DNaWU1AB2Vf_3Mr1sEYJwVVwMaOjNFcJr4Eg@mail.gmail.com>