Re: [R] Replacing tabs with appropriate number of spaces

2008-12-09 Thread Gabor Grothendieck
That's a clever use of gsubfn. Here is a very minor simplification using the same code but representing it in formula notation and sprintf: gsubfn('([^\t]+)\t', ~ sprintf("%s%*s", x, 8-nchar(x)%%8, " "), tmp) On Tue, Dec 9, 2008 at 12:51 PM, Greg Snow <[EMAIL PROTECTED]> wrote: > This is basica

Re: [R] Replacing tabs with appropriate number of spaces

2008-12-09 Thread Greg Snow
This is basically your approach, but automated a bit more than you describe: library(gsubfn) tmp <- strsplit('one\ttwo\nthree\tfour\n12345678\t910\na\tbc\tdef\tghi\n','\n')[[1]] tmp2 <- gsubfn('([^\t]+)\t', function(x) { ln <- nchar(x) nsp <- 8-(ln %% 8) sp <- paste( rep(' ', nsp), colla

Re: [R] Replacing tabs with appropriate number of spaces

2008-12-09 Thread hadley wickham
On Tue, Dec 9, 2008 at 10:39 AM, Dennis Fisher <[EMAIL PROTECTED]> wrote: > Colleagues, > > Platform: OS X (but issue applies to all platforms) > Version: 2.8.0 > > I have a mixture of text and data that I am outputting via R to a pdf > document (using a fixed-width font). The text contains tabs t