[R] Display/show the evaluation result of R commands automatically
Anthony Ching Ho Ng
anthony.ch.ng at gmail.com
Tue Aug 2 16:42:08 CEST 2011
R-help and Barry
Thank you for your suggestions. It works, and may I ask how I am able
to do the opposite (disable the call back, so that I could control
when to show and suppress the output). I would like to make a function
to enable/disable the callback similar to the one as follow:
enableOutput <- function() {
h <<- taskCallbackManager()
h$add(function(expr, value, ok, visible)
{if(!visible){print(value)};TRUE})
}
disableOutput <- function() {
........
}
This shows output feature (and use '';" to suppress the output) is the
default behavior of Matlab which I find it quite useful (without
having to type in the variable name again every time to see the result
of the expression). So I am just curious to know how to do it in R.
Best Regards,
Anthony
On 31 July 2011 20:16, Barry Rowlingson <b.rowlingson at lancaster.ac.uk> wrote:
>> 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
>
More information about the R-help
mailing list