Skip to content
Back to skills

R6

ASecurity

R R6 package for OOP. Use for encapsulated object-oriented programming with reference semantics.

  • 5 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added June 4, 2026
data

Security analysis

A100/100

Scanned June 4, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill R6 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of R6?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for R6
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-r6/badge)](https://www.skillsdirectory.com/skills/leolin990405-r6)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: R6
description: R R6 package for OOP. Use for encapsulated object-oriented programming with reference semantics.
---

# R6 Package

Encapsulated OOP with reference semantics.

## Basic Class

```r
library(R6)

Person <- R6Class("Person",
  public = list(
    name = NULL,
    age = NULL,

    initialize = function(name, age = NA) {
      self$name <- name
      self$age <- age
    },

    greet = function() {
      cat("Hello, I'm", self$name, "\n")
    }
  )
)

# Create instance
p <- Person$new("Alice", 30)
p$greet()
```

## Private Members

```r
BankAccount <- R6Class("BankAccount",
  private = list(
    balance = 0
  ),

  public = list(
    deposit = function(amount) {
      private$balance <- private$balance + amount
      invisible(self)
    },

    withdraw = function(amount) {
      if (amount > private$balance) stop("Insufficient funds")
      private$balance <- private$balance - amount
      invisible(self)
    },

    get_balance = function() {
      private$balance
    }
  )
)
```

## Active Bindings

```r
Circle <- R6Class("Circle",
  private = list(
    .radius = 1
  ),

  active = list(
    radius = function(value) {
      if (missing(value)) return(private$.radius)
      private$.radius <- value
    },

    area = function() {
      pi * private$.radius^2
    }
  )
)

c <- Circle$new()
c$radius <- 5
c$area  # Computed property
```

## Inheritance

```r
Animal <- R6Class("Animal",
  public = list(
    name = NULL,
    initialize = function(name) self$name <- name,
    speak = function() cat("...\n")
  )
)

Dog <- R6Class("Dog",
  inherit = Animal,
  public = list(
    speak = function() cat("Woof!\n")
  )
)

d <- Dog$new("Rex")
d$speak()
```

## Method Chaining

```r
# Return invisible(self) for chaining
account$deposit(100)$withdraw(50)$get_balance()
```

## Clone

```r
p2 <- p$clone()
p2 <- p$clone(deep = TRUE)  # Deep copy
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in data →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.