Print an S-PLUS object on a printer.

DESCRIPTION:
Sends an S-PLUS object to a hardcopy printer.

USAGE:
lpr(x, command="lpr", width=80, length=66, wait=F, rm.file=T,
    ...)

REQUIRED ARGUMENTS:
x:
any object.

OPTIONAL ARGUMENTS:
command:
character string naming a UNIX executable print command which will print an ASCII file. This will be system-dependent. See the examples.
width:
integer specifying the page width, in characters, that print should use in formatting x. This will correspond to the width of the printed page in the font used, unless command adds indentation.
length:
integer specifying the page length, in lines, that print should use in formatting x. This will correspond to the length of the printed page in the font used, unless command adds a header or trailer.
wait:
logical flag: if TRUE, lpr will wait for command to return.
rm.file:
logical flag: if TRUE, the temporary file will be removed after command returns. This is independent of wait. It would make sense to specify rm.file=FALSE only if command removes the file.
...:
additional arguments, which will be passed to the appropriate print method for x.

VALUE:
x is invisibly returned.

SIDE EFFECTS:
x is spooled for printing.

DETAILS:
This function will write x on a temporary file with the S-PLUS function print. It then gives the name of this file to command. Since the UNIX command to print an ASCII file is system dependent, it will typically be necessary to pass the lpr function a value of command other than the default. The same is true of arguments width and length, as the font sizes will depend on your installation.

A convenient way to customize lpr is to write a wrapper function for it. Ask your local S-PLUS administrator, or see the examples.


WARNING:
This function uses sink, so it will wipe out any sink in effect.

RESTRICTIONS:
The length argument will have no effect on the formatting of matrices when file descriptor 1 of the S-PLUS process is not a terminal. This will be the case, for example, when the standard output was redirected to a file or pipe at startup. Under these circumstances, matrices are always formatted for an infinitely long page.

SEE ALSO:
print , printgraph , sink .

EXAMPLES:
  lpr(my.function, command="lpr -Pfred")
    # Assumes the UNIX lpr command accepts ASCII files.
    # Will send to printer "fred".
# The next examples assume that the printer understands only PostScript,
# and that the UNIX command to print an ASCII file is enscript,
# available as part of the Transcript software from Adobe Systems.
  lpr(x, command="enscript -B",  width=90, length=64)
        # assumes default font size is 10 point
  lpr(x, command="grace enscript -B <", width=90, length=64)
        # if enscript is installed only on remote host "grace"
  lpr(x, command="enscript -r -B", width=125, length=49)
        # landscape (horizontal) orientation
# The following is an example of a wrapper function for lpr using
# enscript.
  lpr.enscript <-
function(x, header = NULL, landscape = F, columns = 1,
        font = if(columns == 2) "Courier7" else "Courier10", width,
        length, ...)
{
# front-end to S-PLUS lpr function, for Adobe's enscript program.
# 'width' and 'length' in this function refer to the printed page,
# and include the header. Default values will not be correct for other
# font sizes.
        if(missing(width))
                width <- if(columns == 2)
                                ifelse(landscape, 89, 66)
                        else if(columns == 1)
                                ifelse(landscape, 125, 90)
                        else
                                stop("columns must be 1 or 2")
        if(missing(length))
                length <- if(columns == 2)
                                ifelse(landscape, 67, 90)
                         else
                                ifelse(landscape, 49, 66)
        if(is.null(header))
                header <- paste(deparse(substitute(x)), "   ", date())
        header <- paste(sep = "", "'-b\"", header, "\"'")
        orient <- if(landscape) "-r" else ""
        col.flag <- paste("-", columns, sep = "")
        font <- paste("-f", font, sep = "")
        command <- paste("enscript -q", header, orient, col.flag, font,
                "<")
        invisible(lpr(x, command = command, width = width - 2,
                length = length - 2, ...))
}