From: Gabor Grothendieck <ggrothendieck_at_myway.com>

Date: Tue 22 Mar 2005 - 14:57:28 EST

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Mar 22 15:04:31 2005

Date: Tue 22 Mar 2005 - 14:57:28 EST

Michael S <michael_shen <at> hotmail.com> writes:

*:
*

: dear ALL-R-helper:

*: I modify my question in "textconnection output":
**: I wrote one function in Rgui:
**: output <- function(y){
**: x <- textConnection("foo","w")
**: sink(x)
**: a <-5
**: b <-6
**: z <-a*b
**: z
**: e <-"spss"
**: h <-c(1,2,3)
**: ls()
**: r<-c("s","p","s","s")
**: p<-list(1:10)
**: p
**: y <- foo
**: sink()
**: close(x)
**: return(y)
**: }
**:
**: I want to get resulte is :
**: >y
**:
**: [1] "[1] 30"
**: [2] " [1] \"a\" \"b\" \"c\" \"d\" \"e\" \"f\"
**: \"foo\" \"g\" \"g.p\" \"h\" \"interp\" \"m\"
**: \"mytest\""
**: [3] "[14] \"output\" \"p\" \"r\" \"var1\" \"var2\" \"x\"
**: \"y\" \"z\" "
**: [4] "[[1]]"
**: [5] " [1] 1 2 3 4 5 6 7 8 9 10"
**: [6] ""
**:
**: when I copy the command line within the function ,and paste to RGui,result
**: is ok .but when I use the output function ,">y" show value of y object.I got
**: result "character(0)"
**:
**: seem to me : I didn't get value of y within function
*

You have not defined foo within your function. If you have a foo outside your function then that is being assigned to y. If you haven't a foo anywhere then you should have received an error.

You might want to look at ?capture.output

y <- capture.output({

x <- 1

print(x)

})

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Mar 22 15:04:31 2005

*
This archive was generated by hypermail 2.1.8
: Fri 03 Mar 2006 - 03:30:52 EST
*