On Wednesday 05 March 2008 (12:56:17), Martin Kaffanke wrote:
> Thats really great, but now the sink() uses also this width.  Is it
> possible to make sink using another width (i.e. 80 characters)?

# auto width adjustment

.adjustWidth <- function(...){
       options(width=Sys.getenv("COLUMNS"))
       TRUE
}
 
.adjustWidthCallBack <- addTaskCallback(.adjustWidth)

# a wrapper for 'sink'

Sink <- function(...,width=80){
 if(nargs()){
         removeTaskCallback(.adjustWidthCallBack)
         rm(.adjustWidthCallBack,envir=globalenv())
         options(width=width)
         sink(...)
        }
 else{
    sink()
    assign(".adjustWidthCallBack",
        addTaskCallback(.adjustWidth),
        envir=globalenv()
        )
 }
}

# test
Sink("test.out",width=20) # nonsensically narrow, but shows that
                          # width=<something> has an effect...
iris[1:10,]
Sink()
as.matrix(readLines("test.out"))
iris[1:10,]


Best,
Martin


-------------------------------------------------
Dr. Martin Elff
Faculty of Social Sciences
LSPWIVS (van Deth)
University of Mannheim
A5, 6
68131 Mannheim
Germany

Phone: +49-621-181-2093
Fax: +49-621-181-2099
E-Mail: [EMAIL PROTECTED]
Web: http://webrum.uni-mannheim.de/sowi/elff/
     http://www.sowi.uni-mannheim.de/lspwivs/
-------------------------------------------------

______________________________________________
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.

Reply via email to