如何以编程方式/在包中使用 R Studio View() 函数 [英] How to use R Studio View() function programatically / in a package

查看:77
本文介绍了如何以编程方式/在包中使用 R Studio View() 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式/在包中使用 R Studio View() 函数.

I am trying to use the R Studio View() function programatically / in a package.

当我使用 utils::View() 时,使用了与 R Studio 查看器不同的查看器(它似乎是 R 的内置查看器),但如果我使用 View()(不指定函数从何处导出),在 R CMD CHECK 期间会出现问题.

When I use utils::View(), a different viewer than the R Studio viewer (it appears to be the one built-in to R) is used, but if I use View() (without specifying where the function is exported from), issues come up during R CMD CHECK.

我查看了 推荐答案

RStudio 在启动时用自己的函数替换了 utils::View 函数.他们的来源是

RStudio replaces the utils::View function with their own function when it starts up. Their source is

function (...) 
.rs.callAs(name, hook, original, ...)
<environment: 0x1036a6dc0>

你不能把它复制到你的包中,因为它取决于那个环境中的东西,你的包没有办法得到它.

You can't just copy this into your package, because it depends on things in that environment, and there's no way for your package to get it.

但是,您可以这样做:

myView <- function(x, title)
  get("View", envir = as.environment("package:utils"))(x, title)

并从您的包中导出 myView.如果您在 RStudio 中运行它,您将获得它们的功能,如果您在其他任何地方运行它,您将获得常规功能.

and export myView from your package. If you run this in RStudio, you'll get their function, if you run it anywhere else, you'll get the regular one.

这篇关于如何以编程方式/在包中使用 R Studio View() 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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