Prototype Object-Based Programming

An object oriented system using object-based, also called prototype-based, rather than class-based object oriented ideas.


Travis-CI Build Status CRAN_Status_Badge Coverage Status

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.

Ease of use

The proto package is easy to use because:

  1. 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.

  2. documentation. A 15 page report, a reference card, a demo and help files are provided.

  3. 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.

  4. 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.)

  5. tested. The package has been independently tested by multiple people and has no known bugs. (If you find any please let the developers know!)

Example

The proto package is used like this:

library(proto)
 
# new object with variable a and method addtwice
oo <- proto(a = 1, addtwice = function(., x) .$a <- .$a + 2*x)
 
oo$addtwice(3)  # add twice 3 to 1
oo$ls()         # "a" "addtwice"
oo$a            # 7
 
# create child object overriding a
ooc <- oo$proto(a = 10)
 
ooc$addtwice(1) # inherit addtwice from parent oo
ooc$ls()        # "a"
ooc$a           # 12 - addtwice from oo used "a" in ooc!

Documentation

More information is available via:

demo(proto)           # a self running demo
 
vignette("proto")     # 15 page report
vignette("protoref")  # reference card
 
?proto                # constructs proto objects
?dot.proto            # visualize a proto project

News

VERSION 1.0.0

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

VERSION 0.3-9

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

VERSION 0.3-8

  • minor changes to satisfy R 2.6.0

VERSION 0.3-7

  • 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

VERSION 0.3-6

  • order of arguments in proto and as.proto.list changed to address a bug

VERSION 0.3-5

  • new arg funEnvir= on proto and as.proto.list [experimental]

  • new arg SELECT= on as.proto [experimental]

VERSION 0.3-4

  • new function graph.proto using Rgraphviz replaces dot.proto

  • updated vignettes

  • added proto-package.Rd (viewable via package?proto)

VERSION 0.3-3

  • updated NEWS, README, WISHLIST and moved to to inst directory

VERSION 0.3-2

  • bug fix (recursion bug)

  • documentation improvements (vignette, .Rd files, README)

VERSION 0.3-1

  • .Rd file improvements

VERSION 0.3-0

  • that/super changed to .that/.super.

  • .Name changed to ..Name in dot.proto

  • improvements to .Rd files and vignette

VERSION 0.2-6

  • 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

VERSION 0.2-5

  • vignette and reference card now pass R CMD check/build/install

  • CHANGES renamed to NEWS

VERSION 0.2-4

  • added control argument to dot.proto

VERSION 0.2-3

  • 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

VERSION 0.2-2

  • 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

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("proto")

1.0.0 by Hadley Wickham, 3 years ago


https://github.com/hadley/proto


Report a bug at https://github.com/hadley/proto/issues


Browse source code at https://github.com/cran/proto


Authors: Hadley Wickham [cre] , Gabor Grothendieck [aut] , Louis Kates [aut] , Thomas Petzoldt [aut]


Documentation:   PDF Manual  


GPL-2 license


Suggests testthat, covr


Imported by PTXQC, RDocumentation, analysisPipelines, emojifont, ggtern, oppr, synthpop.

Depended on by AtelieR, PKgraph, SparseFactorAnalysis, coprimary, gsubfn, nls2, prioritizr, sqldf, traitr.

Suggested by HistData, otvPlots, trackr, usmap.


See at CRAN