[R] Printer

Ray Brownrigg Ray.Brownrigg at mcs.vuw.ac.nz
Tue Jul 3 23:08:53 CEST 2001


> I am an econometrics student using R. How do I print directly from R to
> a printer (not to the screen) :
> 
> 1) an object saved previously in the workspace
> 2) a graphic plot on the screen
> 
Try this.  If you give it an object name, it will print that object,
otherwise it will print the current plot (assuming a Postscript
printer):

lpr <-
function (object, file = "Rplotlpr.ps", ...) 
{
    if (missing(object)) {
        current.device <- dev.cur()
        dev.off(dev.copy(device = postscript, file = file, ...))
        dev.set(current.device)
        system(paste("lpr", file))
        print(paste(file, "printed."))
    }
    else {
        if (missing(file)) 
            file <- "Robjlpr.txt"
        sink(file)
        object <- as.character(substitute(object))
        print(get(object))
        sink()
        system(paste("lpr", file))
        print(paste(object, "printed."))
    }
}

Hope this helps,
Ray Brownrigg <ray at mcs.vuw.ac.nz>	http://www.mcs.vuw.ac.nz/~ray
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list