Media-class function

Media

Media

The Media object represents a value identified by a URI. There is a Media subclass for each media type, such as text/csv or application/xml . Coercion methods (see setAs) define mappings between Media subclasses and objects. The user does not usually need to access this functionality directly. class

Type conversion

Each Media subclass may be converted to/from one or more

types. The mappings are established by setAs.

The following bi-directional mappings are built into the package:

application/xml , text/htmlXMLAbstractNode
application/jsonlist
text/csvdata.frame
text/*character

But call mediaCoercionTable to see what is defined in the current session.

The as function is the canonical interface to converting media to objects. It (usefully) requires that the user specify the target type. For convenience, the mediaTarget generic returns the default R type for a given Media object.

To support a new media type, one should define a Media subclass with the same name as the media type (application/xml), a corresponding mediaTarget method, and all relevant coerce methods. See the Media class hierarchy to determine where the new type fits.

Helpers

  • mediaCoercionTable(): Returns a character matrix with columns from and to , indicating the available coercions of media types to/from objects.

Examples

txt <- '{"json":{"rocks":true}}' json <- as(txt, "application/json") as(json, mediaTarget(json))

Author(s)

Michael Lawrence

  • Maintainer: Michael Lawrence
  • License: Artistic-2.0
  • Last published: 2022-06-16

Useful links