Suppose I'm creating a package and I'd like to define a function that creates an object where the object is defined in another package.
get_empty_mtx <- function() return(new("dgCMatrix"))
You can use the
getClassDef function to get a class definition from a specific package and then call
new() on that. For example
new(getClassDef("dgCMatrix", "Matrix")) also seems to work despite the documtation saying
where should be an environment.