[Rd] R Console Bug?

Morgan Morgan morg@n@em@||box @end|ng |rom gm@||@com
Sat Apr 17 09:26:54 CEST 2021


Hi Simon,
Thank you for the feedback.
It is really strange that you have a different output.
I have attached a picture of my R console.
I am just trying to port some pure C code that prints progress bars to R
but it does not seem to be printing properly.
It seems I am doing something wrong with REprintf and R_FlushConsole.
Best regards,
Morgan

On Sat, Apr 17, 2021 at 12:36 AM Simon Urbanek <simon.urbanek using r-project.org>
wrote:

> Sorry, unable to reproduce on macOS, in R console:
>
> > dyn.load("test.so")
> > .Call("printtest",1e4L)
>
>    Processing data chunk 1 of 3
>  [==============================] 100%
>
>    Processing data chunk 2 of 3
>  [==============================] 100%
>
>    Processing data chunk 3 of 3
>  [==============================] 100%
> NULL
>
> But honestly I'm not sure sure I understand the report. R_FlushConsole is
> a no-op for terminal console and your code just prints on stderr anyway
> (which is not buffered). All this does is just a lot of \r output (which is
> highly inefficient anywhere but in Terminal by definition). Can you clarify
> what the code tries to trigger?
>
> Cheers,
> Simon
>
>
> > On Apr 16, 2021, at 23:11, Morgan Morgan <morgan.emailbox using gmail.com>
> wrote:
> >
> > Hi,
> >
> > I am getting a really weird behaviour with the R console.
> > Here is the code to reproduce it.
> >
> > 1/ C code: ---------------------------------------------------
> >
> > SEXP printtest(SEXP x) {
> >  const int PBWIDTH = 30, loop = INTEGER(x)[0];
> >  int val, lpad;
> >  double perc;
> >  char PBSTR[PBWIDTH], PBOUT[PBWIDTH];
> >  memset(PBSTR,'=', sizeof(PBSTR));
> >  memset(PBOUT,'-', sizeof(PBOUT));
> >  for (int k = 0; k < 3; ++k) {
> >    REprintf("\n   Processing data chunk %d of 3\n",k+1);
> >    for (int i = 0; i < loop; ++i) {
> >      perc = (double) i/(loop-1);
> >      val  = (int) (perc * 100);
> >      lpad = (int) (perc * PBWIDTH);
> >      REprintf("\r [%.*s%.*s] %3d%%", lpad, PBSTR, PBWIDTH - lpad, PBOUT,
> > val);
> >      R_FlushConsole();
> >    }
> >    REprintf("\n");
> >  }
> >  return R_NilValue;
> > }
> >
> > 2/ Build so/dll: ---------------------------------------------------
> >
> > R CMD SHLIB
> >
> > 3/ Run code :  ---------------------------------------------------
> >
> > dyn.load("test.so")
> > .Call("printtest",1e4L)
> > dyn.unload("test.so")
> >
> > 4/ Issue:  ---------------------------------------------------
> > If you run the above code in RStudio, it works well both on Mac and
> Windows.
> > If you run it in Windows cmd, it is slow.
> > If you run it in Windows RGui, it is slow but also all texts are flushed.
> > If you run it in Mac terminal, it runs perfectly.
> > If you run it in Mac R Console, it prints something like :
> >> .Call("printtest",1e4L)
> > [==============================] 100%NULL----------------------------]
>  0%
> >
> > I am using R 4.0.4 (Mac) / 4.0.5 (Windows)
> >
> > Is that a bug or am I doing something wrong?
> >
> > Thank you
> > Best regards,
> > Morgan
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-devel using r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot 2021-04-17.png
Type: image/png
Size: 73830 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20210417/8b230984/attachment.png>


More information about the R-devel mailing list