Sharing in memory data in RStudio Server

孤人 提交于 2019-12-08 03:51:34

问题


I am trying to determine if I am able to keep data in-memory with RStudio to be used by multiple sessions, or for the session to at least be preserved. Searching for information about the existence/nonexistence of this feature has proven to be challenging.

The test is this:

  1. In a session with RStudio create a variable and assign a value to it.
  2. In another session run a script that refers to that variable.

If the variable is assigned a value then the script will work, otherwise it fails with "Error: object variable not found.

Is it possible to make a cross session variable in Rstudio Server that will work with this procedure without engaging file i/o? Or is it simply unavailable as a server function?


回答1:


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).



来源:https://stackoverflow.com/questions/35352807/sharing-in-memory-data-in-rstudio-server

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