[R] R as a programming language

Duncan Murdoch murdoch at stats.uwo.ca
Thu Nov 8 20:38:33 CET 2007


On 11/8/2007 2:27 PM, Alberto Monteiro wrote:
> Duncan Murdoch wrote:
>>
>>> and there's always sprintf() for those moments when you
>>> want neat formatting.
>> 
>> That's good when you want good control over the formatting, but it 
>> doesn't tend to be all that readable, with the variables all listed 
>> at the end, instead of in between the bits of string.
>>
> As the old saying goes, you can eat the cake and have it:
> 
> x <- rnorm(1)
> cat("x is close to ", sprintf("%.1lf", x), " and closer to ",
>   sprintf("%.10lf", x), "\n", sep = "")
> 
> :-)

Yes, but that doesn't address my first objection to cat(), which you cut 
out:

>> Nothing wrong when using cat(), but we sometimes need to compute strings 
>> when we aren't using cat().


> 
> I am using R as a generic programming language for doing 
> jobs in Windows that I can't do using DOS batch - things 
> like taking a text in Latin-1 and removing the accented 
> characters, or looping through a directory and renaming 
> files with weird names, or creating a .wpl file with the mp3s.

I didn't claim that this would allow R to do something it can't do now, 
only that it wouldn't have to be so ugly when it did it.

Duncan Murdoch



More information about the R-help mailing list