This function works like reticulate::PyClass()
, but the defs
argument
can now be provided as individual arguments (...
) instead of a list.
Details
The original reticulate::PyClass()
does not allow disabling the automatic
conversion of Python objects to R. This function modifies its function body
to enable that functionality.
Examples
if (FALSE) { # \dontrun{
Employee <- py_class("Employee",
`__init__` = function(self, name, id) {
self$name <- name
self$id <- id
return(invisible(NULL))
},
get_email = function(self) {
paste0(self$name, "_", self$id, "@company.com")
})
Mike <- Employee("Mike", "1234")
Mike$get_email()
Mike$get_email() |> class()
} # }