captain
captain

Reputation: 633

How to call View() / utils::View() in a function as part of a package?

I am writing a function for a package that ends with a call to utils::View(). The aim of the function is to do some data wrangling and then open the dataset in the Rstudio data viewer with View(). If I define the function in the global environment it works fine. As an example (skipping the data wrangling part):

foo <- function(x) {
View(x)
}
foo(mtcars)

opens the dataset mtcars in the data viewer. However, once I put it in my r package and call the function as part of that package it does issue the following error:

"Error in .External2(C_dataviewer, x, title) : unable to start data viewer In addition: Warning message: In utils::View(mtcars) : unable to open display"

I have tried to use utils::View() or simply View(), without success. Also, I have tried it with XQuartz uninstalled and with XQuartz installed and couldn't make it work.

I am using Rstudio version 1.0.153 and R version 3.4.1 (2017-06-30) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS Sierra 10.12.6

I am grateful for any hints on how to resolve this!

Upvotes: 1

Views: 1267

Answers (1)

Amrit Shukla
Amrit Shukla

Reputation: 41

Try using View(df) instead utils::View(df)

or try restarting the session (Ctrl +shft +F10)

then again using View(df)

or use dpylr to convert it into a table then use glimpse

-----------------------Code-------------------------------------------

install.packages("dyplr")

dplyr::tbl_df(mtcars)    #to convert data to table class

dplyr::glimpse(mtcars)

Upvotes: 0

Related Questions