[Rd] R Console Bug?
Morgan Morgan
morg@n@em@||box @end|ng |rom gm@||@com
Fri Apr 16 13:11:39 CEST 2021
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]]
More information about the R-devel
mailing list