0

I'm working on an R package to represent data stored in a file. I'm new to this type of coding as most of my R has been one-off scripts or some quick visualization. My background is more in heavy Object Oriented languages so while my examples reflect that I want to implement this in a way where "real" R programmers would see it and go "Oh, that makes sense."

I'd like to do something like the following pseudo-R:

o <- LoadMyFile("blah.data")

and then Access member elements in it:

file.version <- o.MajorVersion
some.data.series <- o.Experiments[42].RawValues

# Then I could plot some.data.series or do whatever I want

How would this work in R? I could imagine some kind of object being returned from LoadMyFile() and then other functions that operate on it:

o <- mylib.LoadMyFile("blah.data")
file.version <- mylib.MajorVersion(o)
some.data.series <- mylib.GetDataSeries(o, 42)
Cœur
  • 37,241
  • 25
  • 195
  • 267
Dave
  • 1,567
  • 4
  • 13
  • 23
  • As you've noticed, S3 classes are pretty lightweight and [not real OO](http://stackoverflow.com/a/9522858/636656). Coming from an OO background, you may like S4 objects better, although they have their own set of problems. – Ari B. Friedman Nov 25 '13 at 19:28
  • 1
    I'd just store extra info in the attributes of whatever object contains your data. – eddi Nov 25 '13 at 19:39
  • @AriB.Friedman Thanks for the link. I noticed there were several ways to do OO-type stuff and I had assumed that meant it wasn't the "real" way. I'll look into S3 or S4 and see how they shape up. Thanks! – Dave Nov 25 '13 at 19:52
  • 2
    @Dave I would include the more recent `?ReferenceClasses` in your list of things to investigate. – joran Nov 25 '13 at 19:56
  • Info on ReferenceClasses: http://stackoverflow.com/a/5137568/636656 – Ari B. Friedman Nov 26 '13 at 15:42
  • These comments have been very helpful and ReferenceClasses look like what I'm after (although I'm having issues using .self$private_field to get semi-private members). There's no "Answer" so I can't select one. if @joran or AriB.Friedman want to put one up, I'll mark it. – Dave Nov 27 '13 at 13:10

0 Answers0