[R] Getting sink to work with "message" on R 2.11.0 - what didI miss?

Henrik Bengtsson hb at stat.berkeley.edu
Wed May 26 09:31:06 CEST 2010


On Wed, May 26, 2010 at 8:26 AM, Tal Galili <tal.galili at gmail.com> wrote:
> Hello Greg,
> Thank you for the coding.
>
> A few questions and remarks:
>
> 1) I have a feature request that I believe Faiz is interested in:
> He would like to have the formatting of tables/data.frames in the output to
> be prettier then the one extracted from the console output.  I wonder if
> that is (reasonably) possible.

This sounds very much like what is done when for instance exporting
LaTeX and HTML tables from standard R data frames etc, cf. the xtable
package an others.  If an R data object is of a certain (S3/S4) class,
then it is possible to write custom-made methods for exporting to
whatever format you'd like to.  For instance, for the data.frame class
you can imagine to generate a text-to-speech (TTS) friendly data
structure:

df <- data.frame(rank=1:25, symbol=letters[1:25]);
tts(head(df));

where tts() et al. is defined as:

library("R.methodsS3");

setMethodS3("tts", "default", function(x, ...) {
  as.TTS(x);
})

setMethodS3("as.TTS", "data.frame", function(df, ...) {
  # Translate the data frame to a TTS object
  # [work here]
  class(res) <- c("TTS", class(res));
  # Return object
  res;
})

setMethodS3("play", "TTS", function(x, ...) {
  # Send to voice generator (explicitly or implicitly)
  # [work here]
})

setMethodS3("print", "TTS", function(x, ...) {
  # When displaying a TTS object, the default can either
  # be to display it on the screen or to play it.
  play(x, ...);
})

Thus, doing tts(head(df)) at the command line, will be equivalent to:

play(as.TTS(head(df)));

Then you can define as.TTS() for other data types and result classes.

It also smells a lot like XML here; I'm sure there are various schema
out there for different accessibility use cases.

>
> 2) I don't know if you had seen, but I already wrote a code to do such a
> thing here:
> http://www.r-statistics.com/2010/05/helping-the-blind-use-r-by-exporting-r-console-to-word/
> And would like to include your instructions in the post as well.
> Is there any other features or advantage of the new code, that should be
> included when writing about it ?
>
> 3) In a more general note -
> I think the challenges of the blind using R are interesting to look into.  a
> good example would be to ask if there are ways of making R output more
> easily readable for text to speech softwares.
> For example, imagine how a summary.lm output looks like.  Now imagine how a
> text-to-speech would read it.  Might there be a way to take such output and
> rearranging it in such a way so to allow the blind to easily listen to the
> results ?

I just like to say that as a package developer, I follow these
discussions on accessibility.  Although immediate support may be
limited, it is valuable that these kind of needs, use cases and
feature requests are shared.  Hopefully it will guide some of us to
pick the correct of two other equal design options when writing code.
It also push for more well-defined data structures.

My $0.02

/Henrik

