daRknight daRknight - 1 month ago 15
R Question

R (rStudio): View error 'names' attribute [4] must be the same length as the vector [1] for character vector

This has been happening recently, and I cannot understand how to resolve. N.B. I am using rStudio v0.99.893

I have created a character vector from a

data.table
, which I then attempt to View, and receive the above error:
Error in View : 'names' attribute [4] must be the same length as the vector [1]


The original DT has ~10,000 observations of 12 variables, here is a subset capturing all classes:

> head(DT, 3)
HQ URL type ID1 ID2 completion date_first
1: imag image-welcome basic 444 24 0.1111111 2016-01-04 14:55:57
2: imag image-welcome basic 329 12 0.2222222 2016-03-15 11:37:21
3: imag image-confirm int 101 99 0.1111111 2016-01-06 20:55:07

as.character(sapply(DT, class))
[1] "character" "character" "character" "integer"
[5] "integer" "numeric" "c(\"POSIXct\", \"POSIXt\")"


From
DT
I create a character vector of the unique values of
URL
for a subset of interest (only 'imag' HQ):

URL.unique <- unique(DT[HQ == "imag", URL])
> class(URL.unique)
[1] "character"

> names(URL.unique)
NULL

> View(URL.unique)
Error in View : 'names' attribute [4] must be the same length as the vector [1]

> length(URL.unique)
[1] 262


Printing
URL.unique
in the console works fine, as does exporting it via
write.table()
but it is annoying that I cannot view it.

Unless there is something implicitly incorrect about the above, I am resorting to reinstalling rStudio. I've already tried quitting and relaunching, just in case there was some issue as I tend to leave multiple projects open on my computer over days.

Any help would be appreciated!

Answer

As noted by @Jonathan, this is currently filed with RStudio to investigate. Can confirm reinstalling and other measures did not resolve the issue which still persists. If it is reproduced and filed as a bug, I would request @Jonathan to supply the details here for anyone else to tie into.

The workaround of View(data.frame(u = URL.unique)) does the job to launch the viewer on the data object of interest (thanks @Frank)