ripley at stats.ox.ac.uk
2007-Dec-29 12:20 UTC
[Rd] (PR#10534 capture.output(), truncated last output without
This only happens if 'file' is a text connection, and is the expected behaviour in that case: you cannot capture an incomplete line to a text connection. There seems no reason to break the documented behaviour in other cases to change something that you consider to a bug when file=NULL and the user does not produce complete output. It would be possible to make use of isIncomplete() to add a final newline only where needed to complete a line. E.g. use if(inherits(file, "textConnection") && isIncomplete(file)) cat("\n") On Sat, 29 Dec 2007, phgrosjean at sciviews.org wrote:> Full_Name: Philippe Grosjean > Version: 2.6.1 > OS: MacOS X; Windows XP > Submission from: (NULL) (81.243.237.235) > > > Last output from capture.output() is truncated if it does not end with a > carriage return: > >> capture.output(cat("text\n")) # Fine > [1] "text" >> capture.output(cat("text")) # Missing output! > character(0) >> capture.output({cat("text");1+1}) # Only last output is affected > [1] "text[1] 2" > > Proposed patch: add a carriage return before exiting capture.output(): > > capture.output <- > function (..., file = NULL, append = FALSE) { > > > [...] > > for (item in tmp) if (item$visible) > print(item$value) > } > cat("\n") ### ADD THIS! > rval > } > > This changes the behavior of capture.output() a little bit, since it adds "" at > the end of regular outputs, but it solves the problem and it allows to detect if > last output line was ended by \n, or not. > > Regards, > > Philippe Grosjean > _ > platform i386-apple-darwin8.10.1 > arch i386 > os darwin8.10.1 > system i386, darwin8.10.1 > status > major 2 > minor 6.1 > year 2007 > month 11 > day 26 > svn rev 43537 > language R > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- 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
maechler at stat.math.ethz.ch
2007-Dec-29 13:10 UTC
[Rd] (PR#10534 capture.output(), truncated last output without
>>>>> "BDR" == Brian Ripley <ripley at stats.ox.ac.uk> >>>>> on Sat, 29 Dec 2007 13:20:14 +0100 (CET) writes:BDR> This only happens if 'file' is a text connection, and BDR> is the expected behaviour in that case: you cannot BDR> capture an incomplete line to a text connection. BDR> There seems no reason to break the documented behaviour BDR> in other cases to change something that you consider to BDR> a bug when file=NULL and the user does not produce BDR> complete output. It would be possible to make use of BDR> isIncomplete() to add a final newline only where needed BDR> to complete a line. E.g. use BDR> if(inherits(file, "textConnection") && isIncomplete(file)) cat("\n") I think that would be quite a nice improvement. Martin BDR> On Sat, 29 Dec 2007, phgrosjean at sciviews.org wrote: >> Full_Name: Philippe Grosjean Version: 2.6.1 OS: MacOS X; >> Windows XP Submission from: (NULL) (81.243.237.235) >> >> >> Last output from capture.output() is truncated if it does >> not end with a carriage return: >> >>> capture.output(cat("text\n")) # Fine >> [1] "text" >>> capture.output(cat("text")) # Missing output! >> character(0) >>> capture.output({cat("text");1+1}) # Only last output is >>> affected >> [1] "text[1] 2" >> >> Proposed patch: add a carriage return before exiting >> capture.output(): >> >> capture.output <- function (..., file = NULL, append >> FALSE) { >> >> >> [...] >> >> for (item in tmp) if (item$visible) print(item$value) } >> cat("\n") ### ADD THIS! rval } >> >> This changes the behavior of capture.output() a little >> bit, since it adds "" at the end of regular outputs, but >> it solves the problem and it allows to detect if last >> output line was ended by \n, or not. >> >> Regards, >> >> Philippe Grosjean _ platform i386-apple-darwin8.10.1 arch >> i386 os darwin8.10.1 system i386, darwin8.10.1 status >> major 2 minor 6.1 year 2007 month 11 day 26 svn rev 43537 >> language R >> >> ______________________________________________ >> R-devel at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel >> -- Brian D. Ripley, ripley at stats.ox.ac.uk BDR> Professor of Applied Statistics, BDR> http://www.stats.ox.ac.uk/~ripley/ University of BDR> Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, BDR> +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 BDR> 272595 BDR> ______________________________________________ BDR> R-devel at r-project.org mailing list BDR> https://stat.ethz.ch/mailman/listinfo/r-devel
ripley at stats.ox.ac.uk
2007-Dec-29 13:25 UTC
[Rd] (PR#10534 capture.output(), truncated last output without
On Sat, 29 Dec 2007, Martin Maechler wrote:>>>>>> "BDR" == Brian Ripley <ripley at stats.ox.ac.uk> >>>>>> on Sat, 29 Dec 2007 13:20:14 +0100 (CET) writes: > > BDR> This only happens if 'file' is a text connection, and > BDR> is the expected behaviour in that case: you cannot > BDR> capture an incomplete line to a text connection. > > BDR> There seems no reason to break the documented behaviour > BDR> in other cases to change something that you consider to > BDR> a bug when file=NULL and the user does not produce > BDR> complete output. It would be possible to make use of > BDR> isIncomplete() to add a final newline only where needed > BDR> to complete a line. E.g. use > > BDR> if(inherits(file, "textConnection") && isIncomplete(file)) cat("\n") > > I think that would be quite a nice improvement.Yes, I'd like to achieve the effect, but I think there is a better way to do it. The nub of the problem is that close() is done in the on.exit action after the return value is set, so the internal logic needs changing. Brian> Martin > > BDR> On Sat, 29 Dec 2007, phgrosjean at sciviews.org wrote: > > >> Full_Name: Philippe Grosjean Version: 2.6.1 OS: MacOS X; > >> Windows XP Submission from: (NULL) (81.243.237.235) > >> > >> > >> Last output from capture.output() is truncated if it does > >> not end with a carriage return: > >> > >>> capture.output(cat("text\n")) # Fine > >> [1] "text" > >>> capture.output(cat("text")) # Missing output! > >> character(0) > >>> capture.output({cat("text");1+1}) # Only last output is > >>> affected > >> [1] "text[1] 2" > >> > >> Proposed patch: add a carriage return before exiting > >> capture.output(): > >> > >> capture.output <- function (..., file = NULL, append > >> FALSE) { > >> > >> > >> [...] > >> > >> for (item in tmp) if (item$visible) print(item$value) } > >> cat("\n") ### ADD THIS! rval } > >> > >> This changes the behavior of capture.output() a little > >> bit, since it adds "" at the end of regular outputs, but > >> it solves the problem and it allows to detect if last > >> output line was ended by \n, or not. > >> > >> Regards, > >> > >> Philippe Grosjean _ platform i386-apple-darwin8.10.1 arch > >> i386 os darwin8.10.1 system i386, darwin8.10.1 status > >> major 2 minor 6.1 year 2007 month 11 day 26 svn rev 43537 > >> language R > >> > >> ______________________________________________ > >> R-devel at r-project.org mailing list > >> https://stat.ethz.ch/mailman/listinfo/r-devel > >> > >-- 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