简体   繁体   English

打包环境操作并提交给CRAN

[英]Package environment manipulation and submitting to CRAN

I have built a package for shiny that allows the user to interact with reactive objects in their global environment. 我已经构建了一个闪亮的软件包该软件包允许用户在其全局环境中与反应性对象进行交互。 I think it's a game changer for troubleshooting. 我认为这是解决故障的游戏规则。 However, I know that CRAN will reject this due to the manipulation of the global environment. 但是,我知道由于全球环境的操纵,CRAN将拒绝这样做。 I see answers directing users to create a new environment but I don't see how to access the objects of that environment in the environment pane, I just see the environment name. 我看到指导用户创建新环境的答案,但是在环境窗格中看不到如何访问该环境的对象,我只看到环境名称。

If I run something like this from this example: Global variable in a package - which approach is more recommended? 如果我从本示例中运行以下内容: 程序包中的全局变量-更推荐使用哪种方法?

e <- new.env()
assign("a", "xyz123", envir = e)
e$b <- 1

I see this, and clicking on e will call View(e) 我看到了,点击e会调用View(e)

在此处输入图片说明

I want e to be something the user can see on the right-hand side like it is when the user is in their global environment or when debugging a function: 我希望e成为用户可以在右侧看到的东西,就像用户处于其全局环境中或调试函数时一样:

在此处输入图片说明

A similar question was asked here but did not address changing how the user sees objects in the IDE: 在此处提出了类似的问题,但未解决更改用户在IDE中查看对象的方式:

CRAN policy on use of global variables CRAN使用全局变量的政策

This stuff is new territory so I hope my question makes sense. 这些东西是新领域,所以我希望我的问题有意义。

If you run attach(e) , then e will be available to be chosen in the environment pane. 如果您运行attach(e) ,那么可以在环境窗格中选择e You should pair this with detach(e) so that you don't permanently mess up the user's search list. 您应该将它与detach(e)配对,以免永久破坏用户的搜索列表。

If the user chooses to look at e when it is attached, it won't disappear when it is detached, but it won't be available to select again after being detached if the user views a different environment. 如果用户选择在连接时查看e ,则在分离时它不会消失,但是在分离后如果用户查看其他环境,它将无法再次选择。

I don't know if there's an RStudio API way to automatically select it. 我不知道是否有一种RStudio API方法可以自动选择它。

Edited to add: The attach() function creates a new environment copying the value of e at the time of attaching. 编辑为添加: attach()函数创建一个新环境,该环境在attach()复制e的值。 That's probably not what you want. 那可能不是您想要的。 There is a way to get a live one though: 有一种方法可以使现场直播:

attach(NULL, name = "Viewable")
e <- as.environment("Viewable")

# Now somehow get the user to view it in the Environment pane

# Clean up the search list
detach("Viewable")

You then have a live environment, things like 然后,您将拥有一个生活环境,例如

e$a <- 123

will show up there. 会在那里出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM