From hadley at rice.edu  Mon May  2 16:40:28 2011
From: hadley at rice.edu (Hadley Wickham)
Date: Mon, 2 May 2011 09:40:28 -0500
Subject: [Rd] write.csv and match.call
Message-ID: <BANLkTikPN-vqbtTocJyqQzNCxcF=D3Kg9w@mail.gmail.com>

Hi all,

Can help me understand why write.csv manipulates a call object instead
of simply calling write.table with modified arguments? I would have
written write.csv as:

write.csv <- function (...) {
    Call <- match.call(expand.dots = TRUE)
    for (argname in c("append", "col.names", "sep", "dec", "qmethod")) {
      if (!is.null(Call[[argname]]))
        warning(gettextf("attempt to set '%s' ignored", argname),
            domain = NA)

    write.table(..., sep = ",", dec = ".", qmethod = "double")
}

The current approach breaks partial argument matching for row.names:

write.csv(mtcars, "mtcars-1.csv", row = F)
write.table(mtcars, "mtcars-2.txt", row = F)
write.csv(mtcars, "mtcars-2.csv", row.names = F)

What's the advantage of manipulating the call?

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



[Rd] write.csv and match.call
Hadley Wickham