Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autocompletion error during the data frame column selection in RStudio

I used the readxl package to import from the Excel file into RStudio. Now I'm trying to access a column in that dataset using the $ operator. However, I keep getting the notification:

(Type Error): null is not an object (evaluating a.length)

Even though I've performed this type of operation many times before without issue...

The error I'm getting:

enter image description here

The dataset in the Global Environment pane:

enter image description here

like image 352
David Avatar asked Apr 06 '17 04:04

David


1 Answers

The root of the problem is located in NA used as a column name. The error is thrown since RStudio autocompletion is not able to extract column names.

Please see the reproduction of the problem:

df <- data.frame(a = 1:3, b = 1:3)
names(df)[2] <- NA

If you will try to typedf$a the error below will be generated.

enter image description here

To avoid this kind of situation you should assign data.frame column names explicitly. You have to options:

  1. assign names(df) <- c("a", "b");

  2. delete the spacer columns from the source Excel file to avoid NA use as the column names.

like image 131
Artem Avatar answered Nov 03 '22 21:11

Artem