>
>
> Best regards,
> Tal
>
>
>
>
>
> ----------------Contact
> Details:-------------------------------------------------------
> Contact me: Tal.Galili at gmail.com |  972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
> ----------------------------------------------------------------------------------------------
>
>
>
>
> On Tue, May 25, 2010 at 10:23 PM, Greg Snow <Greg.Snow at imail.org> wrote:
>
>> OK, I have uploaded a few new functions to the TeachingDemos package on
>> R-forge (it will be a while before the CRAN version is updated, but you can
>> install directly from R-forge once the changes show up there).
>>
>> The main functions to use (after loading TeachingDemos) are wdtxtStart and
>> wdtxtStop (these depend on the R2wd package, so make sure that it is
>> installed as well).
>>
>> You just need to make sure that either you do not have any word documents
>> open, or your currently open word document is blank or the one that you want
>> your R transcript inserted into, then just issue the wdtxtStart() command.
>> From that point on, all your commands and results from R will be inserted
>> into the word document as you go, so you can switch to word any time and
>> review the commands and results.  Just be sure to scroll down to the bottom
>> of the document before going back to R as the new commands and output will
>> be inserted wherever the cursor was when you went back to R (possibly in the
>> middle of something else if you are not careful).
>>
>> I hope this helps and let me know if you have any problems with it, or if
>> there are additional bells and whistles that would improve the functions (I
>> do have plans to eventually add some color coding, but doubt that that would
>> be important for the use discussed in this thread).
>>
>> --
>> Gregory (Greg) L. Snow Ph.D.
>> Statistical Data Center
>> Intermountain Healthcare
>> greg.snow at imail.org
>> 801.408.8111
>>
>>
>> > -----Original Message-----
>> > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
>> > project.org] On Behalf Of Faiz Rasool
>> > Sent: Saturday, May 22, 2010 2:39 AM
>> > To: R-help at r-project.org
>> > Subject: Re: [R] Getting sink to work with "message" on R 2.11.0 - what
>> > didI miss?
>> >
>> > Thank you to all of those who are trying to help me.
>> >
>> > I am using Windows XP, and using a screen reader called JAWS. When I
>> > type
>> > something at the console, I hear once what I have typed, and then the
>> > focus
>> > is on the next line. Then if I press the up arrow key I get to hear the
>> > function I just typed, not its output. For example if I type mean(x)
>> > and
>> > then I press enter I will hear "[5]" if it is the mean of x. Then I
>> > will
>> > hear ">". Now if I want to find out what was the mean of x by pressing
>> > the
>> > up arrow key, I will only hear mean(x) and I will not hear [5]. My
>> > screen
>> > reader does provide options to use different cursors to read command
>> > lines.
>> > but if I have typed median(x) sd(x) var(x) length(x) after typing
>> > mean(x),
>> > it takes a long time before I can move my cursor to the location where
>> > I can
>> > hear the mean of x. If the results of the commands can be diverted to
>> > MS
>> > Word it becomes comparatively easy for me to quickly move forward and
>> > backward in the document. Following suggestion of Gregory Snow, I will
>> > look
>> > at emacs. I could not find the txtStart function and TeachingDemos
>> > package
>> > after typing TxtStart() and library(TeachingDemos) I am unable to
>> > decide how
>> > to use the code provided by David Winsemius. Should I just copy that to
>> > console and it will start to divert the output to a txt or a .doc file?
>> >
>> > Thank you once again to all of those who have participated in this
>> > thread.
>> > Faiz.
>> >
>> >  ----- Original Message -----
>> > From: "David Winsemius" <dwinsemius at comcast.net>
>> > To: "Greg Snow" <Greg.Snow at imail.org>
>> > Cc: <r-help at r-project.org>
>> > Sent: Saturday, May 22, 2010 2:46 AM
>> > Subject: Re: [R] Getting sink to work with "message" on R 2.11.0 - what
>> > didI
>> > miss?
>> >
>> >
>> > >
>> > > On May 21, 2010, at 5:34 PM, Greg Snow wrote:
>> > >
>> > >> Look at txtStart and friends in the TeachingDemos package as an
>> > >> alternative to sink that includes commands as well as output.
>> > >
>> > > Know the quality of Greg Snows work it will probably be better than
>> > mine,
>> > > but perhaps:
>> > >
>> > > > capfn <- function(inp) {
>> > > +          instring <- deparse(substitute(inp))
>> > > +          capture.output(instring, inp, file="all.Rout") }
>> > > > capfn(1+3)
>> > >
>> > > The file looks like this:
>> > >
>> > > [1] "1 + 3"
>> > > [1] 4
>> > >>
>> > >> --
>> > >> Gregory (Greg) L. Snow Ph.D.
>> > >> Statistical Data Center
>> > >> Intermountain Healthcare
>> > >> greg.snow at imail.org
>> > >> 801.408.8111
>> > >>
>> > >>
>> > >>> -----Original Message-----
>> > >>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
>> > >>> project.org] On Behalf Of Tal Galili
>> > >>> Sent: Friday, May 21, 2010 3:21 PM
>> > >>> To: David Winsemius
>> > >>> Cc: r-help at r-project.org
>> > >>> Subject: Re: [R] Getting sink to work with "message" on R 2.11.0 -
>> > what
>> > >>> did I miss?
>> > >>>
>> > >>> Hi David,
>> > >>>
>> > >>> I want to get both the 4 and the "1+3" that created it.
>> > >>>
>> > >>> I am trying to help someone else on the mailing list that is
>> > looking
>> > >>> for a
>> > >>> way to "sink" the console into word, so he could have word read it
>> > to
>> > >>> him
>> > >>> (he is blind).
>> > >>> I know how to do the second part, but the first part (using sink
>> > with
>> > >>> the
>> > >>> commands, and not just the output), I am somehow missing...
>> > >>>
>> > >>> Best,
>> > >>> Tal
>> > >>>
>> > >>>
>> > >>>
>> > >>> ----------------Contact
>> > >>> Details:-------------------------------------------------------
>> > >>> Contact me: Tal.Galili at gmail.com |  972-52-7275845
>> > >>> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il
>> > (Hebrew)
>> > >>> |
>> > >>> www.r-statistics.com (English)
>> > >>> -------------------------------------------------------------------
>> > ----
>> > >>> -----------------------
>> > >>>
>> > >>>
>> > >>>
>> > >>>
>> > >>> On Sat, May 22, 2010 at 12:17 AM, David Winsemius
>> > >>> <dwinsemius at comcast.net>wrote:
>> > >>>
>> > >>>>
>> > >>>> On May 21, 2010, at 5:02 PM, Tal Galili wrote:
>> > >>>>
>> > >>>> Hi all,
>> > >>>>>
>> > >>>>> I am trying to use type message with sink, like this:
>> > >>>>>
>> > >>>>> sink("all.Rout", type="message")
>> > >>>>> 1+3
>> > >>>>>
>> > >>>>> sink()
>> > >>>>>
>> > >>>>> readLines(con = "all.Rout")
>> > >>>>>
>> > >>>>> So to get the following output:
>> > >>>>>
>> > >>>>> 1+3
>> > >>>>>>
>> > >>>>> [1] 4
>> > >>>>>
>> > >>>>> Obviously this doesn't work.
>> > >>>>>
>> > >>>>>
>> > >>>> What are you trying to do? The sink help page has two rather dire
>> > >>> warnings
>> > >>>> about not using type="message",  and using type="output would give
>> > >>> you what
>> > >>>> you ask:
>> > >>>>
>> > >>>>> sink("all.Rout", type="output")
>> > >>>>
>> > >>>>> 1+3
>> > >>>>>
>> > >>>>> sink()
>> > >>>>>
>> > >>>>> readLines(con = "all.Rout")
>> > >>>> [1] "[1] 4"
>> > >>>>
>> > >>>> The extra "[1]" and quotes are from the readLines function, not
>> > from
>> > >>>> all.Rout.
>> > >>>>
>> > >>>>
>> > >>>> I tried some variations (based on the explanations in the help)
>> > but
>> > >>> am
>> > >>>>> missing something on how to make it work.
>> > >>>>>
>> > >>>>> Any suggestions?
>> > >>>>>
>> > >>>>> (p.s: I need this so to help Faiz Rasool in his latest post)
>> > >>>>>
>> > >>>>> Thanks,
>> > >>>>>
>> > >>>>> Tal
>> > >>>>>
>> > >>>> --
>> > >>>> David Winsemius, MD
>> > >>>> West Hartford, CT
>> > >>>>
>> > >>>>
>> > >>>
>> > >>> [[alternative HTML version deleted]]
>> > >>>
>> > >>> ______________________________________________
>> > >>> 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.
>> > >
>> > > David Winsemius, MD
>> > > West Hartford, CT
>> > >
>> > > ______________________________________________
>> > > 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.
>> >
>> > ----- Original Message -----
>> > From: "David Winsemius" <dwinsemius at comcast.net>
>> > To: "Greg Snow" <Greg.Snow at imail.org>
>> > Cc: <r-help at r-project.org>
>> > Sent: Saturday, May 22, 2010 2:46 AM
>> > Subject: Re: [R] Getting sink to work with "message" on R 2.11.0 - what
>> > didI
>> > miss?
>> >
>> >
>> > >
>> > > On May 21, 2010, at 5:34 PM, Greg Snow wrote:
>> > >
>> > >> Look at txtStart and friends in the TeachingDemos package as an
>> > >> alternative to sink that includes commands as well as output.
>> > >
>> > > Know the quality of Greg Snows work it will probably be better than
>> > mine,
>> > > but perhaps:
>> > >
>> > > > capfn <- function(inp) {
>> > > +          instring <- deparse(substitute(inp))
>> > > +          capture.output(instring, inp, file="all.Rout") }
>> > > > capfn(1+3)
>> > >
>> > > The file looks like this:
>> > >
>> > > [1] "1 + 3"
>> > > [1] 4
>> > >>
>> > >> --
>> > >> Gregory (Greg) L. Snow Ph.D.
>> > >> Statistical Data Center
>> > >> Intermountain Healthcare
>> > >> greg.snow at imail.org
>> > >> 801.408.8111
>> > >>
>> > >>
>> > >>> -----Original Message-----
>> > >>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
>> > >>> project.org] On Behalf Of Tal Galili
>> > >>> Sent: Friday, May 21, 2010 3:21 PM
>> > >>> To: David Winsemius
>> > >>> Cc: r-help at r-project.org
>> > >>> Subject: Re: [R] Getting sink to work with "message" on R 2.11.0 -
>> > what
>> > >>> did I miss?
>> > >>>
>> > >>> Hi David,
>> > >>>
>> > >>> I want to get both the 4 and the "1+3" that created it.
>> > >>>
>> > >>> I am trying to help someone else on the mailing list that is
>> > looking
>> > >>> for a
>> > >>> way to "sink" the console into word, so he could have word read it
>> > to
>> > >>> him
>> > >>> (he is blind).
>> > >>> I know how to do the second part, but the first part (using sink
>> > with
>> > >>> the
>> > >>> commands, and not just the output), I am somehow missing...
>> > >>>
>> > >>> Best,
>> > >>> Tal
>> > >>>
>> > >>>
>> > >>>
>> > >>> ----------------Contact
>> > >>> Details:-------------------------------------------------------
>> > >>> Contact me: Tal.Galili at gmail.com |  972-52-7275845
>> > >>> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il
>> > (Hebrew)
>> > >>> |
>> > >>> www.r-statistics.com (English)
>> > >>> -------------------------------------------------------------------
>> > ----
>> > >>> -----------------------
>> > >>>
>> > >>>
>> > >>>
>> > >>>
>> > >>> On Sat, May 22, 2010 at 12:17 AM, David Winsemius
>> > >>> <dwinsemius at comcast.net>wrote:
>> > >>>
>> > >>>>
>> > >>>> On May 21, 2010, at 5:02 PM, Tal Galili wrote:
>> > >>>>
>> > >>>> Hi all,
>> > >>>>>
>> > >>>>> I am trying to use type message with sink, like this:
>> > >>>>>
>> > >>>>> sink("all.Rout", type="message")
>> > >>>>> 1+3
>> > >>>>>
>> > >>>>> sink()
>> > >>>>>
>> > >>>>> readLines(con = "all.Rout")
>> > >>>>>
>> > >>>>> So to get the following output:
>> > >>>>>
>> > >>>>> 1+3
>> > >>>>>>
>> > >>>>> [1] 4
>> > >>>>>
>> > >>>>> Obviously this doesn't work.
>> > >>>>>
>> > >>>>>
>> > >>>> What are you trying to do? The sink help page has two rather dire
>> > >>> warnings
>> > >>>> about not using type="message",  and using type="output would give
>> > >>> you what
>> > >>>> you ask:
>> > >>>>
>> > >>>>> sink("all.Rout", type="output")
>> > >>>>
>> > >>>>> 1+3
>> > >>>>>
>> > >>>>> sink()
>> > >>>>>
>> > >>>>> readLines(con = "all.Rout")
>> > >>>> [1] "[1] 4"
>> > >>>>
>> > >>>> The extra "[1]" and quotes are from the readLines function, not
>> > from
>> > >>>> all.Rout.
>> > >>>>
>> > >>>>
>> > >>>> I tried some variations (based on the explanations in the help)
>> > but
>> > >>> am
>> > >>>>> missing something on how to make it work.
>> > >>>>>
>> > >>>>> Any suggestions?
>> > >>>>>
>> > >>>>> (p.s: I need this so to help Faiz Rasool in his latest post)
>> > >>>>>
>> > >>>>> Thanks,
>> > >>>>>
>> > >>>>> Tal
>> > >>>>>
>> > >>>> --
>> > >>>> David Winsemius, MD
>> > >>>> West Hartford, CT
>> > >>>>
>> > >>>>
>> > >>>
>> > >>> [[alternative HTML version deleted]]
>> > >>>
>> > >>> ______________________________________________
>> > >>> 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.
>> > >
>> > > David Winsemius, MD
>> > > West Hartford, CT
>> > >
>> > > ______________________________________________
>> > > 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.
>> >
>> > ______________________________________________
>> > 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.
>>
>> ______________________________________________
>> 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.
>>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list