How to use the R Studio View () function programmatically / in a package

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

When I use utils::View() , a different viewer is used than the R Studio viewer (it seems to be the one built into R ), but if I use View() (without specifying where the function is exported from), problems occur during R CMD CHECK .

I checked R cheatsheet Studio , but it did not show if R Studio View() exported .//p>

+5
source share
1 answer

RStudio replaces the utils :: View utility with its own function when it starts. Their source

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

You cannot just copy this into your package, because it depends on what happens in this environment, and there is no way to get your package.

However, you can do this:

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

and export myView from your package. If you run this in RStudio, you will get their function, if you run it somewhere else, you will get the usual one.

+4
source

Source: https://habr.com/ru/post/1274673/


All Articles