Re: [R] console from tcltk

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu, 15 May 2008 08:23:16 -0400

The "terminal" terminology seemed confusing at first but it appears to refer to launching R from a Windows cmd session and in that case, yes, it outputs to that Windows cmd session window (as opposed to the Rgui window) which seems sufficient.

I did find it acts strangely when used in conjunction with pipes. If we launch it like this then the 22 line is not filtered out which seems contrary to its being put on stdout:

C:\tmp2>"\Program Files\R\R-2.7.x\bin\Rgui.exe" | findstr 1 12
22
12

and if we launch it like this:

C:\tmp2>start "" "\Program Files\R\R-2.7.x\bin\Rgui.exe" | findstr 1

we are back to the error message:

> library(tcltk)

Loading Tcl/Tk interface ... done
> .Tcl("puts stdout 12")

Error in structure(.External("dotTcl", ..., PACKAGE = "tcltk"), class = "tclObj") :
  [tcl] can not find channel named "stdout".
> R.version.string

[1] "R version 2.7.0 Patched (2008-05-11 r45672)"

although without the "| findstr 1" the last case it no longer gives that error.

On Thu, May 15, 2008 at 1:21 AM, Prof Brian Ripley <ripley_at_stats.ox.ac.uk> wrote:
> On Wed, 14 May 2008, Gabor Grothendieck wrote:
>
>> Thanks. I've updated to the latest R on the mirror I used and
>> puts stdout 12
>> from tcl does indeed produce output from Rterm on Windows but gives an
>> error message from Rgui on Windows (both on Windows Vista SP1).
>
> Not if you launch Rgui from a terminal, as the quote I gave described.
>
>>
>> ----------------- this works
>>
>> C:\tmp2>Rterm
>>
>> R version 2.7.0 Patched (2008-05-11 r45672)
>> [...deleted...]
>>>
>>> library(tcltk)
>>
>> Loading Tcl/Tk interface ... done
>>>
>>> .Tcl("puts stdout 12")
>>
>> 12
>> <Tcl>
>>>
>>> xx <- .Tcl("puts stdout 12")
>>
>> 12
>>
>> -------------- this gives an error message
>>
>> C:\tmp2>Rgui
>>
>> R version 2.7.0 Patched (2008-05-11 r45672)
>> [...deleted...]
>>>
>>> library(tcltk)
>>
>> Loading Tcl/Tk interface ... done
>>>
>>> xx <- .Tcl("puts stdout 12")
>>
>> Error in structure(.External("dotTcl", ..., PACKAGE = "tcltk"), class
>> = "tclObj") :
>> [tcl] can not find channel named "stdout".
>>
>>
>> On Wed, May 14, 2008 at 11:09 AM, Prof Brian Ripley
>> <ripley_at_stats.ox.ac.uk> wrote:
>>>
>>> I assume by 'console' you mean the Rgui window. That is not where stdout
>>> is
>>> connected -- it is not a file. As the CHANGES file for 2.7.0 says
>>>
>>> o When Rgui is launched from a terminal, C output from ill-formed
>>> packages that write to stdout or stderr rather than use
>>> Rprintf will appear in the terminal rather than being lost.
>>> (Only on XP or later.) This can be very handy for debugging C
>>> code in packages: just write debugging messages to stdout.
>>>
>>> And indeed that is what your example does. It also writes to the
>>> terminal
>>> from Rterm.
>>>
>>> Tcl is no different from any other C-based add-on in this respect.
>>>
>>> Note though that system() does provide a way to capture stdout to the
>>> Rgui
>>> window, so you can probably run tcl scripts via the tcl shell and capture
>>> their output.
>>>
>>> On Tue, 13 May 2008, Gabor Grothendieck wrote:
>>>
>>>> Is it possible to use the console from within tcltk?
>>>>
>>>>> library(tcltk)
>>>>> tcl("puts", "stdout", "Hello, World")
>>>>
>>>> Error in structure(.External("dotTclObjv", objv, PACKAGE = "tcltk"),
>>>> class = "tclObj") :
>>>> [tcl] can not find channel named "stdout".
>>>>>
>>>>> .Tcl('puts stdout "Hello, World"')
>>>>
>>>> Error in structure(.External("dotTcl", ..., PACKAGE = "tcltk"), class
>>>> = "tclObj") :
>>>> [tcl] can not find channel named "stdout".
>>>>>
>>>>> R.version.string # Windows Vista
>>>>
>>>> [1] "R version 2.7.0 RC (2008-04-17 r45367)"
>>>
>>> Oh dear, not even the released version! Please update as the posting
>>> guide
>>> asked you to do before posting.
>>>
>>>> ______________________________________________
>>>> R-help_at_r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>
>>> --
>>> Brian D. Ripley, ripley_at_stats.ox.ac.uk
>>> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
>>> University of Oxford, Tel: +44 1865 272861 (self)
>>> 1 South Parks Road, +44 1865 272866 (PA)
>>> Oxford OX1 3TG, UK Fax: +44 1865 272595
>>>
>>
>> ______________________________________________
>> R-help_at_r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> --
> Brian D. Ripley, ripley_at_stats.ox.ac.uk
> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel: +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UK Fax: +44 1865 272595
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 15 May 2008 - 12:27:16 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 15 May 2008 - 12:30:43 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive