Anthony Ching Ho Ng
2011-Jul-31 11:15 UTC
[R] Display/show the evaluation result of R commands automatically
Hello R-help, I wonder if it is possible to configure R, so that it will display/show the evaluation result of the R commands automatically (similar to the behavior of Matlab) i.e. If I type x <- 8 it will print 8 in the command prompt, instead of having type x explicitly to show the result and perhaps put an ";" at the end to suppress the output. i.e. x <- 8; Thank you Anthony
Barry Rowlingson
2011-Jul-31 12:16 UTC
[R] Display/show the evaluation result of R commands automatically
> h <- taskCallbackManager() > h$add(function(expr, value, ok, visible) {if(!visible){print(value)};TRUE})On Sun, Jul 31, 2011 at 12:15 PM, Anthony Ching Ho Ng <anthony.ch.ng at gmail.com> wrote:> Hello R-help, > > I wonder if it is possible to configure R, so that it will > display/show the evaluation result of the R commands automatically > (similar to the behavior of Matlab) > > i.e. If I type x <- 8 > > it will print 8 in the command prompt, instead of having type x > explicitly to show the result and perhaps put an ";" at the end to > suppress the output. > > i.e. x <- 8; >The first thing I think you can do by adding a task callback manager to print the value if the value would otherwise be invisible: > h <- taskCallbackManager() > h$add(function(expr, value, ok, visible) {if(!visible){print(value)};TRUE}) The semicolon thing would probably need rewriting bits of R at the C code level. I don't think many people would use it though. And my code above might break things. I don't use it. Barry
Duncan Murdoch
2011-Jul-31 23:36 UTC
[R] Display/show the evaluation result of R commands automatically
On 11-07-31 7:15 AM, Anthony Ching Ho Ng wrote:> Hello R-help, > > I wonder if it is possible to configure R, so that it will > display/show the evaluation result of the R commands automatically > (similar to the behavior of Matlab)It's open source so in theory anything is possible, but there's no built-in support for that.> i.e. If I type x<- 8 > > it will print 8 in the command prompt, instead of having type x > explicitly to show the result and perhaps put an ";" at the end to > suppress the output. > > i.e. x<- 8;If you wrap the assignment in parens the result is made visible, e.g. (x <- 8) will print if you enter it in the console. (It won't print if it's a line in a function; there you need an explicit call to print(). Only the value returned at the top level is eligible for auto-printing.) Duncan Murdoch
Gabor Grothendieck
2011-Jul-31 23:39 UTC
[R] Display/show the evaluation result of R commands automatically
On Sun, Jul 31, 2011 at 7:15 AM, Anthony Ching Ho Ng <anthony.ch.ng at gmail.com> wrote:> Hello R-help, > > I wonder if it is possible to configure R, so that it will > display/show the evaluation result of the R commands automatically > (similar to the behavior of Matlab) > > i.e. If I type x <- 8 > > it will print 8 in the command prompt, instead of having type x > explicitly to show the result and perhaps put an ";" at the end to > suppress the output. > > i.e. x <- 8; >Not quite the same but perhaps good enough is that at the console this will give you the last value: .Last.value -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com