pizzarr icon indicating copy to clipboard operation
pizzarr copied to clipboard

S3/S4-based wrappers around R6 classes for more R-like API

Open keller-mark opened this issue 2 years ago • 5 comments

From discussions with @pieterjanvc the non-R6 API would be much more natural for the R ecosystem

  • https://github.com/r-lib/R6/issues/42
  • https://adv-r.hadley.nz/oo-tradeoffs.html
  • http://adv-r.had.co.nz/S3.html (Best Practices section)
  • https://rconsortium.github.io/OOP-WG/

keller-mark avatar Aug 22 '23 12:08 keller-mark

+1 to this

Consider the RNetCDF API pattern where you pass an open object to a function that works with it.

e.g. open.nc() returns an nc object and you pass that object to functions like att.get() or var.put() etc.

dblodgett-usgs avatar Aug 22 '23 14:08 dblodgett-usgs

@keller-mark -- here's what I've got cooking.

https://code.usgs.gov/wma/nhgf/geo-data-portal/rnz/-/tree/develop

The README there shows the basics of what it does so far.

I am going to get a copy of that repository public at: https://github.com/DOI-USGS/rnz and will do the rest of the development on a dirty main branch but there's a bit more paperwork to get cleared before it's done.

dblodgett-usgs avatar May 17 '24 12:05 dblodgett-usgs

I implemented:

#' Returns results of listing the store
#' 
#' @param x a pizzar Store object 
#' @export
names.Store <- function(x) {
  x$listdir()
}

And a side affect that is kind of unfortunate is:

> class(store)
[1] "DirectoryStore" "Store"          "R6"  

image

Not sure what the UX of working with these classes really should be, but I'm not sure that R6 and S3 should really coexist based on this?

dblodgett-usgs avatar May 18 '24 03:05 dblodgett-usgs

might be some relevance in the new S7 on your questions here (if you haven't seen that): https://blog.r-project.org/2024/05/17/generalizing-support-for-functional-oop-in-r/index.html

mdsumner avatar May 28 '24 22:05 mdsumner

I need to sit quietly with some examples of how to implement subsetting and assignment. @keller-mark -- do you feel like the implementations of bracket methods in zarr-array.R are the way they should be or were those just a starting point?

dblodgett-usgs avatar Jun 05 '24 23:06 dblodgett-usgs