i'm trying to do an "node" Class in R, like in java: but the code pop up an error, "The class node doesn't exist when i'm creating the value "Next="node" is it not possible to do recursion in a class in R? or how could i do this?
node <- setRefClass("node", fields = list(value="numeric", next="node"))
Error: inesperado '=' in "node <- node <- setRefClass("node", fields = list(value="numeric", next=""
The problem here is that you are using the flow
Controlwordnext. Tryhelp(next)and this description comes upAs such they cannot be used for variable names, and if they are used for list names they should be quoted. Eg. this will work:
note that I wrote
'next'and notnextAs a side note I would suggest checking out the
R6package, which provides a simpler interface to OOP than reference classes while also being much faster than reference classes.