View() is causing an error

The view function returns an error:

View(iris)
Error in hist(hist_vals, plot = FALSE) : could not find function "hist"

This is true for data.frame, tibble and data.table structures. I don't know why it's looking for 'hist()' but the hist function is there and does work, for what it's worth.

RStudio 1.3.1056.
R -> 4.02
MacOS 10.15.6

You might have accidentally overloaded the View() function (maybe a package you've loaded has a function called View() in it which is masking the View() function loaded by utils. Try running View in command line on its own (without any brackets). The result should look something like this:

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

(The environment part will look like a random stream of numbers/letters).

If it doesn't look like that, try restarting your R session as this will unload any packages that may have overloaded R.

If it does and you're still getting the error, run sessionInfo() to get an overview of what packages are loaded and paste the output here.

It'd be helpful if you post code/results with a line of three backticks ``` above and below. This enters a code chunk on the community forum and makes things much easier to read.

Thanks for your note. One extra piece of information. View() opens a new tab in the Source pane of RStudio, but does not show any output, the new window is blank. View(1) works normally. See the image in Step 5 below.

Here are your tests (and some others that may be helpful).

Step 1: View

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

Step 2: restart R > View >> same result

Step 3: sessionInfo()

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] datasets utils    methods  base    

other attached packages:
[1] RMySQL_0.10.20 DBI_1.1.0     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6     rstudioapi_0.11  magrittr_1.5     grDevices_4.0.2  tidyselect_1.0.0
 [6] munsell_0.5.0    colorspace_1.4-1 R6_2.4.1         rlang_0.4.7      fansi_0.4.1     
[11] dplyr_0.8.5      tools_4.0.2      grid_4.0.2       packrat_0.5.0    gtable_0.3.0    
[16] cli_2.0.2        stats_4.0.2      ellipsis_0.3.1   assertthat_0.2.1 tibble_3.0.3    
[21] lifecycle_0.2.0  crayon_1.3.4     purrr_0.3.4      ggplot2_3.3.0    graphics_4.0.2  
[26] vctrs_0.3.2      glue_1.4.1       compiler_4.0.2   pillar_1.4.6     scales_1.1.0    
[31] pkgconfig_2.0.3 

Step 4: utils::View(iris)

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

Step 5: View(1) <-- Works!!
Screen Shot 2020-08-03 at 9.33.13 PM

Step 6: View(c(1,2)) fails.

1 Like

This error is coming from RStudio itself; it is trying to generate brushing histograms for your column's data (for filtering purposes).

Does .rs.describeCols(iris, maxFactors = 10) also show you the error?

Yes, it does show an error:

> .rs.describeCols(iris, maxFactors = 10)
Error in hist(hist_vals, plot = FALSE) : could not find function "hist"

I have discovered the proximate cause of the failure of View() to work. For reasons I cannot remember, I long ago put the following line in my .Rprofile file:

options(defaultPackages = character())

The presence of this line, which has been there for ages, has suddenly started causing View() to fail. On reading the documentation, I don't think this option even belongs in .Rprofile. I have removed it. All is right with the world again. :sunglasses: :mask:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.