Learn R Programming

restfulr (version 0.0.15)

Media-class: Media

Description

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 R objects. The user does not usually need to access this functionality directly.

Arguments

Type conversion

Each Media subclass may be converted to/from one or more R types. The mappings are established by setAs.

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

application/xml, text/html XMLAbstractNode
application/json list
text/csv data.frame

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

The as function is the canonical interface to converting media to R objects. It (usefully) requires that the user specify the target R 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 R objects.

Examples

Run this code
# NOT RUN {
txt <- '{"json":{"rocks":true}}'
json <- as(txt, "application/json")
as(json, mediaTarget(json))
# }

Run the code above in your browser using DataLab