makeGraphicsDeviceObject: Constructor for an RDevDescMethods object

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/gd.R

Description

This function acts as a constructor for an RDevDescMethods-class object which collects functions together that collectively implement an R graphics device. The resulting S4 object can then be passed to graphicsDevice to create an active graphics device on which we can draw R graphics.

This function takes the functions specified either individually as name = function (via ...) or as an existing list of named elements (via funcs). It then assigns these functions to the corresponding slots in the RDevDescMethods-class object. One can use the ... and the funcs parameters together and those functions specified in ... will be merged with those in funcs.

By default, the function creates and populates its own instance of the RDevDescMethods-class object that is returned. However, one can pass an already created object of class RDevDescMethods-class or a sub-class. This allows this function to be used for initializing sub-classes. The function is sufficiently general that it uses run-time slot access so it naturally handles sub-classes and indeed objects entirely different classes.

Usage

1
2
3
makeGraphicsDeviceObject(..., funcs = list(...),
                          obj = new("RDevDescMethods"),
                          ensureMetric = TRUE)

Arguments

...

a collection of name = function pairs specifying the functions to be inserted into the corresponding slot in obj. The slot names are matched using partial matching pmatch.

funcs

a named list of functions. This is an alternative to the ... specification that is convenient when the functions have already been collected into a list and it is akward to specify them via the ... parameter, e.g. via do.call.

obj

the object whose slots are to be populated by the functions specified via ... and funcs. This is typically an object of class RDevDescMethods-class or a sub-class.

ensureMetric

a logical value that controls whether we force the insertion of a default strWidth and metricInfo method that compute sensible values, if these are not specified by the user, i.e. if the default implementations are there from dummyDevice or NULL.

Value

obj with some of its slots updated.

Author(s)

Duncan Temple Lang

References

“The R Internals Manual”, R Development Core Team.

See Also

RDevDescMethods-class graphicsDevice

Examples

1
2
  o = makeGraphicsDeviceObject()
  o@strWidth = function(str, gcontext, dev) { nchar(str) * 12}

omegahat/RGraphicsDevice documentation built on Jan. 18, 2022, 4:37 a.m.