Error in sink(type = "output") : invalid connection

Hi,

Trying to run rstan, seems to install ok, but when I compiled a stan_demo, originally I had an issue with “C++14 standard requested but CXX14 is not defined”, and so I modified my makevars file as suggested here: C++14 standard requested but CXX14 is not defined

With that change now I have a different problem:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from C:/Program Files/R/R-3.6.0/library/BH/include/boost/random/detail/integer_log2.hpp:19:0,
                 from C:/Program Files/R/R-3.6.0/library/BH/include/boost/random/detail/int_float_pair.hpp:26,
                 from C:/Program Files/R/R-3.6.0/library/BH/include/boost/random/exponential_distribution.hpp:27,
                 from C:/Program Files/R/R-3.6.0/library/BH/include/boost/random/gamma_distribution.hpp:25,
                 from C:/Program Files/R/R-3.6.0/library/StanHeaders/include/stan/math/prim/mat/prob/dirichlet_rng.hpp:5,
                 from C:/Program Files/R/R-3.6.0/library/StanHeaders/include/stan/math/prim/mat.hpp:276,
                 from C:/Program Files/R/R-3.6.0/library/StanHeaders/include/stan/math/rev/mat.hpp:12,
                 from C:/Program Files/R/R-3.6.0/library/StanHeaders/include/stan/math.hpp:4,
                 from C:/Program Files/R/R-3.6.0/library/StanHeaders
Error in sink(type = "output") : invalid connection

I don’t know what that means at all, and I can’t seem to find any resources to help me fix this

Here’s some more info about my computer environment:

Windows 7 Enterprise
Stan Version 2.18.1

.R/Makevars.win
CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=native -mtune=native

CXX14 = g++ 
CXX14FLAGS = -O3

Session info

  • Session info ---------------------------------------------------------------------------------------------------------
    setting value
    version R version 3.6.0 (2019-04-26)
    os Windows 7 x64 SP 1
    system x86_64, mingw32
    ui RStudio
    language (EN)
    collate English_United States.1252
    ctype English_United States.1252
    tz America/Denver
    date 2019-05-21

  • Packages -------------------------------------------------------------------------------------------------------------
    package * version date lib source
    assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0)
    backports 1.1.4 2019-04-10 [1] CRAN (R 3.6.0)
    BH 1.69.0-1 2019-01-07 [1] CRAN (R 3.6.0)
    callr 3.2.0 2019-03-15 [1] CRAN (R 3.6.0)
    checkmate 1.9.3 2019-05-03 [1] CRAN (R 3.6.0)
    cli 1.1.0 2019-03-19 [1] CRAN (R 3.6.0)
    colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.0)
    crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0)
    desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.0)
    digest 0.6.18 2018-10-10 [1] CRAN (R 3.6.0)
    fansi 0.4.0 2018-10-05 [1] CRAN (R 3.6.0)
    ggplot2 * 3.1.1 2019-04-07 [1] CRAN (R 3.6.0)
    glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.0)
    gridExtra 2.3 2017-09-09 [1] CRAN (R 3.6.0)
    gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.0)
    inline 0.3.15 2018-05-18 [1] CRAN (R 3.6.0)
    labeling 0.3 2014-08-23 [1] CRAN (R 3.6.0)
    lattice 0.20-38 2018-11-04 [1] CRAN (R 3.6.0)
    lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.6.0)
    loo 2.1.0 2019-03-13 [1] CRAN (R 3.6.0)
    magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0)
    MASS 7.3-51.4 2019-03-31 [1] CRAN (R 3.6.0)
    Matrix 1.2-17 2019-03-22 [1] CRAN (R 3.6.0)
    matrixStats 0.54.0 2018-07-23 [1] CRAN (R 3.6.0)
    mgcv 1.8-28 2019-03-21 [1] CRAN (R 3.6.0)
    munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.0)
    nlme 3.1-139 2019-04-09 [1] CRAN (R 3.6.0)
    pillar 1.3.1 2018-12-15 [1] CRAN (R 3.6.0)
    pkgbuild 1.0.3 2019-03-20 [1] CRAN (R 3.6.0)
    pkgconfig 2.0.2 2018-08-16 [1] CRAN (R 3.6.0)
    plyr 1.8.4 2016-06-08 [1] CRAN (R 3.6.0)
    prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.6.0)
    processx 3.3.0 2019-03-10 [1] CRAN (R 3.6.0)
    ps 1.3.0 2018-12-21 [1] CRAN (R 3.6.0)
    R6 2.4.0 2019-02-14 [1] CRAN (R 3.6.0)
    RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 3.6.0)
    Rcpp 1.0.1 2019-03-17 [1] CRAN (R 3.6.0)
    RcppEigen 0.3.3.5.0 2018-11-24 [1] CRAN (R 3.6.0)
    reshape2 1.4.3 2017-12-11 [1] CRAN (R 3.6.0)
    rlang 0.3.4 2019-04-07 [1] CRAN (R 3.6.0)
    rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0)
    rstan * 2.18.2 2018-11-07 [1] CRAN (R 3.6.0)
    scales 1.0.0 2018-08-09 [1] CRAN (R 3.6.0)
    StanHeaders * 2.18.1 2019-01-28 [1] CRAN (R 3.6.0)
    stringi 1.4.3 2019-03-12 [1] CRAN (R 3.6.0)
    stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0)
    tibble 2.1.1 2019-03-16 [1] CRAN (R 3.6.0)
    utf8 1.1.4 2018-05-24 [1] CRAN (R 3.6.0)
    viridisLite 0.3.0 2018-02-01 [1] CRAN (R 3.6.0)
    withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0)

