as.response: Coerce Objects to Responses

Description Usage Arguments Details Examples

Description

The as.response functions simplify serving up R objects as server responses.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
as.response(x, ...)

## S3 method for class 'character'
as.response(x, directory = "views", collapse = "\n",
  ...)

## S3 method for class 'data.frame'
as.response(x, format = "json", ...)

## S3 method for class 'matrix'
as.response(x, ...)

is.response(x)

Arguments

x

Any R object.

directory

A character string specifying the system folder of the file x.

collapse

A character string specifying how to collapse the lines read from x.

format

A character string, determining the form of the HTTP response. Can be one of "csv", "html", "json", or "text".

...

Additional arguments passed on to methods.

Details

as.response.character expects x is a character string specifying a file name. The default directory for the file is "views", but a different path may be specified with the directory argument. If the file exists the contents are read and set as the response body. The response Content-Type is guessed from the file extension using guess_type.

as.response.data.frame coerces and serves up a data frame. Several response types are possible.

Examples

1
2
3

nteetor/prairie documentation built on May 24, 2019, 9:56 a.m.