Sharing in memory data in RStudio Server

自闭症网瘾萝莉.ら 提交于 2019-12-06 04:28:37

Unfortunately this is not possible because of the way R itself is designed.

Each R session has its own private memory space which contains values and data (the global environment for that session, etc.).

In order to create a cross-session variable, the R sessions would have to share memory, and they would also have to coordinate access to that memory, so that (for instance) if one session was changing the value of the variable, the other session could not read the value until the first session was done changing it. This sort of coordination mechanism just doesn't exist in R.

If you want to do this there are a couple work-arounds:

  1. Keep your data in a place that both sessions can read and write to safely, for instance in a database, or

  2. As you mentioned, engaging file I/O is an option, but this isn't too hard: use a .Rdata file; when you wish to publish data to other sessions, write the private variables as an R data file (using e.g. save), and when the other session wishes to synchronize, it can load the data into its own private space (using e.g. load).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!