0

Here is the example from the help page again:

mEdit <- setRefClass("mEdit",
                     fields = list( data = "matrix",
                                    edits = "list")
                     )



mEdit$methods(
    initialize = function(data=matrix()) {
        .self$data = data
    }
    )

mv <- setRefClass("matrixViewer",
                  fields = c("viewerDevice", "viewerFile"),
                  contains = "mEdit",
                  )

mv$methods( initialize =
                function(file = "./matrixView.pdf", ...) {
                    viewerFile <<- file
                    pdf(viewerFile)
                    viewerDevice <<- dev.cur()
                    dev.set(dev.prev())
                    callSuper(...)
                },
            finalize = function() {
                dev.off(viewerDevice)
            })

There is no problem here, but if i put the mv class into a different file, say mv.R, then R complains:

Loading testRefClass
Error in getClass(what, where = where) (from mv.R#1) : “mEdit” is not a defined class
qed
  • 22,298
  • 21
  • 125
  • 196

1 Answers1

0

You have to inlucde the other file where mEdit is defined via source(), as mv depends on it. If you have a large project with a plenty of classes and files, think about developing a package, where the folder with your R-files is automatically loaded - and only those files, which have been changed since the last loading.

Patrick Roocks
  • 3,129
  • 3
  • 14
  • 28