Skip to content

Non-generic methods for S7 Objects  #436

@JosiahParry

Description

@JosiahParry

I am trying to work with S7 in an R package for the first time and am struggling a bit with reconciling S7 with other OOO approaches I've worked with.

Typically, I can define a class and their properties. Then for the class, I can define methods that can be called from the class. I would like to do this with S7 but from what I can tell, it is only possible to create generic methods for S7. And it is not possible to create methods for an S7 class.

What I have been toying with is setting a prop as class_function but this allows it to be any function. Not a specific function id like to associate with the class.

Is this possible today?

e.g. in rust i might write:

struct Person {
  name: String
  age: i32
}

impl Person {
  fn greet(self) { println!("Hello, I am {}!", self.name); }
}

in S7 the equivalent might be something like

new_class("person", properties = list(name = class_character, age = class_integer))

but i cannot understand how to create a greet() method

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions