Hi,
thanks for posting here!
i'll put back the answer I made already in the GH issue
The error says that Rnew is not found. From your code, Rnew is not defined outside the function definition corstars. So I think you need to call the function corstars on the x you want to calculate Rnew. Otherwise, Rnew does not exist.
Currently you are under the impression the code works because you may have a Rnew object already existing in your workspace. When you run code from the Rmd chunk, it will run in your workspace. Try to run the code in a new R session with a fresh empty global environment and you should reproduce the error.