[TxMt] New R bundles available
Hans-Joerg Bibiko
bibiko at eva.mpg.de
Tue Mar 18 11:18:11 UTC 2008
On 17 Mar 2008, at 20:30, Sean Anderson wrote:
> On Mon, Mar 17 Mar 2008, at 16:33, Hans-Joerg Bibiko wrote:
>> Now you can select the function declaration and send it to the
>> Rdaemon, switch to the Rdaemon doc, and you can use that function
>> (the Rdaemon console is not "messed up", error messages could be
>> seen
>> with opt+apple+A 2).
>> ...
>>
> Ah, I see. Interesting approach. I do like that in some circumstances.
>
> Other times, however, it is nice to get some immediate feedback on
> errors and/or R output when sending selections of text to Rdaemon. I
> guess the disadvantage is that you can't have multiple console windows
> open without consequences. (Although I've never found myself doing
> that.)
Ok. I see your point here. But I'm not yet convinced ;)
Please remember, the console window (Rdaemon) is not a usual console
known from R.app or R in the Terminal. It is still an editor window!
If I have to develop, let's say, a new function, I also can do this
within the Rdaemon console window.
Example (a Rdaemon console window):
...
> myfun <- function(x,y=3) {
foo <- x * y
print(Foo
}
and I press shift+RETURN
I'll get this:
...
> myfun <- function(x,y=3) {
+ foo <- x * y
+ print(Foo
+ }
Error: unexpected '}' in:
"print(Foo
}"
>
Now I see I've forgot ")". I simply press apple+Z for undo (the
window is an editor!) and I'll get:
...
> myfun <- function(x,y=3) {
foo <- x * y
print(Foo
}
I correct this.
...
> myfun <- function(x,y=3) {
foo <- x * y
print(Foo)
}
and press shift+RETURN
Everything seems to be fine.
Then I try it out and I'll get:
> myfun(2)
Error in print(Foo) : object "Foo" not found
>
Oops, a typo. Now I set my caret to the line:
+ print(Foo)
and I correct it to
+ print(foo)
Finally I select
> myfun <- function(x,y=3) {
+ foo <- x * y
+ print(foo)
+ }
and press shift+ENTER to execute only the selection (not shift+RETURN
which jumps to the end of doc and executes the last command(s) [after
the last prompt "> "])
I go to the line:
> myfun(2)
and I press RETURN and I see my entire coding like that:
> myfun <- function(x,y=3) {
+ foo <- x * y
+ print(foo)
+ }
> myfun(2)
[1] 6
>
Error in print(Foo) : object "Foo" not found
>
see a screencast http://www.bibiko.de/TM_R_ex01.mov
[BTW I'm just gathering some screencasts/documents to illustrate some
workflows. Afterwards I'll put them on my server]
Within the Rdaemon console window you can navigate through the entire
console window as usual. Go lines up to edit a command and execute it
again. You can write an article in between the R prompts "> " like
Good morning,
this is an example
> 2+4
[1] 6
>
Now I want to show you what happens if ...
> plot(1:10)
>
Ah, a plot appears.
etc. p.p.
What kind of workaround do you have regarding to writing something in
a R window and send it (not quietly) to the Rdaemon?
> Might be nice to simply have two bundle commands: one to send silently
> and one to update the console and output the result.
>
> This new behaviour reminds me of the Emacs + ESS command 'evaluate
> this line/region' without switching focus. On that note, as an
> alternative, would it be possible to have a selection sent to the
> console, the output displayed, and the focus shifted back (or always
> staying on) the R source code window? I would find that quite useful.
In principal one can do it. I also find a way to append R's output
not to the file console.Rcon but to the current content of
console.Rcon by using AppleScript :)
To keep the focus on the R window, could be a bit tricky, but I have
something in my mind ;)
But, then we would have these different commands:
-send to Rdaemon
-send to Rdaemon quietly
-send to Rdaemon quietly without switching focus
...
(?)
Kind regards,
--Hans
BTW I'm got used to Rdaemon in such a way that I have some problems
to switch to R.app ;)
More information about the textmate
mailing list