Connections

This illustrates variable number of arguments, deparse, substitute, pipe, url, switch, dump

Mail Function

toJan <- function(..., where = "stat") {
    objs <- nameargs(...)
    email <- switch(where, stat = "deleeuw@stat.ucla.edu", fraz = "deleeuw@frazmtm.com", 
        apple = "jdeleeuw@me.com", cuddy = "deleeuw@cuddyvalley.org", ucla = "deleeuw@ucla.edu")
    smoke <- pipe(paste("mail -s 'Voila some objects' ", email), "w")
    dump(objs, smoke)
    close(smoke)
}

Utility

Taken from Venables and Ripley, p. 46

nameargs <- function(...) {
    dots <- as.list(substitute(list(...)))[-1]
    nm <- names(dots)
    fixup <- if (is.null(nm)) 
        seq(along = dots) else nm == ""
    dep <- sapply(dots[fixup], function(x) deparse(x)[1])
    if (is.null(nm)) 
        return(dep) else {
        nm[fixup] <- dep
        return(nm)
    }
}

Sending Mail

a <- matrix(1:20, 4, 5)
b <- list(letters[1:5])
toJan(a, b, eigen, where = "apple")
toJan(a, b, eigen, where = "stat")

Writing and Reading a URL

makePage <- function(x) {
    nm <- paste("file:///Users/deleeuw/Desktop/", deparse(substitute(x)), ".html", 
        sep = "")
    cn <- url(nm, open = "w")
    cat("<html>", file = cn)
    cat("I am open", as.character(isOpen(cn)), "<br>", file = cn)
    cat("This is one line <hr>", file = cn)
    cat("This is another line <br>", file = cn)
    cat("</html>", file = cn)
    close(cn)
    browseURL(nm)
    cn <- url(nm, open = "r")
    print(readLines(cn, -1, warn = FALSE))
    close(cn)
}
makePage(foo)
## [1] "<html>I am open TRUE <br>This is one line <hr>This is another line <br></html>"