R “for loop” error messages {}

后端 未结 3 1003
死守一世寂寞
死守一世寂寞 2020-12-04 03:58

Since a couple of days ago when I run a for loop in R it gives me plenty of errors related to \"}\". It only happens if I highlight the whole code and run it. If i execute i

相关标签:
3条回答
  • 2020-12-04 04:24

    I suspect that the issue was in using the R script that I downloaded from a website. I ended up reinstalling R and saving my own R script as a new file. I am not sure what and how, but now it is working fine.

    0 讨论(0)
  • 2020-12-04 04:28

    I have been experiencing the same problem, and have found that it is caused by a bug in RStudio (the code runs fine in R and R-gui, but fails in RStudio.) It is hard to reproduce until something gets corrupted in RStudio's saved state, after which the behaviour is pretty consistent.

    Removing ~/.rstudio-desktop fixed the issue for me.

    mv ~/.rstudio-desktop ~/rstudio-desktop.old
    

    More on resetting RStudio's state on various platforms here.

    0 讨论(0)
  • 2020-12-04 04:39

    I am also using Rstudio and get the same error message when running for loops.

    Error: unexpected '}' in "}"
    

    If I source the file, like this...

    source('~/.active-rstudio-document')
    

    or if I simply click the "source" button in the GUI, I don't get the same error message.

    If sourcing the whole R script is not an option, consider copying the for loop to another file and sourcing that.

    0 讨论(0)
提交回复
热议问题