在 RStudio Server 中共享内存数据 [英] Sharing in memory data in RStudio Server

查看:76
本文介绍了在 RStudio Server 中共享内存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定我是否能够使用 RStudio 将数据保存在内存中以供多个会话使用,或者至少可以保留会话.事实证明,搜索有关此功能存在/不存在的信息具有挑战性.

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.

测试是这样的:

  1. 在与 RStudio 的会话中创建一个变量并为其赋值.
  2. 在另一个会话中运行引用该变量的脚本.

如果变量被赋值,那么脚本将工作,否则它会失败并显示错误:找不到对象变量.

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

是否可以在 Rstudio Server 中创建一个跨会话变量,以便在不参与文件 i/o 的情况下使用此过程?或者它只是作为服务器功能不可用?

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?

推荐答案

不幸的是,由于 R 本身的设计方式,这是不可能的.

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

每个 R 会话都有自己的私有内存空间,其中包含值和数据(该会话的全局环境等).

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

为了创建跨会话变量,R 会话必须共享内存,并且它们还必须协调对该内存的访问,以便(例如)如果一个会话正在更改变量的值,在第一个会话完成更改之前,另一个会话无法读取该值.这种协调机制在 R 中是不存在的.

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. 将您的数据保存在两个会话都可以安全读写的地方,例如在数据库中,或者

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

正如您提到的,参与文件 I/O 是一种选择,但这并不难:使用 .Rdata 文件;当你希望向其他会话发布数据时,将私有变量写成R数据文件(例如使用save),当其他会话希望同步时,它可以将数据加载到自己的私有变量中空间(使用例如load).

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

这篇关于在 RStudio Server 中共享内存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