[R] R-Terminal
Martin Elff
elff at sowi.uni-mannheim.de
Wed Mar 5 13:37:26 CET 2008
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: elff at sowi.uni-mannheim.de
Web: http://webrum.uni-mannheim.de/sowi/elff/
http://www.sowi.uni-mannheim.de/lspwivs/
-------------------------------------------------
More information about the R-help
mailing list