10

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

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.

I checked the R Studio cheatsheet, but this did not show whether / from where the R Studio View() is exported.

Joshua Rosenberg
  • 4,014
  • 9
  • 34
  • 73

1 Answers1

9

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.

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'll get their function, if you run it anywhere else, you'll get the regular one.

user2554330
  • 37,248
  • 4
  • 43
  • 90