Can't use variable name `class` in a BUGS model
Using the variable name class causes a compilation error.
Understandable, but it would be nice to avoid this.
Example:
library(nimble)
code <- nimbleCode({ class ~ dnorm(0, 1) })
Rmodel <- nimbleModel(code)
Cmodel <- compileNimble(Rmodel, showCompilerOutput = TRUE)
## Error: Failed to create the shared library.
## /usr/local/clang4/bin/clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -DR_NO_REMAP -DEIGEN_MPL2_ONLY=1 -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/nimble/include" -Wno-misleading-indentation -Wno-ignored-attributes -Wno-deprecated-declarations -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c P_1_code_MID_1.cpp -o P_1_code_MID_1.o
## warning: unknown warning option '-Wno-misleading-indentation'; did you mean '-Wno-missing-declarations'? [-Wunknown-warning-option]
## In file included from P_1_code_MID_1.cpp:7:
## ./P_1_code_MID_1.h:24:23: error: expected member name or ';' after declaration specifiers
## NimArr<1, double> * class;
## ~~~~~~~~~~~~~~~~~ ^
## P_1_code_MID_1.cpp:48:24: error: expected expression
## namedObjects["class"]=&class;
## ^
## P_1_code_MID_1.cpp:52:1: error: declaration of anonymous class must be a definition
## class
We also can't use variable name 'missing':
code=nimbleCode({
y ~ dnorm(missing,1)
})
m = nimbleModel(code)
defining model...
building model...
Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
It might be names that are R and/or C++ keywords or functions. IIRC this has come up before. I think we could fix it with name mangling like adding a trailing underscore. We use active bindings for access, which can still use the original name. I bet there would be some wrinkles to iron out if we think this is worth it.
@perrydv I'm fine either way, but big picture, if it's not too much trouble, I'm of the opinion we should have an easy way of handling these (e.g., a list you just add another "variable name" to), which then does additional mangling of that name when it occurs, so that using it in a model is ok. I think we should support use of names such as "class", and "missing", if possible.