knitr::opts_knit$set(root.dir = rprojroot::find_rstudio_root_file()) # Set WD to Root
here::i_am("dev/r6-play.Rmd")
library(here)
library(R6)

May be too complicated

Extract <- R6Class("Extract", list(
  digits = function(x) stringr::str_extract(x, "[:digit:]+"),
  chars = function(x) stringr::str_extract(x, "[:alpha:]+")
))

extractor <- Extract$new()
extractor
Extract <- R6Class("Extract", cloneable = FALSE,
  private = list(
    str_extract = function(x, regex) stringr::str_extract(x, regex)
  ),
  public = list(
    digits = function(x) private$str_extract(x, "[:digit:]+"),
    chars = function(x) private$str_extract(x, "[:alpha:]+")
  )
)
extractor <- Extract$new()
class(extractor)
sloop::otype(extractor)
# Can't access private field
# extractor$str_extract("a2", "[:alpha:]+")
extractor$chars("a1")
extractor$digits("b1")
extractor$digits()

extractor[["digits"]]("b1")
test_regex <- list(digits = "[:digit:]+",
                   chars = "[:alpha:]+")
Extract <- R6Class("Extract", cloneable = FALSE,
  private = list(
    str_extract = function(x, regex) stringr::str_extract(x, regex)
  ),
  public = list(
    digits = function(x) private$str_extract(x, "[:digit:]+"),
    chars = function(x) private$str_extract(x, "[:alpha:]+")
  )
)
extractor <- Extract$new()


Lightbridge-KS/labChartHRV documentation built on June 12, 2022, 3:21 p.m.