I have looked a little into the inline
package and I believe I have found the problem. Thanks to @hpjfromdk for giving me the clues I needed.
In the inline
package, the function compileCode()
is sourced in the background and is called from the inline::cxxfunction()
that throws the same error as stan()
. In this function the system(R CMD SHLIB..)
command is called in the following way:
cmd <- paste(R.home(component="bin"), "/R CMD SHLIB ", basename(libCFile), " 2> ", errfile, sep="")
if (verbose) cat("Compilation argument:\n", cmd, "\n")
compiled <- system(cmd, intern=!verbose)
Apparently the " 2 > "
command is not understood by my computer and causes the system()
command to return character(0)
but without writing the error file (.err.txt
). The stan
and inline
errors come from the next line:
> errmsg <- readLines( errfile )
since no error-file is generated, this call returns:
> Error in file(con, "r") : cannot open the connection
> In addition: Warning message:
> In file(con, "r") :
> cannot open file 'file471012dc4e44.cpp.err.txt': No such file or directory
Now the interesting part:If I edit the system command to:
cmd <- paste(R.home(component="bin"), "/R CMD SHLIB ", basename(libCFile), sep="")
i.e. erase the " 2> ", errfile,
and then subsequently comment out the three following lines regarding error handling I can get the function to work.
Hence, with those edits:
> fx <- cxxfunction( signature(x = "integer", y = "numeric" ) , 'return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;' , verbose = FALSE)
> fx(2L,3)
[1] 6
Now, the next step in getting this hack to play with stan
, I recon, is to build a new edited version of the inline
package and then use that in place of the original (until the problem is resolved in a more sustainable wayā¦).
Iāve not come this far yet, but just thought I would post it in case others can use it and are maybe inspired to post a more elegant solutionā¦
Thanks for the help to all of you!