Closed gitclem closed 5 years ago
That's clearer. I will remove the few posts that accidentally ended at the bottom of #138.
The issue is that identifiers in these interfaces have to be legal in both R and Cpp. If you use the _x
style elsewhere it works:
R> Rcpp::cppFunction("double doubleMe(double x) { double _y = x + x; return _y; }")
R> doubleMe(21)
[1] 42
R>
But because you cannot use a [leading] underscore on R identifiers :
R> _x <- 4
Error: unexpected input in "_"
R>
you cannot use it in places that will also appear in R. Makes sense?
We could add an entry to the Rcpp FAQ but it is ex ante indeed not fixable.
(Edited to stress leading underscores which what I was talking about as it is the issue at hand.)
Actually, the problem is you can't use leading underscores. R relaxed the use of underscores so that a_b is now legal. (I hadn't realized leading underscores are still illegal.)
> a_b <- 1
> a_b
[1] 1
You never could, and snake_case
with middle _
is not exactly novel either.
The point is that what you tried never could work reasons that are not obvious at first, but entire rational.
So ok to close this?
The issue could probably be fixed by quoting the non-syntactic R identifiers. PRs welcome.
Fine to close it, but please leave the thread. I'm sure another naive programmer will encounter this error and will be stumped.
Good point. I keep forgetting about the escaping backtick:
R> `_x` <- 4
R> `_x`
[1] 4
R>
Second the notion that we're open to reviewing PRs but unlikely to write one here.
(Yes, I am strongly opposed to deleting issues and regret they added it. I am, as you can now tell, also opposed to randomly spamming 4 1/2 year old existing tickets. This one will remain, but the sad truth is that not too many people dig through older issues. Oh well.)
I was searching for an explanation for the obscure error I found. I was going to make a new ticket, but I did see that it had been explained but had in the course of 4 years, had morphed. I was just trying to make it easier for the next befuddled programmer to find his way out... (I spent the better part of an afternoon unraveling this...)
What I have learned today, is Rcpp is a great tool, but because it's straddling the R and C++ world, there are gotchas. Thanks for your help.
Yes, sorry. You are not unreasonable in trying to expand the old ticket, but it may be cleaner to just start fresh.
As for the gotchas: Yup. I should earmark this for the Rcpp FAQ. It kinda belongs there and I don't think it is.
Thanks for the report. It is good to have ticket just in case, and better still with a very descriptive subject as you had chosen.
I doubt anybody really will want to fix it and it's not really worth fixing, but the error message is that a naive programmer might doubt his sanity. The solution is simple: don't use a leading underscore.