On 22/09/2009 8:19 PM, Rolf Turner wrote:
On 23/09/2009, at 12:14 PM, Henrique Dallazuanna wrote:
Try this:
treeName <- "PINE"
write.table(d, file = sprintf("C:/%sheight.txt", treeName))
Why not use the (less esoteric) paste() function?
The printf() family of functions are one of the good things of the C
language. I'm with Henrique here, it makes the code easier to read than
the error-prone paste().
There's one bad thing in C: the lack of type checking, so that you can
use formats that make no sense given the args. The R implementation (by
Brian Ripley) adds type checking, so for example you would get a "too
few arguments" error if you tried
sprintf("C:/%sheight.txt")
(Well, maybe the strange syntax of the formats in C isn't perfect, but
it's still easier to read than
paste("C:/", treeName, "height.txt")
and the error in the above is pretty hard to spot.)
Duncan Murdoch
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.