Coder Social home page Coder Social logo

classr's Introduction

classr

Class instances for rapid prototyping.

Installation

require("devtools")
devtools::install_github("Rappster/classr")
require("classr")

Regular S3 instances

## Default instance "body" //
res <- createInstance("TestClass")
res

ls(res)
class(res)

## Explicit object as instance "body" //
res <- createInstance("TestClass", input = list(x = TRUE))
res 

## Strict //
try(createInstance("TestClass", strict = TRUE))

R6 instances

Default input

This is ideal for rapid prototyping. All list elements are mapped to publicly available fields.

inst <- createR6Instance(input = list(x = 1, y = 2))
inst
inst$x
inst$y

Special input format

For more fine control over the class structure.

input <- list(
  public = list(x = 10, foo = function() private$bar()),
  private = list(bar = function() "Hello World!"),
  active = list(
    x2 = function(value) {
      if (missing(value)) return(self$x * 2) else self$x <- value/2
    }
  )
)

## Step by step to see what's actually going on //
inst <- createR6Instance(input, lazy = TRUE)
inst
class(inst)
## --> call

inst <- eval(inst)
inst
class(inst)
ls(inst)
## --> object generator

inst <- inst$new()
inst
ls(inst)
## --> instance

inst$x
inst$foo
inst$foo()
inst$x2
inst$x2 <- 100
inst$x

Explicit name

createR6Instance(input, name = "TestClass")

Lazy evaluation

(inst <- createR6Instance(input, lazy = TRUE))
(inst <- eval(inst))
(inst <- inst$new())

Empty

createR6Instance()
createR6Instance(lazy = TRUE)

classr's People

Contributors

jankowtf avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.