An object oriented system using object-based, also called prototype-based, rather than class-based object oriented ideas.
Proto is an R package that facilitates prototype programming, a type of object-oriented programming that does not use classes as an atomic concept (but is powerful enough to encompass them).
The package is lightweight providing a thin layer on top of R environments. Unlike other packages which grow over time proto has become smaller over time as it was successively polished to reduce it to its essentials. Despite its small size prototype-based systems can be more powerful than more complex class-based systems.
The proto package is easy to use because:
few names. There is only one new function name to learn among the core functions. The 'proto' function constructs new proto objects. Remaining core functions include various as.proto methods, assignment and retrieval via $ and is.proto.
documentation. A 15 page report, a reference card, a demo and help files are provided.
consistency. Proto objects form an subclass of the
environment class. They are and work like environments.
One can leverage everything one knows about environments
to use proto. The package is highly consistent with R and
works the way R works.
concise implementation. The source code, excluding dot.proto, is about one page of code making it possible to rapidly understand it in its entirety not only from the documentation but also by reading its source. (This should not be necessary but its there for those who wish.)
tested. The package has been independently tested by multiple people and has no known bugs. (If you find any please let the developers know!)
The proto package is used like this:
library(proto) # new object with variable a and method addtwiceoo <- proto(a = 1, addtwice = function(., x) .$a <- .$a + 2*x) oo$addtwice(3) # add twice 3 to 1oo$ls() # "a" "addtwice"oo$a # 7 # create child object overriding aooc <- oo$proto(a = 10) ooc$addtwice(1) # inherit addtwice from parent ooooc$ls() # "a"ooc$a # 12 - addtwice from oo used "a" in ooc!
More information is available via:
demo(proto) # a self running demo vignette("proto") # 15 page reportvignette("protoref") # reference card ?proto # constructs proto objects?dot.proto # visualize a proto project
You can override the default printing method by providing a proto_print
method in your object.
graph.proto()
has been removed since it relies on packages that are
no longer on CRAN. name.proto()
is no longer exported since it was
used primarily by graph.proto()
.
Hadley Wickham has taken over maintenance.
All outstanding R CMD check problems have been fixed.
New NAMESPACE file that ensures that proto works when not attached.
minor changes to satisfy subtitute/eval changes in R 2.13.0 (thanks to Luke Tierney)
x could previously not be the name of a proto object. Now fixed.
proto print methods could break str.proto. Now fixed.
FAQ added as Appendix A of vignette
str.proto added (modified code of Tom Short)
the class of p$fun is now "instantiatedProtoMethod" and print.instantiatedProtoMethod provided (modified code of Tom Short)
"$.proto" now has a third argument which, if present, is a list of arguments at which to evaluate the instantiated method. Intended for use within sapply/lapply/etc. See examples in ?proto .
modified DESCRIPTION to point to new home page
new arg funEnvir= on proto and as.proto.list [experimental]
new arg SELECT= on as.proto [experimental]
new function graph.proto using Rgraphviz replaces dot.proto
updated vignettes
added proto-package.Rd (viewable via package?proto)
bug fix (recursion bug)
documentation improvements (vignette, .Rd files, README)
that/super changed to .that/.super.
.Name changed to ..Name in dot.proto
improvements to .Rd files and vignette
demo index file fixed and demo renamed and enhanced
proto.bib updated
consistent use of obj$with(meth) in examples and demo where method not used in the context of a call
vignette and reference card now pass R CMD check/build/install
CHANGES renamed to NEWS
added reference card
modified demo, .Rd files and vignette to correspond to new interface
changed argument list for proto and eliminated delegate
created as.proto.list and eliminated copy.proto
fixed bug in proto. Parent was not always set correctly.
added ... argument to copy.proto
added the isnot.function support function for use with copy.proto
cleaned up $.proto code for handling .. names.
the on-the-fly wrapper function generated by obj$meth now has the current environment as its environment.
proto no longer coerces its parent to a proto object. See note at end of proto.Rd.
added .. name processing and updated .Rd file
dot.proto now accepts names with dots in them
added delegate and copy.proto commands and updated .Rd file
added .. name processing and updated .Rd file
dot.proto now accepts names with dots in them
added delegate and copy.proto commands and updated .Rd file