Create objects of class output.

as.output(x, ...)

Arguments

x

object to be converted to an instance of output.

...

optional arguments to be passed to implementing methods of as.output. Most methods support the following arguments: sep string, column/value separator, nsep string, key separator, keys either a logical (if FALSE names/row names are suppressed) or a character vector with overriding keys. The default for keys typically varies by class or is auto-detected (e.g., named vectors user names as keys, data.frames use row names if they are non-automatic etc.). All methods also support con argument which pushes the output into a connection instead of generating an output object - so as.output(x, con=...) is thus not a coersion but used only for its side-effect. Note that con also supports special values iotools.stdout, iotools.stderr and iotools.fd(fd) which write directly into the corresponding streams instead of using theconnection API.

Details

as.output is generic, and methods can be written to support new classes. The output is meant to be a raw vector suitable for writing to the disk or sending over a connection.

Value

if con is set to a connection then the result is NULL

and the method is used for its side-effect, otherwise the result is a raw vector.

Side note: we cannot create a formal type of output, because

writeBin does is.vector() check which doesn't dispatch and prevents anything with a class to be written.

Author

Simon Urbanek

Examples

  m = matrix(sample(letters), ncol=2)
  as.output(m)
#>  [1] 75 7c 63 0a 7a 7c 65 0a 78 7c 66 0a 6a 7c 6e 0a 72 7c 64 0a 79 7c 67 0a 76
#> [26] 7c 62 0a 6d 7c 68 0a 74 7c 73 0a 6f 7c 70 0a 77 7c 69 0a 6b 7c 71 0a 61 7c
#> [51] 6c 0a

  df = data.frame(a = sample(letters), b = runif(26), c = sample(state.abb,26))
  str(as.output(df))
#>  raw [1:596] 6b 7c 30 2e ...

  as.output(df, con=iotools.stdout)
#> NULL