progress
                                
                                 progress copied to clipboard
                                
                                    progress copied to clipboard
                            
                            
                            
                        cpp version won't work on windows
Hi, thanks for the useful package and it works fine on my mac for both the R version and Cpp version. However, the cpp version of progress bar fails to display on windows. Here's a minimal repro (using the code from your test package):
library(Rcpp)
sourceCpp(code = '
#include <Rcpp.h>
#include <RProgress.h>
#include <unistd.h>
// [[Rcpp::depends("progress")]]
// [[Rcpp::export]]
Rcpp::CharacterVector test_progress(Rcpp::CharacterVector formatSEXP =
"[:bar] :percent ") {
BEGIN_RCPP
const char *format = formatSEXP[0];
RProgress::RProgress pb(format);
pb.tick(0);
for (int i = 0; i < 100; i++) {
usleep(2.0 / 100 * 1000000);
pb.tick();
}
Rcpp::CharacterVector result(1);
result[0] = "DONE";
return result;
END_RCPP
}'
)
test_progress()
my session info
> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_People's Republic of China.936 
[2] LC_CTYPE=Chinese (Simplified)_People's Republic of China.936   
[3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936
[4] LC_NUMERIC=C                                                   
[5] LC_TIME=Chinese (Simplified)_People's Republic of China.936    
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
other attached packages:
[1] Rcpp_0.12.13
loaded via a namespace (and not attached):
[1] compiler_3.4.1    magrittr_1.5      assertthat_0.2.0  R6_2.2.2          prettyunits_1.0.2 tools_3.4.1      
[7] yaml_2.1.14       progress_1.1.2 
Confirmed.
Should be fixed by b1efa6b9ec2ec26d4b2fd223d010081d9aa566b1
@gaborcsardi I have installed the dev version of this package but it doesn't display the progress bar using my example code above.
This works for me. What is your platform? Is this the latest progress version?
@gaborcsardi  Windows 7 X64.  The progress version is the latest on Github, installed via devtools::install_github('r-lib/progress') (I even checked the installed RProgress.h header file, it's the same as in Github). For details, please see the session info below.
> devtools::session_info()
─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                                              
 version  R version 3.4.4 (2018-03-15)                       
 os       Windows 7 x64 SP 1                                 
 system   x86_64, mingw32                                    
 ui       RStudio                                            
 language (EN)                                               
 collate  Chinese (Simplified)_People's Republic of China.936
 tz       Asia/Taipei                                        
 date     2018-04-25                                         
─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version     date       source                             
 ansistrings   1.0.0.9000  2018-04-13 Github (r-lib/ansistrings@4e4d309) 
 assertthat    0.2.0       2017-04-11 CRAN (R 3.4.4)                     
 backports     1.1.2       2017-12-13 CRAN (R 3.4.3)                     
 cli           1.0.0.9002  2018-04-13 Github (r-lib/cli@c408924)         
 clisymbols    1.2.0       2017-05-21 CRAN (R 3.4.1)                     
 crayon        1.3.4       2017-09-16 CRAN (R 3.4.1)                     
 DBI           0.8         2018-03-02 CRAN (R 3.4.4)                     
 desc          1.1.1       2017-08-03 CRAN (R 3.4.1)                     
 devtools      1.13.5.9000 2018-04-08 local                              
 digest        0.6.15      2018-01-28 CRAN (R 3.4.3)                     
 glue          1.2.0       2017-10-29 CRAN (R 3.4.2)                     
 hms           0.4.2       2018-03-10 CRAN (R 3.4.4)                     
 magrittr      1.5         2014-11-22 CRAN (R 3.4.4)                     
 memoise       1.1.0       2017-04-21 CRAN (R 3.4.0)                     
 pkgbuild      0.0.0.9000  2017-12-06 Github (r-lib/pkgbuild@ce7f6d1)    
 pkgconfig     2.0.1       2017-03-21 CRAN (R 3.4.4)                     
 pkgload       0.0.0.9000  2017-12-06 Github (r-lib/pkgload@70eaef8)     
 prettyunits   1.0.2       2015-07-13 CRAN (R 3.4.1)                     
 progress      1.2.0       2018-04-23 Github (r-lib/progress@a2678e8)    
 R6            2.2.2       2017-06-17 CRAN (R 3.4.1)                     
 Rcpp        * 0.12.16     2018-03-13 CRAN (R 3.4.4)                     
 rlang         0.2.0       2018-02-20 CRAN (R 3.4.3)                     
 rprojroot     1.3-2       2018-01-03 CRAN (R 3.4.3)                     
 rstudioapi    0.7.0-9000  2018-04-13 Github (rstudio/rstudioapi@e87b481)
 selectr       0.4-1       2018-04-06 CRAN (R 3.4.4)                     
 sessioninfo   1.0.1.9000  2017-12-06 Github (r-lib/sessioninfo@c871d01) 
 stringi       1.1.7       2018-03-12 CRAN (R 3.4.4)                     
 stringr       1.3.0       2018-02-19 CRAN (R 3.4.3)                     
 testthat      2.0.0       2017-12-13 CRAN (R 3.4.4)                     
 usethis     * 1.3.0       2018-02-24 CRAN (R 3.4.3)                     
 withr         2.1.2       2018-03-15 CRAN (R 3.4.4)                     
 xml2          1.2.0       2018-01-24 CRAN (R 3.4.3)                     
 yaml          2.1.18      2018-03-08 CRAN (R 3.4.4)  
@gaborcsardi I did a simple debug. all the three functions below always return 0.
https://github.com/r-lib/progress/blob/a2678e82445f24255f8570edbc7265aec47f6f6d/inst/include/RProgress.h#L278
Moreover, even I force the is_r_studio() to return true (I test this in the Rstudio IDE), the progress bar won't be print, either... I don't know why.
Thanks.
What's your rstudio version?
Version 1.1.423
What' more, I just confirmed that it won't work for the RGui either.
Yeah, looking at the code, RGui is expected I think. But RStudio should work. What is your RSTUDIO environment variable set to?
Sys.getenv("RSTUDIO")
It's "1". However, I tried in cpp using std::getenv("RSTUDIO") will get empty.
Example
Rcpp::cppFunction('void test() {
  char *v = std::getenv("RSTUDIO");                 
  Rcpp::Rcout << (v == 0);
}')
test()
# returns 1 meaning it's empty.  By contrast, if you change ”RSTUDIO" to "PATH", it returns 0.
Moreover,
I find if I change the % of the below line to anything else like abcd, it gets worked in the CMD console.
https://github.com/r-lib/progress/blob/a2678e82445f24255f8570edbc7265aec47f6f6d/inst/include/RProgress.h#L128

So,
- don't know why std::getenv("RSTUDIO")returns empty in the Rstudio IDE (even thoughSys.getenv("RSTUDIO")returns "1")...
- don't know why if a std::stringcontains%, theRprintf(str.c_str())will print nothing.
The example to my second point (change % to %% will solve the problem but I don't know why it's not needed on the OSX):
Rcpp::cppFunction('void test2() {
  std::string a = "abcd";                 
  std::string b = "efgh%";                 
  Rprintf(a.c_str());
  Rprintf(b.c_str());
}')
test2()
# abcdWarning message:
# In test2() : printing of extremely long output is truncated
Oh, yeah, there is a bug here. The  % is interpreted in Rprintf() or REprintf. I'll fix that.
But that's independent of the RSTUDIO env var being unset. That is just strange. It seems like a windows specific thing. Wow.
I'll think about how to detect RStudio from C++ code then....
Looks like a bunch of other env vars are there from C as well:
RSTUDIO_WINUTILS=C:/Program Files/RStudio/bin/winutils
RSTUDIO_PANDOC=C:/Program Files/RStudio/bin/pandoc
RMARKDOWN_MATHJAX_PATH=C:/Program Files/RStudio/resources/mathjax-26
RSTUDIO_MSYS_SSH=C:/Program Files/RStudio/bin/msys-ssh-1000-18
This might be an RStudio bug then?
Looks like that if you set  the variable  explicitly with Sys.setenv(RSTUDIO  = "1") then it will be there in C++ as well?
Yes, you are right. Calling Sys.setenv(RSTUDIO = "1") solves this. I don't really know why's that. Maybe a bug from the RStudio side?
Maybe, but I don't know how that would be even possible. It is R calling the external code via .Call, RStudio has nothing to do with it AFAICT. Anyway, I asked the RStudio IDE team, will let you know.
I'll fix the other bugs as well,  the % one, and the detection of RGui and R.app
Thanks! :smiley: