Thank you for explaining this, reaty. I understand it now. Thank you also for the alternative.
If I put
<%* let myVar = 10 %>
above the frontmatter
---
number: <%* tR += myVar %>
---
then the frontmatter is not recognised. If, however, I put it inside like this
---
number: <%* let myVar = 10 %><%* tR += myVar %>
---
then it all works.