[Rd] R Console Bug?
Simon Urbanek
@|mon@urb@nek @end|ng |rom R-project@org
Sat Apr 17 01:36:09 CEST 2021
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
>
More information about the R-devel
mailing list