I am trying to use the pymer4 package in python for Multi-Level Models, and I have to pass an "R-style formula specifying the model". I understand that it looks like:
target ~ varA + varB
However, I have many variables and some of those have numbers at the end of the names, parentheses, and slashes, like:
var1, (var)2, var1/var2
When I create a string like in the first example, I get the following error, indicating a variable with a number as the suffix.
RRuntimeError: Error in str2lang(x) : <text>:1:70: unexpected numeric constant
I know I could change the names, but it is tedious as I have many variables, as well as having a lot of other code that uses the existing names. I have never coded in R so I haven't got a clue how to solve this problem. There must be a way to just specify that the number and other characters are part of the string, no?
pymer4, but I can produce that error withas.formula("var1 ~ (var)2 + var1/var2")and the error does not occur withas.formula("`var1` ~ `(var)2` + `var1/var2`"). While I don't assume that you're callingas.formulaorstr2langdirectly, the backticks should cascade into where the error is being triggered.