I use R and R Markdown for my workflow. I have come to realise that Cursor cannot generate code when they are to be within an R Markdown file (which has a mix of R and Markdown). What tends to happen is having to copy and paste each section into the code file for it to work because the generation often just starts and ends with the first code chunk and recognises the subsequent code as text.
Hopefully this can be resolved.