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!)


The proto package is used like this:

# 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!


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



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


  • minor changes to satisfy R 2.6.0


  • 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


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


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


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


  • bug fix (recursion bug)

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


  • .Rd file improvements


  • 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 control argument to dot.proto


  • 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

Reference manual

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


1.0.0 by Hadley Wickham, 5 years ago

Report a bug at

Browse source code at

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

Documentation:   PDF Manual  

GPL-2 license

Suggests testthat, covr

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

Depended on by SparseFactorAnalysis, gsubfn, nls2, prioritizr, sqldf.

Suggested by HistData, otvPlots, trackr, usmap.

See at CRAN