[1] C:/Program Files/R/R-3.6.0/library

Any help is appreciated!!!

What is the output of

library(rstan)
stancode <- 'data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}'
mod <- stan_model(model_code = stancode, verbose = TRUE)

particularly the line that has error: (with the colon) in it?

As I saw elsewhere, installing R in a directory with spaces can cause problems.

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from C:/Program Files/R/R-3.6.0/library/BH/include/boost/random/detail/integer_log2.hpp:19:0,
                 from C:/Program Files/R/R-3.6.0/library/BH/include/boost/random/detail/int_float_pair.hpp:26,
                 from C:/Program Files/R/R-3.6.0/library/BH/include/boost/random/exponential_distribution.hpp:27,
                 from C:/Program Files/R/R-3.6.0/library/BH/include/boost/random/gamma_distribution.hpp:25,
                 from C:/Program Files/R/R-3.6.0/library/StanHeaders/include/stan/math/prim/mat/prob/dirichlet_rng.hpp:5,
                 from C:/Program Files/R/R-3.6.0/library/StanHeaders/include/stan/math/prim/mat.hpp:276,
                 from C:/Program Files/R/R-3.6.0/library/StanHeaders/include/stan/math/rev/mat.hpp:12,
                 from C:/Program Files/R/R-3.6.0/library/StanHeaders/include/stan/math.hpp:4,
                 from C:/Program Files/R/R-3.6.0/library/StanHeaders

Unfortunately this produces the same problem when R is installed in a different folder:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from C:/R/R-3.6.0/library/BH/include/boost/random/detail/integer_log2.hpp:19:0,
                 from C:/R/R-3.6.0/library/BH/include/boost/random/detail/int_float_pair.hpp:26,
                 from C:/R/R-3.6.0/library/BH/include/boost/random/exponential_distribution.hpp:27,
                 from C:/R/R-3.6.0/library/BH/include/boost/random/gamma_distribution.hpp:25,
                 from C:/R/R-3.6.0/library/StanHeaders/include/stan/math/prim/mat/prob/dirichlet_rng.hpp:5,
                 from C:/R/R-3.6.0/library/StanHeaders/include/stan/math/prim/mat.hpp:276,
                 from C:/R/R-3.6.0/library/StanHeaders/include/stan/math/rev/mat.hpp:12,
                 from C:/R/R-3.6.0/library/StanHeaders/include/stan/math.hpp:4,
                 from C:/R/R-3.6.0/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from file3d54101e1493.cpp:8:
C:/R/R-3.6.0/library/BH/include/boos
Error in sink(type = "output") : invalid connection

I ran into the same error. Setting

CXX14=$(BINPREF)g++ -O2 -march=native -mtune=native

solved if for me.

1 Like

Amazing…it works now! Can you explain why it works now or what these settings do?

I’m having the same issue. Are you setting this in terminal?

1 Like

I’d also like to know. Someone does a similar step HERE but that’s for Windows. I’m a mac user and not sure where to out that.

Hi, you can try to reinstall Rstan. see this website for more information